python -m ensurepip –default-pip
获取安装代码
https://bootstrap.pypa.io/get-pip.py
python get-pip.py
默认会安装 setuptools 和 wheel
可通过下面参数取消安装:
–no-setuptools
–no-wheel
pip command [options]
https://pip.pypa.io/en/latest/reference/pip/#general-options
pip install [options]
https://pip.pypa.io/en/latest/reference/pip_install/#pip-install-options
从指定位置安装包
python get-pip.py –no-index –find-links=/local/copies
安装到 user site:
python get-pip.py –user
指定代理:
python get-pip.py –proxy=”http://[user:passwd@]proxy.server:port”
进入 pypi 官网下载源码包
https://pypi.python.org/pypi/pip#downloads
解压源码包 python setup.py install
apt-get install python-pip
apt-get install python3-pip
Linux: pip install -U pip
Windows: python -m pip install -U pip
如果安装了 setuptools、wheel,也要一起升级:
pip install -U pip setuptools wheel
python -m pip install –upgrade pip setuptools wheel
主要看环境变量的设置,python3 中 有时为了方便,也会命名 pip
mkdir ~/.pip
cat > ~/.pip/pip.conf << EOF
[global]
trusted-host=mirrors.aliyun.com
index-url=https://mirrors.aliyun.com/pypi/simple/
EOF
首先在window的文件夹窗口输入 : %APPDATA%
然后创建pip文件夹
最后创建pip.ini文件,写入如下内容
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
pip < command> [options] # 基本格式
python -m pip < command> [options] # 指定解释器运行
pip install SomePackage # 最新版本
pip install SomePackage==1.0.4 # 特定版本
pip install ‘SomePackage>=1.0.4’ # 最小版本
pip install SomePackage>=1.0.4,<=2.0 #
pip install -r requirements.txt # 从文件安装
####### example-requirements.txt #######
#
###### Requirements without Version Specifiers ######
nose
nose-cov
beautifulsoup4
#
###### Requirements with Version Specifiers ######
# See https://www.python.org/dev/peps/pep-0440/#version-specifiers
docopt == 0.6.1 # Version Matching. Must be version 0.6.1
keyring >= 4.1.1 # Minimum version 4.1.1
coverage != 3.5 # Version Exclusion. Anything except version 3.5
Mopidy-Dirble ~= 1.1 # Compatible release. Same as >= 1.1, == 1.*
#
###### Refer to other requirements files ######
-r other-requirements.txt
#
#
###### A particular file ######
./downloads/numpy-1.9.2-cp34-none-win32.whl
http://wxpython.org/Phoenix/snapshot-builds/wxPython_Phoenix-3.0.3.dev1820+49a8884-cp34-none-win_amd64.whl
#
###### Additional Requirements without Version Specifiers ######
# Same as 1st section, just here to show that you can put things in any order.
rejected
green
#
###### Other arguments ######
--no-index
--index-url https://pypi.python.org/simple/
--find-links /my/local/archives
--find-links http://some.archives.com/archives
pip install –upgrade SomePackage # 升级安装
pip install SomePackage-1.0-py2.py3-none-any.whl # 指定 whl 文件安装
pip install –no-index –find-links=/local/wheels -r requirements.txt # 只使用本地 whl 安装需要的包
pip install ./downloads/SomePackage-1.0.4.tar.gz # 指定源码安装
pip install http://my.package.repo/SomePackage-1.0.4.zip
pip install –user # 安装到 python 用户站点包目录,
# 默认 Linux ~/.local,MacOS ~/Library/Python/X.Y,Windows %APPDATA%\Python,
# 可通过 PYTHONUSERBASE 变量配置
# 当与系统安装包冲突时,忽略系统安装包;
# 当系统安装包满足要求时,不进行安装;
# 不在 virtualenv 上安装,对于 –system-site-packages 的 virtualenv 当有冲突时,也不安装。
pip install -e . # 安装当前目录已打包好的项目
pip install -e path/to/project # 安装指定目录已打包好的项目
pip install -e git+https://git.repo/some_pkg.git#egg=SomePackage # from git
pip install -e hg+https://hg.repo/some_pkg.git#egg=SomePackage # from mercurial
pip install -e svn+svn://svn.repo/some_pkg/trunk/#egg=SomePackage # from svn
pip install -e git+https://git.repo/some_pkg.git@feature#egg=SomePackage # from ‘feature’ branch
pip install -e “git+https://git.repo/some_repo.git#egg=subdir&subdirectory=subdir_path” # install a python package from a repo subdirectory
pip install –pre SomePackage # 安装预发行和安装的版本,默认安装的是稳定版本
pip uninstall -y SomePackage
pip uninstall -r requirements.txt
pip list # 列举所有包
pip list –outdated/-o # 列举可升级的包
pip list –format=json # json 格式输出
pip list –format=freeze # freeze 格式输出
pip show SomePackage # 查看包的信息
pip show –verbose SomePackage # 查看包的所有信息
pip show -f SomePackage # 显示包所在的目录
pip search < query >
pip freeze > requirements.txt
pip wheel –wheel-dir=/local/wheels SomePackage # 打包成 whl 文件
pip wheel –wheel-dir=/local/wheels -r requirements.txt
pip install –download DIR SomePackage # 包下载到指定目录
pip install -d DIR -r requirements.txt
Linux
/etc/pip.conf
也遵循 XDG_CONFIG_DIRS 变量
MacOS
/Library/Application Support/pip/pip.conf
WinXp
C:\Documents and Settings\All Users\Application Data\pip\pip.ini
Win7 +
C:\ProgramData\pip\pip.ini
不支持 WinVista
Linux
$HOME/.config/pip/pip.conf
也遵循 XDG_CONFIG_HOME 变量
MacOS
HOME/Library/ApplicationSupport/pipexists否则是 H O M E / L i b r a r y / A p p l i c a t i o n S u p p o r t / p i p e x i s t s 否 则 是 HOME/.config/pip/pip.conf
Windows
%APPDATA%\pip\pip.ini
Linux 或 MacOS
$VIRTUAL_ENV/pip.conf
Windows
%VIRTUAL_ENV%\pip.ini
[global]
timeout = 60
index-url = http://download.zope.org/ppix
no-cache-dir = false
find-links =
http://download.example.com
[freeze]
timeout = 10
[install]
ignore-installed = true
no-dependencies = yes
no-compile = no
find-links =
http://mirror1.example.com
http://mirror2.example.com
PIP_< UPPER_LONG_NAME>
将参数名中 - 替换为 _ 并大写
export PIP_FIND_LINKS=”http://mirror1.example.com http://mirror2.example.com”
等同于
pip install –find-links=http://mirror1.example.com –find-links=http://mirror2.example.com