我想打包我的python代码并将其上传到PyPI,这样人们就可以轻松使用它。我遵循了包装python项目的文档,并最终将其上传到PyPI测试网站。我运行pip安装来尝试安装它。
奇怪的是,安装后,我找不到包:
(base) ➜ ~ python3 -m pip install --index-url https://test.pypi.org/simple/ oomstore==0.0.4
Looking in indexes: https://test.pypi.org/simple/
Collecting oomstore==0.0.4
Downloading https://test-files.pythonhosted.org/packages/4f/a5/4e7089a1ecb36a59f7f0852a5f96a6054daf886d97132060a7efcda5f04f/oomstore-0.0.4-py3-none-any.whl (12 kB)
Installing collected packages: oomstore
Successfully installed oomstore-0.0.4
(base) ➜ ~ python3
Python 3.8.5 (default, Sep 4 2020, 02:22:02)
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import oomstore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'oomstore'
>>>
我去了软件包的安装路径,在其中没有发现python文件:
(base) ➜ ~ cd ~/miniconda3/lib/python3.8/site-packages/oomstore-0.0.4.dist-info
(base) ➜ oomstore-0.0.4.dist-info ls
INSTALLER LICENSE METADATA RECORD REQUESTED WHEEL top_level.txt
(base) ➜ oomstore-0.0.4.dist-info
我做错什么了吗?我的setup.cfg文件有问题吗?请原谅我问了这么一个无知的问题,我是蟒蛇的新手。。。
问题是,package_dir
选项告诉setuptools在oomstore
目录中查找模块和包,但oomstore
包就在setup.cfg旁边。您应该删除该选项。
您还可以将oomstore
移动到src
目录中并配置package_dir =n = src
;请参阅本文,了解将模块放入src
目录的原因:https://hynek.me/articles/testing-packaging/