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

六月ゝ 毕业季﹏ 提交于 2021-01-28 12:14:02

问题


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.



来源:https://stackoverflow.com/questions/46716027/python-3-import-error-attributeerror-modulelock-object-has-no-attribute-na

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!