PyPi Statistics¶
You can check download statistics of Python Packages on PYPI at https://
Prefer Virtual Environment + pip¶
Virtual environment + pip is the preferred way to install Python packages.
Install pip¶
pip should be already available when you create a Python virtual environment.
Bootstrapping the pip Installer¶
The package ensurepip provides support for bootstrapping the pip installer into an existing Python installation or virtual environment.
sudo python3 -m ensurepipInstall a Specific Version of a Python Package¶
List all available versions of a Python package.
:::bash pip3 install pylibmc==Install a specific version of a Python package.
:::bash pip3 install MySQL_python==1.2.2Install pyarrow with a verison of at least 0.14.0. Notice that you must quote
pyarrow>=0.14.0using single/double quotes.:::bash pip3 install 'pyarrow>=0.14.0'Install a Python package with a version in a range.
:::bash pip3 install "jupyterlab>=1.2.7,<2.0.0"You can install the pre-release version of a package using the
--preoption. For example, the current version of pybuilder (0.11.7) is not compatible with Python 3.7. If you are using Python 3.7 and still want to use the pybuilder package, you can install the pre-release version (0.12) which is compatible with Python 3.7.:::bash pip3 install --pre pybuilder
Install Python Packages from Source¶
Install Python package from a
tar.gzfile which contains the source code.:::bash pip3 install xinstall-0.23.0.tar.gzInstall from the current directory
:::bash pip3 install .pip20.0+ supports instaling a peotry managed Python project from GitHub directly. For example, the comamnd below installs the Python package dsutil from the GitHub repository dclong/dsutil directly.:::bash pip3 install git+ssh://git@github.com/dclong/dsutil # or pip3 install git+https://github.com/dclong/xinstall # or install with optional components pip3 install --user -U "dsutil[all] @ git+https://github.com/dclong/dsutil@main" pip3 install "dsutil[cv] @ file:///home/dclong/dsutil-0.54.1-py3-none-any.whl" pip3 install "dsutil[cv] @ https://github.com/dclong/dsutil/releases/download/v0.54.1/dsutil-0.54.1-py3-none-any.whl"If you are behind a corporate proxy, you might need 2FA to visit the enterprise GitHub of your company. However, 2FA is usually not required for Git comamnd line (since it would too much hassle). The above way to install Python packages from GitHub repositories directly can be a good way to avoid 2FA authentication if you are behind a corporate proxy.
Install Python Packages from Requirements.txt¶
You can install Python packages from a requirements.txt file.
:::bash
pip3 install -r requirements.txtNotice that all formats accepted by pip3 install is valid in requirements.txt.
For example,
git+https://github.com/dclong/dsutil@master is valid to use in requirements.txt.
Difference between --ignore-installed and --force-reinstall¶
Sometimes a package is installed by distutils
which cannot be reinstalled using pip,
not even with the --force-reinstall option.
In that case,
you have to use the --ignore-installed option.
For more discussions,
please refer to
Difference Between Pip Install Options Ignore Installed and Force Reinstall
and
blockstack-core::Issues 504
.
Install Python Packages Without Installing Dependencies¶
You can install a Python package without installing its dependencies using the command below.
:::bash
pip3 install --no-deps some_packageUpgrade Python Packages¶
You can upgrade an already installed Python package to the latest version using the command below.
:::bash
pip3 install --upgrade wheelList All Installed Python Packages¶
List all installed modules.
:::bash pip3 listList outdated modules only.
:::bash pip3 list --outdatedYou can also use
help('modules')to show all installed modules in Python.
Use pip with Proxy¶
You can export environment variables http_proxy and https_proxy
or you can use pip with the --proxy option directly.
pip3 --proxy http://proxy__server_ip:port install some_pkgWhen using the --proxy with pip/pip3,
you can omit http:// and the port if the port is 80.
pip3 --proxy 10.135.227.47 search notifiersNotice that sometimes pip does not respect the environment variables.
In that case,
you have to use the option --proxy to pass proxy to pip.
And even with the option --proxy,
pip might not work well if you install from a version control system.
Just be ware of that.
ProxyChains
is likely a solution when that issue happens.
Misc¶
pipsupports downloading Python packages without installing them. At the same time, you can disablepipcaching using the option--no-cache-dir. For more discussions, please refer to Caching .export LC_ALL=Cresolves an issues (cannot remember which issue exactly) of pip3.
Installation Location¶
Please refer to The Installation Location of Python Packages Using Pip for more discussions.
Check for Existence of a Python Package¶
The most robust way turns out to be pip3 list,
because some packages are namespace sub packagess
which are not exposed (visible to importlib) by default.
However,
all installed packages (via pip) are visible to pip.
:::bash
pip3 list | grep -i pelican-render-mathReferences¶
https://
https://
http://
http://
https://
https://
https://
https://
How to pip install a package with min and max version range?
How to state in requirements.txt a direct github source
‘pip install’ From a Git Repository