Python pip 安装与使用

安装 pip

下载(Windows x86-64 embeddable zip file) https://www.python.org/downloads/windows & https://www.python.org/ftp/python & https://registry.npmmirror.com/binary.html?path=python

环境变量

# python.exe
python-x.x.x
# pip.exe
python-x.x.x\Scripts
# pip install xxx 后的 xxx.exe
python-x.x.x\Lib\site-packages\bin

下载 get-pip.py:https://bootstrap.pypa.io/get-pip.py & https://pip.pypa.io/en/stable/installation

curl -O https://bootstrap.pypa.io/get-pip.py
curl -O https://raw.githubusercontent.com/pypa/get-pip/main/public/get-pip.py
curl -O https://fastly.jsdelivr.net/gh/pypa/get-pip@main/public/get-pip.py
curl -O https://ghproxy.net/https://raw.githubusercontent.com/pypa/get-pip/main/public/get-pip.py

安装 pip

# 修改 pythonXX._pth 文件,去掉 #import site 前的 # 号。或直接删除该文件
# 安装 pip,先设置 pip 源安装会快一点
python get-pip.py
# 后续升级 pip
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U --trusted-host pypi.tuna.tsinghua.edu.cn
# 验证是否安装成功
python -m pip install --help

 

修改 pip 源

Windows 在用户目录下新建 pip\pip.ini 文件(也可以在 python.exe 同级目录创建 pip.ini),如:C:\Users\Administrator\pip\pip.ini

linux 在用户目录下新建 ~/.pip/pip.conf 文件

[global] 
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install] 
trusted-host = pypi.tuna.tsinghua.edu.cn

命令方式修改

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 如果提示源不受信任,就设置这个
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn

一些 pip 国内镜像

阿里云:https://mirrors.aliyun.com/pypi/simple/
中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban):https://pypi.douban.com/simple/
清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/

查看位置(默认从下往上的路径搜索)

python -m site
python -m site -help

USER_BASE python.exe 启动程序路径
USER_SITE 依赖安装包基础路径


python -m pip -v config list

For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\Administrator\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\Administrator\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'D:\PcAPP\Python\pip.ini'
global.index-url='https://mirrors.aliyun.com/pypi/simple/'
global.target='D:\\PcAPP\\Python\\Lib\\site-packages'
install.trusted-host='mirrors.aliyun.com'

更改 pip 安装位置

[global]
target = C:\python-x.x.x\Lib\site-packages

更改 pip 缓存位置

pip config set global.cache-dir "D:\MyFile\pip"

相当于
[global]
cache-dir = D:\MyFile\pip

 

常用 pip 命令

# 安装
pip install numpy

# 卸载
pip uninstall numpy

# 安装指定版本
pip install numpy==1.16.0

# 更新
pip install -U numpy

 

conda 命令

# 查看
conda info --env

# 创建
conda create -n labelme python=3

# 切换
conda activate labelme

# 删除
conda activate base
conda remove -n labelme --all

# 更新
conda update --all

Anaconda 环境变量

Anaconda3
Anaconda3\Scripts
Anaconda3\Library\bin

启动(Cmd 快捷方式)

# Anaconda Prompt (Anaconda3)
%windir%\System32\cmd.exe "/K" D:\PCAPP\Anaconda3\Scripts\activate.bat D:\PCAPP\Anaconda3

# Anaconda Powershell Prompt (Anaconda3)
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'D:\PCAPP\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'D:\PCAPP\Anaconda3' "

# 起始位置
%HOMEPATH%

 


https://mirrors.tuna.tsinghua.edu.cn/help/pypi

https://mirror.tuna.tsinghua.edu.cn/help/anaconda

https://repo.anaconda.com/miniconda

posted @ 2019-09-12 11:54  江湖小小白  阅读(566)  评论(0编辑  收藏  举报