前言
本文汇总下python环境的安装与卸载。
卸载python环境
- 卸载系统环境内的python环境
sh
python_version_number=3.10
sudo rm -rf /Library/Frameworks/Python.framework/Versions/${python_version_number}/
sudo rm -rf "/Applications/Python ${python_version_number}/"
cd /usr/local/bin && ls -l | grep "/Library/Frameworks/Python.framework/Versions/${python_version_number}" | awk '{print $9}' | sudo xargs rm
- 卸载homebrew中python
sh
# 查看已安装python版本
brew search python
# 查看已安装python版本
brew list | grep python
# 卸载指定python版本
brew uninstall python@3.11
安装
- 通过brew安装
HomeBrew安装python路径为/opt/homebrew/Cellar/python@3.9
里面存放HomeBrew所安装版。
sh
brew install python@3.9
# which命令查看python3程序地址
which python3
- 通过官网安装
通过官网https://www.python.org/downloads/macos/下载指定版本,一路点击Next,即可安装。
安装路径在:/Library/Frameworks/Python.framework/Versions/3.x
sh
# 配置.bash_profile
open ~/.bash_profile
export PATH=${PATH}:/Library/Frameworks/Python.framework/Versions/3.9/bin
export PATH=${PATH}:/Library/Frameworks/Python.framework/Versions/3.9/bin/pip3.9
open ~/.zshrc
在zshrc文件内追加 source ~/.bash_profile
virtualenv
安装虚拟环境
sh
pip3 install virtualenv
# 查看是否安装成功
virtualenv --version