【发布时间】:2022-01-01 03:27:23
【问题描述】:
我的项目目录中有一个名为 ImgUtils 的包,如下所示:
├── myproject
│ ├── test.py
│ ├── Analyzer
│ ├── __init__.py
│ ├── utils.py
│ └── ImgUtils
│ ├── __init__.py
│ ├── ImgUtils.pyd
│ ├── ImgUtils.so
│ └── a bunch of *.dll files
ImgUtils.pyd 导出一个名为 PyImageUtils 的类。
\\ utils.py
from ImgUtils.ImgUtils import PyImageUtils
def my_test_function():
a = PyImageUtils.analyze()
return a
\\ test.py
from Analyzer import utils
print(utils.my_test_function())
utils.py 中的导入工作正常,但如果我运行 test.py,我会得到 ModuleNotFoundError: No module named 'PyImgUtils'。
我正在使用 Python 3.10。 ImgUtils.pyd 的路径在 sys.path 列表中。
【问题讨论】:
-
你启动 jupyter notebook 的根目录与你直接执行 python 脚本的根目录是什么?
-
@matszwecja 两种情况下的根目录相同。但是 jupyter notebook 在 conda 环境中运行,而脚本却没有。
标签: python-3.x django package python-import python-packaging