installation

[!NOTE|label:references:]

install pip

from source code

$ curl https://bootstrap.pypa.io/get-pip.py | python [--no-setuptools] [--no-wheel]
# or
$ curl https://bootstrap.pypa.io/get-pip.py | python3.2
# or
$ curl https://bootstrap.pypa.io/get-pip.py | python - 'pip==8.0.0'
  • python3.6

    $ python3 < <(curl -s https://bootstrap.pypa.io/pip/3.6/get-pip.py)
    
  • example

    $ python get-pip.py --no-index --find-links=/local/copies
    $ python get-pip.py --user
    $ python get-pip.py --proxy="http://[user:passwd@]proxy.server:port"
    $ python get-pip.py pip==9.0.2 wheel==0.30.0 setuptools==28.8.0
    

upgrade pip

  • linux

    $ [sudo [-H]] pip install --upgrade pip
    
    # or - https://github.com/Homebrew/homebrew-core/blob/master/Formula/p/python%403.13.rb#L324
    $ python3 -Im pip install -v --no-index --upgrade --isolated \
      --target=/usr/local/lib/python3.13/site-packages \
      /usr/local/Cellar/python@3.13/3.13.2/Frameworks/Python.framework/Versions/3.13/lib/python3.13/ensurepip/_bundled/pip-25.0-py3-none-any.whl \
      /usr/local/Cellar/python@3.13/3.13.2/libexec/wheel-0.45.1-py3-none-any.whl
    
  • windows
    > python -m pip install --upgrade pip
    

from easy_install

$ cd /path/to/install/home/Scripts
$ easy_install pip

# or: https://pypi.org/project/ez_setup/#modal-close
$ curl -fsSL https://files.pythonhosted.org/packages/ba/2c/743df41bd6b3298706dfe91b0c7ecdc47f2dc1a3104abeb6e9aa4a45fa5d/ez_setup-0.9.tar.gz | tar xzf - -C .
$ python ez_setup-0.9/ez_setup.py pip

cache

  • clean cache ([pip cache](https://pip.pypa.io/en/stable/reference/pip_cache/))

    $ pip cache purge
    $ pip cache remove matplotlib
    
    # list info
    $ python3 -m pip cache info
    
  • set no cache ([pip config](https://pip.pypa.io/en/stable/reference/pip_config/))

    $ pip install --no-cache-dir <PKG_NAME>
    $ python3 -m pip install --upgrade --no-cache-dir --force-reinstall <PKG_NAME>
    
    # or
    $ pip config set global.cache-dir false
    

for global user (or non user)

[!NOTE]

export PYTHONPATH="/usr/local/lib/python3.9/site-packages:$PYTHONPATH"
# load the user's $HOME/.pip/pip.conf
$ sudo python -m pip install <package-name>

# or
# CANNOT load the user's $HOME/.pip/pip.conf
$ sudo -H pip install <package-name>

re-install package in site.USER_BASE

[!NOTE|label:references:]

$ python -c 'import site; print(site.USER_BASE)'
/Users/marslo/Library/Python/3.9
$ export PYTHONUSERBASE="$(python -c 'import site; print(site.USER_BASE)')"
$ pip install --upgrade --force-reinstall --user <package-name>

setup default python version

# temporary
$ export VERSIONER_PYTHON_VERSION=3.9

$ defaults write com.apple.versioner.python Version 3.9

index-url & extra-index-url

[!NOTE] reference:

$ pip config list
global.extra-index-url='https://artifactory.domain.com/artifactory/api/pypi/pypi-dev/simple'
global.index-url='https://artifactory.domain.com/artifactory/api/pypi/tools/simple'

list pip package with url

[!NOTE|label:references:]

$ sudo yum install util-linux -y
$ pip list --format=freeze |
      cut -d= -f1 |
      xargs pip show |
      awk '/^Name/{printf $2} /^Home-page/{print ": "$2}' |
      column -t
beautifulsoup4:     http://www.crummy.com/software/BeautifulSoup/bs4/
certifi:            https://certifiio.readthedocs.io/en/latest/
cffi:               http://cffi.readthedocs.org
chardet:            https://github.com/chardet/chardet
click:              https://palletsprojects.com/p/click/
click-config-file:  http://github.com/phha/click_config_file
colorama:           https://github.com/tartley/colorama
commonmark:         https://github.com/rtfd/commonmark.py
compressed-rtf:     https://github.com/delimitry/compressed_rtf
configobj:          https://github.com/DiffSK/configobj
docker:             https://github.com/docker/docker-py
extract-msg:        https://github.com/mattgwwalker/msg-extractor
git-review:         http://docs.openstack.org/infra/git-review/
idna:               https://github.com/kjd/idna
IMAPClient:         https://github.com/mjs/imapclient/
Markdown:           https://Python-Markdown.github.io/
mdv:                http://github.com/axiros/terminal_markdown_viewer
meson:              https://mesonbuild.com
olefile:            https://www.decalage.info/python/olefileio
pip:                https://pip.pypa.io/
pprintpp:           https://github.com/wolever/pprintpp
psutil:             https://github.com/giampaolo/psutil
pycparser:          https://github.com/eliben/pycparser
Pygments:           https://pygments.org/
pytz:               http://pythonhosted.org/pytz
PyUserInput:        https://github.com/SavinaRoja/PyUserInput
requests:           https://requests.readthedocs.io
rich:               https://github.com/willmcgugan/rich
setuptools:         https://github.com/pypa/setuptools
six:                https://github.com/benjaminp/six
soupsieve:          https://github.com/facelessuser/soupsieve
ssdfw-scripts:      https://gerrit.sample.com/a/storage/ssdfw/devops/scripts/devkit
tabulate:           https://github.com/astanin/python-tabulate
typing-extensions:  https://github.com/python/typing/blob/master/typing_extensions/README.rst
tzlocal:            https://github.com/regebro/tzlocal
urllib3:            https://urllib3.readthedocs.io/
websocket-client:   https://github.com/websocket-client/websocket-client.git
wheel:              https://github.com/pypa/wheel
xattr:              http://github.com/xattr/xattr

installing from local packages

  • osx/unix

    $ python -m pip download --destination-directory DIR -r requirements.txt
    
    # --no-index && --find-links
    $ python -m pip install --no-index --find-links=DIR -r requirements.txt
    
  • windows

    $ py -m pip download --destination-directory DIR -r requirements.txt
    
    # --no-index && --find-links
    $ py -m pip install --no-index --find-links=DIR -r requirements.txt
    

remove

remove package and dependencies

$ pip install pip-autoremove
# or
$ python3 -m pip install pip-autoremove

# remove package and dependencies
$ pip-autoremove <package-name> -y
  • another solution

    # pip-uninstall-with-dependencies.py
    
    #
    # usage: python pip-uninstall-with-dependencies.py pkg1 [pkg2 ...]
    #
    
    from sys import argv
    from pip._internal.commands.show import search_packages_info
    from pip._internal.cli.main import main
    from typing import List, Dict
    
    if len(argv) < 2:
        print(f"Usage: {argv[0]} pkg1 [pkg2 ...]")
        exit(1)
    
    def get_dependency_tree(packages: List[str], candidates: Dict[str, List[str]] = dict()) -> Dict[str, List[str]]:
        for package in packages:
            if not candidates.get(package):
                pkg_info = next(search_packages_info([package]))
                candidates[package] = pkg_info.required_by
                for package in pkg_info.requires:
                    get_dependency_tree([package])
    
        return candidates
    
    candidates = get_dependency_tree(argv[1:])
    
    # eliminate required
    for package in list(candidates):
        diff = set(candidates[package]).difference(list(candidates))
        if diff:
            print(f"Package {package} cannot be removed, it is required by {diff}")
            del candidates[package]
    
    print("Uninstalling packages and dependencies:", *candidates)
    for package in candidates:
        main(['uninstall', '-y', package])
    

download

[!NOTE|label:references:]

config

[!TIP|label:config files and priority:] references:

TYPE LOCATION COMMENTS
global ${HOMEBREW_PREFIX}/share/pip/pip.conf for --global
global /Library/Application Support/pip/pip.conf for --global
site ${HOMEBREW_OPT}/python@3.14/Frameworks/Python.framework/Versions/3.14/pip.conf for --site
site ${VIRTUAL_ENV}/pip.conf for --site, venv config file
user ~/.pip/pip.conf for --user, legacy config
user ~/.config/pip/pip.conf for --user, XDG config path
  • when pip config set ( without --global or --site ), the config will write into ~/.config/pip/pip.conf (XDG config path)

    [!NOTE|label:priority:]

  • when config conflict

    [!NOTE|label:priority:]

    • priority: command line > environment variable > site config file > user config file > global config file
    • because of : OVERRIDE_ORDER
      kinds = enum(
          USER="user",       # User Specific
          GLOBAL="global",   # System Wide
          SITE="site",       # [Virtual] Environment Specific
          ENV="env",         # from PIP_CONFIG_FILE
          ENV_VAR="env-var", # from Environment Variables
      )
      OVERRIDE_ORDER = kinds.GLOBAL, kinds.USER, kinds.SITE, kinds.ENV, kinds.ENV_VAR       # the latter covers the former
      

loading order

PRIORITY TYPE SOURCE
highest command line flag Command-Line Interface, i.e.: --keyring-provider
ENV_VAR Environment Variable, i.e.: PIP_*
ENV ENV configured in PIP_CONFIG_FILE
SITE i.e.: ${VIRTUAL_ENV}/pip.conf
USER ~/.config/pip/pip.conf > ~/.pip/pip.conf
lowest GLOBAL /Library/Application Support/pip/..., /opt/homebrew/share/pip/pip.conf

options

pip

PARAMETER VALUE ENVIRONMENT VARIABLE
-h, --help - PIP_HELP
-v, --verbose - PIP_VERBOSE
-q, --quiet - PIP_QUIET
--debug - PIP_DEBUG
--isolated - PIP_ISOLATED
--require-virtualenv - PIP_REQUIRE_VIRTUALENV, PIP_REQUIRE_VENV
--python <python> PIP_PYTHON
--log <path> PIP_LOG
--no-input - PIP_NO_INPUT
--keyring-provider auto*, disabled, import, subprocess PIP_KEYRING_PROVIDER
--proxy <proxy> PIP_PROXY
--no-proxy-env - PIP_NO_PROXY_ENV
--retries <n> (5*) PIP_RETRIES
--timeout <seconds> (15*) PIP_TIMEOUT
--exists-action <action> (s*, i, w, b, a) PIP_EXISTS_ACTION
--trusted-host <hostname> PIP_TRUSTED_HOST
--cert <path> PIP_CERT
--client-cert <path> PIP_CLIENT_CERT
--cache-dir <dir> (~/.cache/pip*) PIP_CACHE_DIR
--no-cache-dir - PIP_NO_CACHE_DIR
--disable-pip-version-check - PIP_DISABLE_PIP_VERSION_CHECK
--no-color - PIP_NO_COLOR
--use-feature <feature> PIP_USE_FEATURE
--use-deprecated <feature> PIP_USE_DEPRECATED
--resume-retries <n> (5*) PIP_RESUME_RETRIES

pip install

PARAMETER VALUE ENVIRONMENT VARIABLE
-r, --requirement <file> PIP_REQUIREMENTS
-c, --constraint <file> PIP_CONSTRAINTS
--build-constraint <file> PIP_BUILD_CONSTRAINTS
--requirements-from-script <file> PIP_REQUIREMENTS_FROM_SCRIPT
--no-deps - PIP_NO_DEPS, PIP_NO_DEPENDENCIES
--only-deps - PIP_ONLY_DEPS, PIP_ONLY_DEPENDENCIES
-e, --editable <path/url> PIP_EDITABLE
--dry-run - PIP_DRY_RUN
-t, --target <dir> PIP_TARGET
--platform <platform> PIP_PLATFORM
--python-version <python_version> PIP_PYTHON_VERSION
--implementation <implementation> PIP_IMPLEMENTATION
-abi <abi> PIP_ABI
--user - PIP_USER
--root <dir> PIP_ROOT
--prefix <dir> PIP_PREFIX
--src <dir> PIP_SRC
-U, --upgrade - PIP_UPGRADE
--upgrade-strategy only-if-needed*, eager PIP_UPGRADE_STRATEGY
--force-reinstall - PIP_FORCE_REINSTALL
-I, --ignore-installed - PIP_IGNORE_INSTALLED
--ignore-requires-python - PIP_IGNORE_REQUIRES_PYTHON
--no-build-isolation - PIP_NO_BUILD_ISOLATION
--check-build-dependencies - PIP_CHECK_BUILD_DEPENDENCIES
--break-system-packages - PIP_BREAK_SYSTEM_PACKAGES
-C, --config-settings <setting> PIP_CONFIG_SETTINGS
--compile - PIP_COMPILE
--no-compile - PIP_NO_COMPILE
--no-warn-script-location - PIP_NO_WARN_SCRIPT_LOCATION
--no-warn-conflicts - PIP_NO_WARN_CONFLICTS
--require-hashes - PIP_REQUIRE_HASHES
--no-require-hashes - PIP_NO_REQUIRE_HASHES
--progress-bar auto*, off, on, raw PIP_PROGRESS_BAR
--root-user-action warn*, ignore PIP_ROOT_USER_ACTION
--report <file> PIP_REPORT
--group <[path:]group> PIP_GROUP
--no-clean - PIP_NO_CLEAN
-i, --index-url <url> PIP_INDEX_URL
--extra-index-url <url> PIP_EXTRA_INDEX_URL
--no-index - PIP_NO_INDEX
--refresh-package <refresh_package> PIP_REFRESH_PACKAGE
-f, --find-links <url> PIP_FIND_LINKS
--uploaded-prior-to <datetime_or_duration> PIP_UPLOADED_PRIOR_TO
--pre - PIP_PRE
--all-releases <release_control> PIP_ALL_RELEASES
--only-final <release_control> PIP_ONLY_FINAL
--no-binary <format_control> PIP_NO_BINARY
--only-binary <format_control> PIP_ONLY_BINARY
--prefer-binary - PIP_PREFER_BINARY

pip uninstall

PARAMETER VALUE ENVIRONMENT VARIABLE
-r, --requirement <file> PIP_REQUIREMENTS
-y - PIP_YES
--root-user-action warn*, ignore PIP_ROOT_USER_ACTION
--break-system-packages - PIP_BREAK_SYSTEM_PACKAGES

pip index

PARAMETER VALUE ENVIRONMENT VARIABLE
--platform <platform> PIP_PLATFORM
--python-version <python_version> PIP_PYTHON_VERSION
--implementation <implementation> PIP_IMPLEMENTATION
--abi <abi> PIP_ABI
--ignore-requires-python - PIP_IGNORE_REQUIRES_PYTHON
--json - PIP_JSON
-i, --index-url <url> PIP_INDEX_URL
--extra-index-url <url> PIP_EXTRA_INDEX_URL
--no-index - PIP_NO_INDEX
--refresh-package <refresh_package> PIP_REFRESH_PACKAGE
-f, --find-links <url> PIP_FIND_LINKS
--uploaded-prior-to <datetime_or_duration> PIP_UPLOADED_PRIOR_TO
--pre - PIP_PRE
--all-releases <release_control> PIP_ALL_RELEASES
--only-final <release_control> PIP_ONLY_FINAL
--no-binary <format_control> PIP_NO_BINARY
--only-binary <format_control> PIP_ONLY_BINARY
--prefer-binary - PIP_PREFER_BINARY

pip config

PARAMETER VALUE ENVIRONMENT VARIABLE
--editor <editor> PIP_EDITOR
--global - PIP_GLOBAL
--user - PIP_USER
--site - PIP_SITE

list all configs

[!NOTE]

# to check where config comes from
$ python -m pip config debug
env_var:
env:
global:
  /etc/xdg/pip/pip.conf, exists: False
  /etc/pip.conf, exists: True
    global.index-url: https://artifactory.domain.com/artifactory/api/pypi/tools/simple
site:
  /usr/pip.conf, exists: False
user:
  /home/marslo/.pip/pip.conf, exists: False
  /home/marslo/.config/pip/pip.conf, exists: False

# or
$ pip config -v list
For variant 'global', will try loading '/opt/homebrew/share/pip:/Library/Application Support/pip/pip.conf'
For variant 'user', will try loading '/Users/marslo/.pip/pip.conf'
For variant 'user', will try loading '/Users/marslo/.config/pip/pip.conf'
For variant 'site', will try loading '/opt/homebrew/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/pip.conf'
:env:.break-system-packages='true'
global.break-system-package='true'

$ echo "${PIP_BREAK_SYSTEM_PACKAGES}"
true

samples

[!NOTE|label:references:]

FLAG pip.conf (under [install]) pip.config (under [global])
--ignore-installed ignore-installed = true -
--no-dependencies no-dependencies = yes -
--no-compile no-compile = yes -
--no-warn-script-location no-warn-script-location = yes -
--no-cache-dir - no-cache-dir = yes
--break-system-packages - break-system-packages = true
--user - user = true
--extra-index-url <HOST> - extra-index-url = <HOST>
  • --verbose and --quiet

    [!NOTE|label:references:]

    • verbose: export PIP_VERBOSE=<n> == pip install [-v, -vv, -vvv, -vvvv]
      • 0: no output
      • 1: print only errors
      • 2: print errors and warnings
      • 3: print errors, warnings, and info
      • 4: print everything
    [global]
    verbose = 2
    quiet = 0
    
  • --trusted-host

    [install]
    trusted-host =
        mirror1.example.com
        mirror2.example.com
    
  • --find-links

    [global]
    find-links =
        http://download.example.com
    
    [install]
    find-links =
        http://mirror1.example.com
        http://mirror2.example.com
    

authentication

keyring

OPTION VALUE
keyring-provider subprocess, import, auto
# install
$ python3 -m pip install keyring
$ python3 -m pip install --user 'keyring[completion]'

# config
$ pip config set --user global.keyring-provider import
$ pip config set --user global.keyring-provider auto
$ pip config set --user global.keyring-provider subprocess

# setup keyring
#                                                                 artifactory MUST ends with `/` for keyring setup
#                                                                                   v
$ keyring set "https://artifactory.domain.com/artifactory/api/pypi/pypi-local/simple/" marslo
Password for 'marslo' in 'https://artifactory.domain.com/artifactory/api/pypi/pypi-local/simple':
$ echo -n 'cm************************************************************ly' | keyring set "https://artifactory.domain.com/artifactory/api/pypi/devops-local/simple/" marslo

# get password
$ keyring get "https://artifactory.domain.com/artifactory/api/pypi/pypi-local/simple/" marslo
cm************************************************************ly
$ security find-generic-password -s "https://artifactory.domain.com/artifactory/api/pypi/pypi-local/simple/" -a marslo -w
cm************************************************************ly

# install
#
$ python3 -m pip install --upgrade --user <PKG_NAME> --keyring-provider auto --extra-index-url https://artifactory.domain.com/artifactory/api/pypi/pypi-local/simple --break-system-packages

[!TIP|label:subprocess 401:] Whenever pip resolves keyring through the CLI (provider subprocess, or auto once the in-process import fails), it REFUSES a keyring executable located in its own scripts directory.

reason: keyring lives in /opt/homebrew/bin, and pip's sysconfig.get_path('scripts') is also /opt/homebrew/bin.
The subprocess provider has an anti-recursion guard - pip/_internal/network/auth.py

CLI (/opt/homebrew/bin/keyring) starts with scripts directory (/opt/homebrew/bin) → excluded the scripts directory from PATH (/opt/homebrew/bin) → keyring not found → provider set to disabled → no credentials sent → 401

$ python3 -c "import shutil; print( shutil.which('keyring') )"
/opt/homebrew/bin/keyring
$ python3 -c "import sysconfig; print(sysconfig.get_path('scripts'))"
/opt/homebrew/bin

solution

  • use --keyring-provider import or --keyring-provider auto instead of subprocess
    $ python3 -m pip config set global.keyring-provider auto
    
  • pip install with --user
    $ python3 -m pip install --user keyring
    
  • pipx install to ~/.local/bin
    $ pipx install keyring
    

tricky

argcomplete

$ python3 -m pip install -U argcomplete

$ sudo mkdir -p $(brew --prefix)/etc/bash_completion.d
$ activate-global-python-argcomplete --dest=$(brew --prefix)/etc/bash_completion.d

$ grep bash_completion.sh ~/.bash_profile ~/.bashrc
/Users/marslo/.bash_profile:  [[ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh"      ]] && source "$(brew --prefix)/etc/profile.d/bash_completion.sh"

# enable completion for pipx
$ echo 'eval "$(register-python-argcomplete pipx)"' >> ~/.bashrc

get size of installed pip package

$ pip list |
      tail -n +3 |
      awk '{print $1}' |
      xargs pip show |
      grep --color=never -E 'Location:|Name:' |
      cut -d ' ' -f 2 |
      paste -d ' ' - - |
      awk '{print $2 "/" tolower($1)}' |
      xargs du -sh 2> /dev/null |
      sort -hr
124M  /Users/marslo/Library/Python/3.12/lib/python/site-packages/cmake
28M   /usr/local/lib/python3.12/site-packages/kubernetes
16M   /usr/local/lib/python3.12/site-packages/pip
13M   /usr/local/lib/python3.12/site-packages/ansible
9.9M  /usr/local/lib/python3.12/site-packages/cryptography
8.8M  /usr/local/lib/python3.12/site-packages/pygments
5.1M  /usr/local/lib/python3.12/site-packages/setuptools
1.5M  /usr/local/lib/python3.12/site-packages/msgpack
1.5M  /usr/local/lib/python3.12/site-packages/greenlet
1.3M  /usr/local/lib/python3.12/site-packages/pycparser
1.3M  /usr/local/lib/python3.12/site-packages/oauthlib
1.2M  /usr/local/lib/python3.12/site-packages/jinja2
948K  /usr/local/lib/python3.12/site-packages/pyasn1
848K  /usr/local/lib/python3.12/site-packages/cffi
824K  /Users/marslo/Library/Python/3.12/lib/python/site-packages/fortls
820K  /usr/local/lib/python3.12/site-packages/click
784K  /usr/local/lib/python3.12/site-packages/urllib3
556K  /usr/local/lib/python3.12/site-packages/wheel
556K  /Users/marslo/Library/Python/3.12/lib/python/site-packages/pynvim
520K  /usr/local/lib/python3.12/site-packages/tqdm
520K  /usr/local/lib/python3.12/site-packages/pipx
520K  /usr/local/lib/python3.12/site-packages/idna
456K  /usr/local/lib/python3.12/site-packages/requests
360K  /usr/local/lib/python3.12/site-packages/packaging
348K  /usr/local/lib/python3.12/site-packages/asciidoc
312K  /usr/local/lib/python3.12/site-packages/certifi
244K  /usr/local/lib/python3.12/site-packages/rsa
204K  /usr/local/lib/python3.12/site-packages/argcomplete
204K  /Users/marslo/Library/Python/3.12/lib/python/site-packages/json5
196K  /usr/local/lib/python3.12/site-packages/tabulate
156K  /usr/local/lib/python3.12/site-packages/distlib
140K  /usr/local/lib/python3.12/site-packages/resolvelib
96K   /usr/local/lib/python3.12/site-packages/argopt
88K   /usr/local/lib/python3.12/site-packages/cachetools
84K   /usr/local/lib/python3.12/site-packages/userpath
44K   /usr/local/lib/python3.12/site-packages/platformdirs
32K   /usr/local/lib/python3.12/site-packages/bashate
28K   /usr/local/lib/python3.12/site-packages/pbr
20K   /usr/local/lib/python3.12/site-packages/markupsafe
0     /usr/local/lib/python3.12/site-packages/virtualenv
0     /usr/local/lib/python3.12/site-packages/tbb
0     /usr/local/lib/python3.12/site-packages/openvino
0     /usr/local/lib/python3.12/site-packages/numpy
0     /usr/local/lib/python3.12/site-packages/filelock
0     /usr/local/lib/python3.12/site-packages/docutils

pipx

[!NOTE|label:references:]

setup pipx

$ python3 -m pip install pipx
$ pipx ensurepath
$ pipx install ansible --include-deps

# re-install pipx if system python version changed
$ pipx reinstall-all --python /bin/python3.11
# or
$ pipx reinstall-all --python "$(command -v python3)"

# -- upgrade pipx -- #
$ python3 -m pip install --user --upgrade pipx

show info

$ pipx environment
$ pipx environment --value PIPX_VENV_CACHEDIR
$ pipx environment --value PIPX_LOG_DIR
$ pipx environment --value PIPX_TRASH_DIR
$ pipx environment --value PIPX_HOME

check health

$ pipx health

examples

  • pipx install

    $ pipx install pycowsay
    $ pipx install --python python3.10 pycowsay
    $ pipx install --python 3.12 pycowsay
    $ pipx install --fetch-missing-python --python 3.12 pycowsay
    
    # install from source control
    $ pipx install git+https://github.com/psf/black.git
    $ pipx install git+ssh://git@github.com/psf/black
    $ pipx install git+https://github.com/psf/black.git@branch
    $ pipx install git+https://github.com/psf/black.git@ce14fa8b497bae2b50ec48b3bd7022573a59cdb1
    $ pipx install https://github.com/psf/black/archive/18.9b0.zip
    
    $ pipx install black[d]
    $ pipx install --preinstall ansible-lint --preinstall mitogen ansible-core
    $ pipx install 'black[d] @ git+https://github.com/psf/black.git@branch-name'
    $ pipx install --suffix @branch-name 'black[d] @ git+https://github.com/psf/black.git@branch-name'
    $ pipx install --include-deps jupyter
    
    # install with pip args
    $ pipx install --pip-args='--pre' poetry
    $ pipx install --pip-args='--index-url=<private-repo-host>:<private-repo-port> --trusted-host=<private-repo-host>:<private-repo-port>' private-repo-package
    
    $ pipx --global install pycowsay
    
    # install from local
    $ pipx install .
    $ pipx install path/to/some-project
    
    # with private index
    $ pipx install my-package --index-url https://my-index.example.com/simple/
    $ pipx install my-package --index-url https://test.pypi.org/simple/ --pip-args='--extra-index-url https://pypi.org/simple/'
    $ pipx install my-package --pip-args="--extra-index-url https://my-index.example.com/simple/"
    $ pipx install my-package --pip-args="--index-url https://my-index.example.com/simple/ --trusted-host my-index.example.com"
    # -- with pip environment variable --
    $ export PIP_INDEX_URL=https://my-index.example.com/simple/
    $ export PIP_TRUSTED_HOST=my-index.example.com
    $ pipx install my-private-package
    
    # install offline
    $ pipx install my-package --pip-args="--no-index --find-links /path/to/wheels"
    
  • pipx install-all

    $ pipx list --json > pipx.json
    $ pipx instal-all pipx.json
    
  • pipx run

    $ pipx run BINARY  # latest version of binary is run with python3
    $ pipx run --spec PACKAGE==2.0.0 BINARY  # specific version of package is run
    $ pipx run --python python3.10 BINARY  # Installed and invoked with specific Python version
    $ pipx run --python python3.9 --spec PACKAGE=1.7.3 BINARY
    $ pipx run --spec git+https://url.git BINARY  # latest version on default branch is run
    $ pipx run --spec git+https://url.git@branch BINARY
    $ pipx run --spec git+https://url.git@hash BINARY
    $ pipx run pycowsay moo
    $ pipx --version  # prints pipx version
    $ pipx run pycowsay --version  # prints pycowsay version
    $ pipx run --python pythonX pycowsay
    $ pipx run pycowsay==2.0 --version
    $ pipx run pycowsay[dev] --version
    $ pipx run --spec git+https://github.com/psf/black.git black
    $ pipx run --spec git+https://github.com/psf/black.git@branch-name black
    $ pipx run --spec git+https://github.com/psf/black.git@git-hash black
    $ pipx run --spec https://github.com/psf/black/archive/18.9b0.zip black --help
    $ pipx run https://gist.githubusercontent.com/cs01/fa721a17a326e551ede048c5088f9e0f/raw/6bdfbb6e9c1132b1c38fdd2f195d4a24c540c324/pipx-demo.py
    
  • pipx inject

    $ pipx install ptpython
    $ pipx inject ptpython requests pendulum
    
  • pipx upgrade-shared

    $ pipx upgrade-shared
    $ pipx upgrade-shared --pip-args=pip==24.0
    

troubleshooting

  • error: externally-managed-environment

    [!NOTE|label:references:]

    • issue

      $ pip install pipx
      error: externally-managed-environment
      
      × This environment is externally managed
      ╰─> To install Python packages system-wide, try brew install
          xyz, where xyz is the package you are trying to
          install.
      
          If you wish to install a non-brew-packaged Python package,
          create a virtual environment using python3 -m venv path/to/venv.
          Then use path/to/venv/bin/python and path/to/venv/bin/pip.
      
          If you wish to install a non-brew packaged Python application,
          it may be easiest to use pipx install xyz, which will manage a
          virtual environment for you. Make sure you have pipx installed.
      
      note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
      hint: See PEP 668 for the detailed specification.
      
    • solution: ignore by pip.config

      [!TIP|label:rerefences:]

      • pip.config:
        • ~/.pip/pip.conf
        • ~/.config/pip/pip.conf
      • check pip config:
        $ python3 -m pip config debug
        env_var:
        env:
        global:
          /opt/homebrew/share/pip:/Library/Application Support/pip/pip.conf, exists: False
        site:
          /opt/homebrew/opt/python@3.13/Frameworks/Python.framework/Versions/3.13/pip.conf, exists: False
        user:
          /Users/marslo/.pip/pip.conf, exists: True
            global.break-system-package: true
          /Users/marslo/.config/pip/pip.conf, exists: False
        
      # setup by command
      $ python3 -m pip config set global.break-system-packages true
      
      # or added manually
      $ cat ~/.pip/pip.conf
      [global]
      break-system-package = true
      
    • solution: via option temporary

      $ python3 -m pip install --upgrade pip --break-system-packages
      
      # or
      $ python3 -m pip install --upgrade pip --system-site-packages
      
    • solution: via environment variable

      $ export PIP_BREAK_SYSTEM_PACKAGES=true
      $ python3 -m pip install --upgrade pip
      
      # or
      $ PIP_BREAK_SYSTEM_PACKAGES=true python3 -m pip install --upgrade pip
      
    • solution: remove EXTERNALLY-MANAGED file

      # 3.12
      $ mv $(brew --prefix python@3.12)/Frameworks/Python.framework/Versions/3.12/lib/python3.12/EXTERNALLY-MANAGED{,.bak}
      # 3.13
      $ mv $(brew --prefix python@3.13)/Frameworks/Python.framework/Versions/3.13/lib/python3.13/EXTERNALLY-MANAGED{,.bak}
      
  • Skipping ... due to invalid metadata entry 'name'

    [!NOTE|label:info]

    • changelog : 23.2 (2023-07-15) Deprecate support for eggs for Python 3.11 or later, when the new importlib.metadata backend is used to load distribution metadata. This only affects the egg distribution format (with the .egg extension); distributions using the .egg-info metadata format (but are not actually eggs) are not affected. For more information about eggs, see relevant section in the setuptools documentation
    • solution

      $ pip list
      WARNING: Skipping /usr/local/lib/python3.12/site-packages/six-1.16.0-py3.12.egg-info due to invalid metadata entry 'name'
      
      $ pip uninstall six
      $ rm -rf /usr/local/lib/python3.12/site-packages/six-1.16.0-py3.12.egg-info
      # if necessary
      $ rm -rf /usr/local/lib/python3.12/site-packages/six-1.16.0-py3.12.dist-info
      $ pip install six
      
  • has inconsistent version

    [!NOTE|label:references:]

    • solution
      $ python -m pip install --upgrade --no-cache-dir --use-deprecated=legacy-resolver <your_package>
      
Copyright © marslo 2020-2026 all right reserved,powered by GitbookLast Modified: 2026-08-06 18:43:32

results matching ""

    No results matching ""