Skip to content

Instantly share code, notes, and snippets.

@mano8
Last active August 31, 2023 17:49
Show Gist options
  • Save mano8/968d6c48883c4cf753cb316f56db6c63 to your computer and use it in GitHub Desktop.
Save mano8/968d6c48883c4cf753cb316f56db6c63 to your computer and use it in GitHub Desktop.

SetupTools Cheat Sheet

Create package from source

$ python setup.py sdist bdist_wheel

Check package

$ twine check dist/*

Upload pip package

$ twine upload dist/*

pip Cheat Sheet

This is a forked version from opensource.com By Moshe Zadka

Upgrade pip

$ pip install --upgrade pip

Package sources

Instal package from PiPy

$ pip install requests

Install package from a local wheel file

$ pip install requests-2.22.0-py2.py3-none-any.whl

Install package from a Git repository

$ pip install git+https://github.com/psf/requests.git

Install package from a directory

$ pip install /home/user/src/requests

Package Versions

Install specific version

$ pip install requests==2.22.0

Install most recent version in a range

$ pip install requests>=2.22.0,<3

Install package, avoid a specific version

$ pip install requests!=2.21.0

Upgrade package to latest version

$ pip install --upgrade requests

Freezing (useful for recording an environment so it can be duplicated later)

Capture all currently installed versions in a text file

$ pip freeze > requirements.txt

Install packages from a requirements file

$ pip install -r requirements.txt

Search

Search for packages mentioning “term”

$ pip search <some term>

Show

Show details of package

$ pip show <some package>
It is usually easier to search and view information using the PiPy.org web site

Download

Download a package and all of its dependencies.

Except in unusual cases, it is better to run “pip wheel” and have the packages in a wheel format. $ pip download <package>

List Installed

Lists all modules currently installed by pip.

Usually pip freeze is a better alternative. $ pip list

Custom Indexes

Install from an alternative index to PyPI

$ pip install --index-url https://our-pypi-proxy.internal.example.com

Install packages using an extra index for local, unpublished externally, packages.

$ pip install --extra-index-url https://local-pacakges.internal.example.com

Wheels

Produce wheels of the package and all its dependencies, and put them in the “wheelhouse” directory

$ pip wheel --wheel-dir ./wheelhouse/ some-package[==version]

Produce wheels of all packages named in requirements file, and put them in the “wheelhouse” directory

$ pip wheel --wheel-dir wheelhouse -r requirements.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment