目录

一些Python相关的命令

环境相关

升级pip

1
python -m pip install -U --force-reinstall pip

创建虚拟环境

1
2
3
virtualenv --no-site-packages venv #创建默认Python版本的虚拟环境

virtualenv -p /usr/local/bin/python3 --no-site-packages venv #创建自定义Python版本的虚拟环境

使用虚拟环境

1
source venv/bin/activate

退出虚拟环境

1
deactivate

编译python

1
2
3
4
5
6
7
rm -rf /usr/local/python3
./configure --prefix=/usr/local/python3/
make && make install
rm -rf /usr/local/bin/python3
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3
rm -rf /usr/local/bin/pip3
ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3

pip导出包列表

1
pip freeze > requirements.txt

pip恢复包

1
pip install -r requirements.txt

安装证书(macOS上python根的证书不被信任)

注意
这是macOS特有问题
1
2
cd /Applications/Python\ 3.8
sudo ./Install\ Certificates.Command