我在 python 包分发中迈出了第一步。
不幸的是,我有ModuleNotFoundError
从 pip 安装成功后。
我的目录布局非常简单:
maindir
|- setup.py
|- pysoft
|- __init__.py
|- main.py
|- pylib.py
main.py:
import pylib
def main():
print("main program")
pylib.libfunc()
if __name__ == '__main__':
main()
pylib.py:
def libfunc():
print("lib func")
设置.py:
import setuptools
setuptools.setup(
name='pysoft',
version='0.0.21',
author='als',
author_email='[email protected]',
description='deploy tester',
py_modules=['pylib'],
packages=setuptools.find_packages(),
python_requires='>=3.6',
entry_points={
'console_scripts': [
'pysoft = pysoft.main:main',
],
},
)
我打包并上传到测试.pypi.org:
python3 setup.py sdist bdist_wheel
python3 -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
我设置并开始新的virtualenv
并安装我的包:
python3 -m pip install -i https://test.pypi.org/simple/ pysoft
然后我尝试运行它,但出现错误:
pysoft
Traceback (most recent call last):
File "/home/fat/buff/tt/bin/pysoft", line 5, in <module>
from pysoft.main import main
File "/home/fat/buff/tt/lib/python3.6/site-packages/pysoft/main.py", line 1, in <module>
import pylib
ModuleNotFoundError: No module named 'pylib'
你能找出我哪里错了吗?