为什么我不能导入我创建的python3包,尽管已经正确安装了?

2024-05-20 14:18:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经在中创建了我的第一个python包测试.pypi(在python3.7.1中开发,更多细节:https://github.com/BatLabLancaster/preparenovonix): https://test.pypi.org/project/preparenovonix/

可以通过以下方式正确安装:python3 -m pip

但是,当我尝试导入包时,会收到一条错误消息。你知道吗

我试过在Windows和Linux中安装这个包。我还将Docker容器用于ubuntu和python3.6。在我尝试的3个环境中,安装都是成功的。对于安装,我遵循https://packaging.python.org/tutorials/packaging-projects/中的描述。下面是我在docker+ubuntu中获得的安装命令和消息(在Windows中类似的消息):

$ python3 -m pip install -i https://test.pypi.org/simple/ --user preparenovonix 

Collecting preparenovonix
  Using cached https://test-files.pythonhosted.org/packages/1b/b2/97dd3a537bae2b9605c5e1435c49ac644946b10adf41dc904dee2f1d45e4/preparenovonix-0.0.1-py3-none-any.whl
Installing collected packages: preparenovonix
Successfully installed preparenovonix-0.0.1

这是导入时收到的错误消息:

# python3 -i
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import preparenovonix
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'preparenovonix'

我希望python能够看到这个包,因为它已经成功安装,并且在使用pipshow时也会显示出来。你知道吗


Tags: piphttpsorgtestpypi消息ubuntuwindows
1条回答
网友
1楼 · 发布于 2024-05-20 14:18:00

我认为包的结构有问题。我试过你的”示例.py“成功了。你知道吗

D:\preparenovonix>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycode.novonix_add
>>>

相关问题 更多 >