【发布时间】:2010-09-25 05:22:05
【问题描述】:
Python 安装在本地目录中。
我的目录树如下所示:
(local directory)/site-packages/toolkit/interface.py
我的代码在这里:
(local directory)/site-packages/toolkit/examples/mountain.py
为了运行这个例子,我写了python mountain.py,在我的代码中:
from toolkit.interface import interface
我得到了错误:
Traceback (most recent call last):
File "mountain.py", line 28, in ?
from toolkit.interface import interface
ImportError: No module named toolkit.interface
我已经检查了sys.path,并且那里有目录/site-packages。此外,我在工具包文件夹中有文件__init__.py.bin,以向 Python 表明这是一个包。我在示例目录中也有一个__init__.py.bin。
不知道为什么 Python 在 sys.path 中找不到文件。有任何想法吗?会不会是权限问题?我需要一些执行权限吗?
【问题讨论】:
-
检查您是否具有从 python 读取该文件的权限。见:stackoverflow.com/a/20999950/1657225
-
请务必将您的目录标记为“Resources Root”,让 PyCharm 知道这是一个包。
-
我的问题是新安装的模块的权限不是
755。这是因为机器上的umask是0027,因此others没有read权限导致模块无法读取。添加read权限解决了我的问题。安装后需要检查目标目录的权限。 -
尝试吹 url : stackoverflow.com/questions/47887614/…
-
这就是 Python 垃圾的原因。 537 次投票,42 个答案,查看了 190 万次 - 这里有些烂。
标签: python importerror python-import