「记录」一些Python相关的命令

环境相关

升级pip

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

创建虚拟环境

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

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

使用虚拟环境

source venv/bin/activate

退出虚拟环境

deactivate

编译python

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导出包列表

pip freeze > requirements.txt

pip恢复包

pip install -r requirements.txt

安装证书

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