[英]Importing local packages in python
Python: 3.10.4 Windows: 10 Python:3.10.4 Windows:10
Ok so I have been struggling with this for while now.好的,所以我一直在努力解决这个问题。
I've been testing module imports in python.我一直在 python 中测试模块导入。 I'm using https://github.com/tomchen/example_pypi_package as a (very useful) example.
我使用https://github.com/tomchen/example_pypi_package作为(非常有用的)示例。 I run the following:
我运行以下命令:
git clone https://github.com/tomchen/example_pypi_package
cd example_pypi_package
python -m setup.py develop
pip install -e .
Now, I expect to be able to import example_pypi_package
in the REPL of that environment.现在,我希望能够在该环境的 REPL 中导入
example_pypi_package
。
import example_pypi_package.module1
Yet I get ModuleNotFoundError
.然而我得到
ModuleNotFoundError
。
How?如何? I checked that my
sys.path
is correct and in my Lib\site-packages
there is an example_pypi_package.egg-info
file.我检查了我的
sys.path
是否正确,并且在我的Lib\site-packages
中有一个example_pypi_package.egg-info
文件。 I checked that my sys.execuatble
is the correct environment and installed it with pip
within that environment.我检查了我的
sys.execuatble
是正确的环境,并在该环境中安装了pip
。 The package shows up in pip list
. package 出现在
pip list
。 What am I missing?我错过了什么? I can't import the package not even import subpackages of that package.
我无法导入 package 甚至无法导入 package 的子包。
The importable package (directory with __init__.py
) for this distribution package is examplepy
.此发行版 package 的可导入 package(带有
__init__.py
的目录)是examplepy
。 See https://github.com/tomchen/example_pypi_package/tree/main/src/examplepy见https://github.com/tomchen/example_pypi_package/tree/main/src/examplepy
So try import examplepy
or所以尝试
import examplepy
或
import examplepy.module1
PS. PS。 The name of a distribution/package/repository could be completely different from importable names.
分发/包/存储库的名称可能与可导入的名称完全不同。 See my examples at https://stackoverflow.com/a/54599368/7976758
请参阅我在https://stackoverflow.com/a/54599368/7976758上的示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.