Summary of a.

Spiderkeeper-new: spiderKeeper-new: spiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new: SpiderKeeper-new I hope to offer some help to my friends who have the same needs.

2. Upload Python package to pYPi official website

First of all, check the official document. The official document is very detailed. After reading the official document, you will know the whole construction process.

1. Configure the project

Create a setup.py file under the root of your project. Here, using the contents of SpiderKeeper as an example, the setup.py file will look like this:

#! /usr/bin/env python
from os import path
from setuptools import setup, find_packages

here = path.abspath(path.dirname(__file__))
with open(path.join(here, 'requirements.txt'), 'r', encoding='utf-8') as f:
    all_reqs = f.read().split('\n')

with open(path.join(here, 'README.md'), 'r', encoding='utf-8') as f:
    long_description = f.read()

install_requires = [x.strip() for x in all_reqs if 'git+' not in x]

setup(
    name='SpiderKeeper-new'.PIP install Spiderkeeper-new PIP install Spiderkeeper-new PIP install spiderkeeper-new
    version='1.0.0'.# Mandatory, the version of the project, it is recommended to follow the semantic version specification
    author='edisonwd'.# Author of the project
    description='Admin ui for spider service, update info: upgrade dependent package'.# A brief description of the project
    long_description=long_description,  # detailed description of the project, usually read the contents of the readme.md file
    long_description_content_type='text/markdown'.The format of the description, optional values: text/plain, text/x-rst, and text/markdown
    author_email='[email protected]'.# valid email address of the author
    url='https://github.com/edisonwd/SpiderKeeper'.# project source code address
    license='MIT',
    include_package_data=True,
    packages=find_packages(),  Find_packages (where=' SRC '); find_packages(where=' SRC ');
    install_requires=install_requires,  # specify the Python package your project depends on. Read requirements.txt directly
    The following setup will provide a command called spiderKeeper on the command line, which launches the project by executing the main method run under the SpiderKeeper package
    entry_points={
        'console_scripts': {
            'spiderkeeper = SpiderKeeper.run:main'}},Classifiers help users find items by classifying them
    classifiers=[
        'Development Status :: 4 - Beta'.'License :: OSI Approved :: MIT License'.'Operating System :: OS Independent'.'Programming Language: Python :: 2.7'.'Programming Language: Python :: 3.7',].)Copy the code

The above setup.py file references requirements. TXT and readme. md. By default, the source distribution that packages Python contains only the py file, and an error will be reported if those files are not introduced during installation. To package other files into the distribution package, you need to specify the manifest.in file. The contents of spiderKeeper’s manifest.in are as follows:

recursive-include SpiderKeeper/app/templates *
recursive-include SpiderKeeper/app/static *
include requirements.txt
include README.md
Copy the code

2. Package projects

Before building sdists and wheel for your project, you need to install the build package using the following command:

pip install build
Copy the code

Build the source package and wheel package for the project using the following command in the setup.py file location:

python -m build
Copy the code

The -m option is followed by module, which runs the module as a script.

If you only want to build the source package, you can execute the following command:

python -m build --sdist
Copy the code

If you just want to build the wheel package, you can execute the following command:

python -m build --wheel
Copy the code

After the build is complete, a dist/ directory is generated under the root of the project to hold the build package.

3. Upload the project to PYPI

Twine is a tool for uploading Python packages to pypi, installed using the following command:

pip install twine
Copy the code

Before uploading, use the following command to check for problems with the built package:

twine check dist/*
Copy the code

Create account

First, you need a PyPI user account. You can create an account using the form on the PyPI website.

Now you will create a PyPI API token so that the project can be securely uploaded.

Go to the pypi.org/manage/acco… The API token; Do not limit its scope to specific projects because a new project is being created.

Do not close the page until you have copied and saved the token – you will not see it again.

To avoid having to copy and paste tokens every time you upload, create a $HOME/.pypirc file:

[pypi]
username = __token__
password = <the token value, including the `pypi-` prefix>
Copy the code

Notice that this stores the token in clear text.

For more details, see.pypirc.

Upload your distribution

Once you have an account, you can use Twine to upload your distribution to PyPI.

The process for uploading a version is the same whether or not the project already exists on PyPI – if not, it will be created automatically when the first version is uploaded.

For second and subsequent releases, PyPI simply requires that the version number of the new release be different from any previous release.

twine upload dist/*
Copy the code

Can navigate to upload the project name https://pypi.org/project/ < sampleproject > the URL to see if the package has been successfully spread, upload the project takes a minute or two to appear on the site.

3. Problems encountered

When prompted to upgrade using the PIP install package, use the following command:

pip install --upgrade pip setuptools wheel
Copy the code

Error as follows:

ERROR: Could not install packages due to an OSError: [WinError 5] Access denial. :'e:\\anaconda3\\scripts\\pip.exe'
Consider using the `--user` option or check the permissions.
Copy the code

The following error occurs when the PIP command is executed again:

> pip
Script file 'E:\anaconda3\Scripts\pip-script.py' is not present
Copy the code

Cause analysis,

PIP install –ugrade PIP PIP install –ugrade PIP PIP install –ugrade PIP PIP install –ugrade PIP

The solution

Use the following method to install:

Get $curl https://bootstrap.pypa.io/get-pip.py - o - PIP. Py # download installation scripts $python get - PIP. Py # run the setup scriptCopy the code

PIP is associated with whichever version of Python is used to run the installation script, and if Python3 is used, execute the following command:

$sudo python3 get-pip.py # Run the installation script.Copy the code

PIP corresponds to Python 2.7 and PIp3 corresponds to Python 3.x.

Some Linux distributions, such as Debian and Ubuntu, can install PIP directly with the package manager:

sudo apt-get install python-pip
Copy the code

Reference documentation

Packaging.python.org/en/latest/g…

Packaging.python.org/en/latest/g…

Pypi.org/help/#file-…

twine.readthedocs.io/en/stable/