我在创建python包发行版时失败了。我已经按照指示
https://packaging.python.org/tutorials/packaging-projects/
这就是发生的事。例如,如果我根据需要创建必要的文件和文件夹
first/
first/
__init__.py
setup.py
LICENSE
README.md
myfirst.py
我在setup.py中将包命名为“first”
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="tvg11",
version="0.0.1",
author="Ganesh",
author_email="tvganesh.85@gmail.com",
description="A small example package",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
packages=setuptools.find_packages(),
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
然后我运行命令
python setup.py sdist bdist_wheel
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
创造了
dist/
,
build/
和
first.egg-info
。
现在我发现如果我在同一个目录下
pip install --index-url https://test.pypi.org/simple/ first
然后我发现这会创建一个新文件夹
Pycache公司
通过编译的代码,我可以
import first
first/
first/
__pycache__ # new!
build/
dist/
first.egg.info
__init__.py
setup.py
LICENSE
README.md
myfirst.py
但是,如果我在根文件夹“first/first”之外的任何其他文件夹中,我会
pip install——索引url https://test.pypi.org/simple/first
我得到一个“成功安装”,但是当我调用python并执行
先导入
我得到
ModuleNotFoundError
“没有模块'first'”
请让我知道我做错了什么。说明很简单。