reference:
1 How does python make the code into a library that can be pip
2 python packaging: package custom modules for others to import and use offline
1. Separate the code that needs to be packaged
file format :
|----guacapyClientRest(文件夹)
|----具体项目代码.py
|-----requirement.txt
|-----setup.py
Two settings configuration file
Set the .pypirc file in the user directory, first use txt to enter the content:
Home directory configuration, enter * %homepath% * in the address bar of the Windows resource server and press Enter to enter the home directory of the current user in the system, that is, the home directory
Content example:
[distutils]
index-servers=pypi
[pypi]
repository = https://upload.pypi.org/legacy/
username: admin
password: admin
Use cmd to change the file type , command:
rename .pypirc.txt .pypirc
Three detection setup is set correctly
Check if setup.py is correct, return running check is correct
3.1 Enter the command in the setup directory
python setup.py check
It is normal to return running check
3.2 Package .tar.gz and .whl
Commands in Python for packaging and distributing Python projects.
python setup.py
: Runssetup.py
a Python script named , which typically contains metadata and dependency information for the project.sdist
: Generate source code distribution package (source distribution). This will create a tarball file containing the project's source code, which can be copied to other computers for installation.bdist_wheel
: Generate a binary distribution. This will create a tarball file containing precompiled binaries that can be installed on systems without a Python interpreter.
python setup.py sdist bdist_wheel
Two files are generated in the dist directory .tar.gz and .whl The tar.gz file is the source archive and the .whl file is the built distribution. Newer pip versions prefer installing built distributions, but will fall back to source code archives if needed. You should always upload source archives and provide built archives for platforms your project is compatible with.
3.3 Publishing Python packages to private libraries
python setup.py sdist bdist_wheel
python -m twine upload --repository wid-pip dist/*
3.4 To install dependencies from private libraries, you can refer to the following commands
pip install --index-url https://pip-reader:[email protected]/repository/wip/simple -U py-watmodel-api