这是从here开始的,但变化很大,我觉得我不得不再提一个问题。
我用python 3创建了一个包(thompcoUtils)
setup.py:
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="thompcoUtils",
version="0.0.9",
author="Jordan Thompson",
author_email="Jordan@ThompCo.com",
description="A collection of utilities",
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",
],
)
建造了它:
python3 setup.py sdist bdist_wheel
running sdist
running egg_info
writing thompcoUtils.egg-info/PKG-INFO
writing dependency_links to thompcoUtils.egg-info/dependency_links.txt
writing top-level names to thompcoUtils.egg-info/top_level.txt
reading manifest file 'thompcoUtils.egg-info/SOURCES.txt'
writing manifest file 'thompcoUtils.egg-info/SOURCES.txt'
running check
creating thompcoUtils-0.0.9
creating thompcoUtils-0.0.9/thompcoUtils.egg-info
copying files to thompcoUtils-0.0.9...
copying README.md -> thompcoUtils-0.0.9
copying setup.py -> thompcoUtils-0.0.9
copying thompcoUtils.egg-info/PKG-INFO -> thompcoUtils-0.0.9/thompcoUtils.egg-info
copying thompcoUtils.egg-info/SOURCES.txt -> thompcoUtils-0.0.9/thompcoUtils.egg-info
copying thompcoUtils.egg-info/dependency_links.txt -> thompcoUtils-0.0.9/thompcoUtils.egg-info
copying thompcoUtils.egg-info/top_level.txt -> thompcoUtils-0.0.9/thompcoUtils.egg-info
Writing thompcoUtils-0.0.9/setup.cfg
Creating tar archive
removing 'thompcoUtils-0.0.9' (and everything under it)
running bdist_wheel
running build
installing to build/bdist.macosx-10.14-x86_64/wheel
running install
running install_egg_info
Copying thompcoUtils.egg-info to build/bdist.macosx-10.14-x86_64/wheel/thompcoUtils-0.0.9-py3.7.egg-info
running install_scripts
adding license file "LICENSE" (matched pattern "LICEN[CS]E*")
creating build/bdist.macosx-10.14-x86_64/wheel/thompcoUtils-0.0.9.dist-info/WHEEL
creating 'dist/thompcoUtils-0.0.9-py3-none-any.whl' and adding 'build/bdist.macosx-10.14-x86_64/wheel' to it
adding 'thompcoUtils-0.0.9.dist-info/LICENSE'
adding 'thompcoUtils-0.0.9.dist-info/METADATA'
adding 'thompcoUtils-0.0.9.dist-info/WHEEL'
adding 'thompcoUtils-0.0.9.dist-info/top_level.txt'
adding 'thompcoUtils-0.0.9.dist-info/RECORD'
removing build/bdist.macosx-10.14-x86_64/wheel
我像这样将其添加到pypi中:
twine upload --repository pypi dist/*
Uploading distributions to https://test.pypi.org/legacy/
Uploading thompcoUtils-0.0.9-py3-none-any.whl
100%|██████████████████████████████████████| 6.21k/6.21k [00:00<00:00, 61.9kB/s]
Uploading thompcoUtils-0.0.9.tar.gz
100%|██████████████████████████████████████| 5.23k/5.23k [00:00<00:00, 8.69kB/s]
使用此.pypirc文件:
[distutils]
index-servers=
pypi
testpypi
[pypi]
username: my_username
password: my_password
[testpypi]
repository: https://test.pypi.org/legacy/
username: my_other_username
password: my_other_password
然后我像这样从另一个文件夹安装它:
pip3 install --no-cache-dir thompcoUtils -U
Collecting thompcoUtils
Downloading https://files.pythonhosted.org/packages/00/da/d87bd82d95fbf90f5c4fb2083a3af514f14d46986ddebcc095bc6c8a4c48/thompcoUtils-0.0.9-py3-none-any.whl
Installing collected packages: thompcoUtils
Successfully installed thompcoUtils-0.0.9
并检查以确保已正确安装:
pip3 list | grep thompcoUtils
thompcoUtils 0.0.9
但是当我尝试使用它时,它会失败:
python3
Python 3.7.2 (default, Feb 12 2019, 08:15:36)
Type "help", "copyright", "credits" or "license" for more information.
>>> import thompcoUtils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'thompcoUtils'
答案 0 :(得分:0)
好吧,经过多次磨难和考验,使一切都变得正确,事实证明这并不困难。
创建了一个包含以下文件和单个子文件夹的文件夹(thompcoutils-名称应为程序包的名称):
./LICENSE
./install.sh
./thompcoutils
./thompcoutils/logging.py
./thompcoutils/os.py
./thompcoutils/__init__.py
./README.md
./setup.py
install.sh是一个帮助程序脚本,用于将程序包构建并安装到pypi.org:
#!/bin/bash
build=1
clean=1
if [[ $# -gt 0 ]]
then
if [[ $1=="clean" ]]
then
build=0
fi
fi
if [[ $clean -eq 1 ]]
then
rm -rf dist
rm -rf build
rm -f *.whl
rm -rf *.egg-info
fi
if [[ $build -eq 1 ]]
then
python3 setup.py sdist bdist_wheel
twine upload --repository pypi dist/*
fi
软件包名称为 thompcoutils ,由子文件夹名称和setup.py文件定义。
这是setup.py:
import setuptools
with open("README.md", "r") as fh:
long_description = fh.read()
setuptools.setup(
name="thompcoutils",
version="0.0.16",
author="Jordan Thompson",
author_email="Jordan@ThompCo.com",
description="Another collection of utilities",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/pypa/sampleproject",
packages=setuptools.find_packages(),
install_requires=[
'psutil', 'netifaces'
],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)
exclude_package_data = {'': ['install.sh']},
请注意,每次推送到云时都必须增加版本。 我希望这会在将来对某人有所帮助(并提醒我;-)