# use pip mirror for speeding up $ pip3 install -U pip # OR $ pip install -U pip
$ pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/ # OR manually edit /root/.config/pip/pip.conf $ cat /root/.config/pip/pip.conf [global] index-url = http://mirrors.aliyun.com/pypi/simple/ # or change index-url temporary for each install $ pip install --index-url http://mirrors.aliyun.com/pypi/simple/ ansible-core==2.11.12
$ pip cache dir /home/ubuntu/.cache/pip
$ pip cache list Nothing cached.
# global install, all users see it!!! $ sudo pip install package_name # install/uninstall for current user $ pip install package_name # ~/.local/lib/python
# list all version of given package $ pip install ansible==not_exist # install a package of given version $ pip install package_name==version $ pip uninstall package_name
# pip list --format=freeze>req.txt $ pip install -r req.txt
# !!!while dpkg -l only shows apt-get installed packages!!!
# show info of package $ pip show self-tool-lib Name: self-tool-lib Version: 0.1 Summary: self utilities for tool Home-page: Author: Jason Luo Author-email: jason_lkm@163.com License: UNKNOWN Location: /home/data/Anaconda3/envs/py3.9/lib/python3.9/site-packages Requires: Required-by:
# show files of installed package $ pip show -f self-tool-lib Name: self-tool-lib Version: 0.1 Summary: self utilities for tool Home-page: Author: Jason Luo Author-email: jason_lkm@163.com License: UNKNOWN Location: /home/data/Anaconda3/envs/py3.9/lib/python3.9/site-packages Requires: Required-by: Files: self_tool_lib-0.1.dist-info/INSTALLER self_tool_lib-0.1.dist-info/LICENSE self_tool_lib-0.1.dist-info/METADATA self_tool_lib-0.1.dist-info/RECORD self_tool_lib-0.1.dist-info/REQUESTED self_tool_lib-0.1.dist-info/WHEEL self_tool_lib-0.1.dist-info/direct_url.json self_tool_lib-0.1.dist-info/top_level.txt
# show files in wheel file(which can be installed by pip directly) # pip install dist/self_tool_lib-0.1-py3-none-any.whl $ python -m zipfile --list dist/self_tool_lib-0.1-py3-none-any.whl File Name Modified Size self_tool_lib-0.1.dist-info/LICENSE 2022-06-14 15:19:08 1074 self_tool_lib-0.1.dist-info/METADATA 2022-06-14 15:19:08 403 self_tool_lib-0.1.dist-info/WHEEL 2022-06-14 15:19:08 92 self_tool_lib-0.1.dist-info/top_level.txt 2022-06-14 15:19:08 1 self_tool_lib-0.1.dist-info/RECORD 2022-06-14 15:19:08 404
Note: some python pkg may be only available by apt source or pypi source, not both
pkg source is different
apt-get can install any package from remote repo, not only python related but pip/pip3 only for python package, for some python packages you can install it from apt-get or pip, the difference is apt-get use source.list library that's dedicated for particular ubuntu version, the package from there is always old, but pip uses its own library(PyPI https://pypi.org/pypi) which always have new version for the application, while for some python package, apt-get may NOT have. from apt-get you can’t specify the version to install while pip can have.
pypi usually has many versions of a single pkg while apt source only has one
install dest location is different
apt-get installs python modules in system-wide location. We cannot just install modules in our project virtualenv. pip solves this problem for us. If we are using pip after activating the virtualenv, it is intelligent enough to only install the modules in our project virtualenv. As mentioned in previous point, if there is a version of a particular python package already installed in system-wide location, and one of our project requires an older version of the same python package, in such situations we can use virtualenv and pip to install that older version of python package without any conflicts.
apt dest location
1 2 3 4
# show dest location $ dpkg -L python3-httplib2 /usr/bin /usr/lib/
pip dest location
1 2 3 4 5 6
# show dest location $ pip show httplib2 /user/local/bin /usr/local/lib ~/.local/lib ~/.local/bin
if you install one package by these two, there will be two copies(may be two version of this pkg), but apt-get always wins, as the sys.path always, /usr/bin/; /usr/local/bin, but you can change the PATH.
conda(which has its own repo: https://anaconda.org/) is another way to install python pkg, as conda has a python env, activated after you reboot system after installation, hence pip/pip3 comes from conda python env, all packages installed either by conda or pip, they see the others as well!!!.