Python 3.x Python 3 Import error AttributeError: '_ModuleLock_' object has no attribute 'name'

Python 3.x Python 3 Import error AttributeError: '_ModuleLock_' object has no attribute 'name',python-3.x,debugging,import,attributeerror,Python 3.x,Debugging,Import,Attributeerror,I'm updating a package from python 2 to 3 and I cannot get imports to work. Even the easy ones like import math or import os. Everything checks out ok when I run it with idle. If I try to run it through terminal I get a failed to load process message. In debugger it runs through a few file paths and always gives the same error. I've read a lot of documentation on imports and I'm fairly certain the imports are correct. import os ... import logging ... ... import argparse log = logging.getLog

I'm updating a package from python 2 to 3 and I cannot get imports to work. Even the easy ones like import math or import os. Everything checks out ok when I run it with idle.

If I try to run it through terminal I get a failed to load process message. In debugger it runs through a few file paths and always gives the same error. I've read a lot of documentation on imports and I'm fairly certain the imports are correct.

import os
...
import logging
...
...
import argparse

log = logging.getLogger(__name__) 


ap = ArgumentParser()

I've found this documentation to confirm im doing these right.

https://docs.python.org/3/library/logging.html

https://docs.python.org/3/howto/argparse.html

Cant post last link to os

So everything seems right, but when I run my code I can tell I get no output from argparse, which prompted me to run debugger. The following is the error I got.

for os

Traceback (most recent call last):
  File "C:/path_to/Apps/python/py-scripts/new/untitled.py", line 3, in <module>
    import logging
  File "<frozen importlib._bootstrap>", line 968, in _find_and_load
  File "<frozen importlib._bootstrap>", line 148, in __enter__
  File "<frozen importlib._bootstrap>", line 174, in _get_module_lock
  File "<frozen importlib._bootstrap>", line 59, in __init__
  File "<frozen importlib._bootstrap>", line 59, in __init__
  File "C:\path_to\AppData\Local\Programs\Python\Python36\lib\bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "C:\path_to\AppData\Local\Programs\Python\Python36\lib\bdb.py", line 66, in dispatch_line
self.user_line(frame)
  File "C:\path_to\AppData\Local\Programs\Python\Python36\lib\idlelib\debugger.py", line 24, in user_line
    self.gui.interaction(message, frame)
AttributeError: '_ModuleLock' object has no attribute 'name'

for logging

Traceback (most recent call last):
  File "C:/path_to/Apps/python/py-scripts/new/untitled.py", line 3, in <module>
    import logging
  File "<frozen importlib._bootstrap>", line 968, in _find_and_load
  File "<frozen importlib._bootstrap>", line 148, in __enter__
  File "<frozen importlib._bootstrap>", line 174, in _get_module_lock
  File "<frozen importlib._bootstrap>", line 59, in __init__
  File "<frozen importlib._bootstrap>", line 59, in __init__
  File "C:\path_to\AppData\Local\Programs\Python\Python36\lib\bdb.py", line 48, in trace_dispatch
    return self.dispatch_line(frame)
  File "C:\path_to\AppData\Local\Programs\Python\Python36\lib\bdb.py", line 66, in dispatch_line
    self.user_line(frame)
  File "C:\path_to\AppData\Local\Programs\Python\Python36 \lib\idlelib\debugger.py", line 24, in user_line
    self.gui.interaction(message, frame)
AttributeError: '_ModuleLock' object has no attribute 'name'

In posting this I notice its calling libraries from AppData and not where I installed python. Is that normal as well?


#1

i had this issue when import caffe and had the same error. It turns out the python, when running, is not calling caffe library at the right location. So i manually has sys.path.append("right_path"), fill in there where your packages are installed. This solved my problem.


#2

Please include the full traceback of the error message. The most likely issue is that something in your current path is clashing with a built-in module; the error message can help diagnose this.

#3

Mr. Martijn Pieters, I have since updated the question to reflect a Minimal, Complete, and Verifiable example, or so I think. Pls remove the hold so that one may be able to assist if possible.

#4

I still can't reproduce this, and the traceback doesn't immediately tell me what is going on either, but I've reopened it anyway. Note that the paths may be those recorded in the .pyc files why whomever created the Python distribution you installed and not necessarily reflect your own filesystem.

#5

Never mind, it's 3.6.3.

#6

I think this is a bad interaction between the IDLE debugger and the bootstrap module locking code. An empty _ModuleLock instance is created and __init__ is being called on that instance. But the name attribute is being set on line 61, so before that point anything that might trigger an attempt to look at that attribute from a different thread might end up with that exception. Why there is another thread trying to load the attribute name is not yet clear.