当前位置: 首页 > 工具软件 > MacPython > 使用案例 >

mac python配置环境变量

公冶宏深
2023-12-01

python环境变量

第一步

打开终端

open ~/.bash_profile 

将以下代码复制,改一下python版本

#Setting PATH for Python 3.10

export PATH=${PATH}:/Library/Frameworks/Python.framework/Versions/3.10/bin

alias python="/Library/Frameworks/Python.framework/Versions/3.10/bin/python3.10"

export PATH=${PATH}:/Library/Frameworks/Python.framework/Versions/3.10/bin

alias pip="/Library/Frameworks/Python.framework/Versions/3.10/bin/pip3"

export PATH="$PATH:/usr/local/bin/python3.10"

第二步:

source ~/.bash_profile

(使配置生效)

终端输入python

zhangsong@zhangsongdeMacBook-Pro ~ % python                
Python 3.10.1 (v3.10.1:2cd268a3a9, Dec  6 2021, 14:28:59) [Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

以上步骤应该就可以了,但是有的mac会出现环境变量配置仅生效一次可以用到以下操作

第三步:

open ~/.zshrc

输入以下代码

if [ -f ~/.bash_profile ]; then
   source ~/.bash_profile
fi

第四步:

source ~/.bash_profile

使配置生效

 类似资料: