This question already has answers here:
Importing installed package from script raises “AttributeError: module has no attribute” or “ImportError: cannot import name”

(3个答案)


去年关闭。




我正在使用Open CV PYTHON进行人脸检测。我的整个代码昨天工作正常,今天我收到此错误。
['/usr/local/lib/python2.7/dist-packages/numpy']
 Traceback (most recent call last):
  File "facerec-opencv.py", line 2, in <module>
  from scipy.misc import imread
  File "/usr/local/lib/python2.7/dist-packages/scipy/__init__.py", line 61,in <module>
  from numpy import show_config as show_numpy_config
  File "/usr/local/lib/python2.7/dist-packages/numpy/__init__.py", line 163, in <module>
  from . import random
  File "/usr/local/lib/python2.7/dist-packages/numpy/random/__init__.py", line 99, in <module>
  from .mtrand import *
  File "mtrand.pyx", line 149, in init mtrand (numpy/random/mtrand/mtrand.c:37623)
  File "/home/irum/Desktop/Face-Recognition/thakarrecog/threading.py", line 6, in <module>
  import logging
  File "/usr/lib/python2.7/logging/__init__.py", line 201, in <module>
    _lock = threading.RLock()
AttributeError: 'module' object has no attribute 'RLock'

我已经尝试更新numpy,我也重新安装它,但nothong正在工作。

最佳答案

如果可以帮助某人,那么我也有完全相同的问题。代码运行到一天,然后突然出现此错误。发生的变化是,我在同一目录中创建了一个名为threading.py的文件。线程也是一个库名。这就造成了冲突,所有代码都被破坏了。只需删除threading.py即可为我解决。

关于python-2.7 - AttributeError: 'module'对象没有属性 'RLock'`,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41012121/

10-16 22:50