有 python 3.4 找到我的自定义包

Having python 3.4 find my custom package

我在 python 中写了一个包,现在我尝试使用 .pth 文件将它添加到我的 site-packages 文件夹中,以便我可以使用 import 语句从任何地方调用它,但它不是正在工作。

sste.pth 我的站点包文件夹中的文件

/scratch/automation/sste

sste 文件夹结构

sste-\
     ---__init__.py
     ---module1.py
     ---module2.py

据我了解,当我启动 python 时,它应该获取 site_packages 文件,包括我的 sste.pth 文件,并将 /scratch/automation/sste 添加到模块列表中,这样我就可以通过执行 import sste 导入它,但我得到一个 import error,并且无法弄清楚为什么。

看起来您已指示 Python 在 /scratch/automation/sste 中查找您的模块,而 sste 本身就是一个包。当 Python 在 /scratch/automation/sste 中查找时,它不会找到名为 sste 的包,只会找到 .py 个名为 __init__.pymodule1.pymodule2.py.

简而言之,您应该告诉 Python 在 /scratch/automation 中查找模块。 Python 的路径不是它可以导入的模块列表,而是可能 包含 个模块的目录列表。

此外,请检查 sys.modules 以确保您期望的目录在那里。