3导入错误AttributeError

3导入错误AttributeError

本文介绍了Python 3导入错误AttributeError:'_ModuleLock_'对象没有属性'name'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将软件包从python 2更新到3,但是我无法使导入工作.即使是简单的程序,例如import math或import os.当我在空闲状态下运行时,一切都检查正常.

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

所以一切似乎都正确,但是当我运行代码时,我可以告诉我argparse没有任何输出,这促使我运行调试器.以下是我得到的错误.

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.

对于操作系统

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'

用于记录

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'

在发布此内容时,我注意到它来自AppData的调用库,而不是我安装python的位置.那也正常吗?

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

推荐答案

导入caffe时出现此问题,并且出现相同的错误.事实证明,python在运行时未在正确的位置调用caffe库.因此,我手动安装了sys.path.append("right_path"),然后在其中安装软件包.这解决了我的问题.

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.

这篇关于Python 3导入错误AttributeError:'_ModuleLock_'对象没有属性'name'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 10:19