如何在MAC上管理Python路径
我尝试运行 Django 项目并创建一个新应用程序。终端运行 python manage.py makemigrations 时,找不到 Django 并导入错误,且虚拟环境未激活?
经过我尝试寻找答案,可能是翻译的问题。然后我发现我安装了多个Python版本和anaconda。并且macOS包含Python 2.7。我完全困惑了。
以下是我的 zsh
文件
export PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8:$PATH"
#python
alias python='/usr/local/bin/python3' or alias python='/usr/bin/python3'
#conda
export PATH=/Users/smart/opt/anaconda3/bin:$PATH
#ruby
iterm2
smart@smartMBP ~ which python
python: aliased to /usr/bin/python3
smart@smartMBP ~ which -a python
python: aliased to /usr/bin/python3
/Users/smart/opt/anaconda3/bin/python
/usr/bin/python
smart@smartMBP ~ which -a python3
/Users/smart/opt/anaconda3/bin/python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
/usr/local/bin/python3
/usr/bin/python3
smart@smartMBP ~ conda --version
conda 4.7.12
smart@smartMBP ~ echo $PATH
/Users/smart/opt/anaconda3/bin
/Users/smart/bin
/opt/flutter/bin
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
/Library/Frameworks/Python.framework/Versions/3.9/bin
/Library/Frameworks/Python.framework/Versions/3.8/bin
我该怎么办?路径应该使用 '/Library/Frameworks/Python.framework' 或 '/usr/bin/' ? Zsh会只读取第一个有效路径,还是会继续读取覆盖的路径?
我想删除并重新安装,但我担心它会很糟糕,
谢谢您的建议
I try to run Django project and create a new app. When the terminal run python manage.py makemigrations ,Django cannot be found and import error ,and the virtual environment is not activated?
After I tried to search the answer, it might be the problem of the interpreter. Then I found that I had installed multiple Python versions and anaconda.And macOS contains Python 2.7. I was completely confused.
The following is my zsh
file
export PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8:$PATH"
#python
alias python='/usr/local/bin/python3' or alias python='/usr/bin/python3'
#conda
export PATH=/Users/smart/opt/anaconda3/bin:$PATH
#ruby
iterm2
smart@smartMBP ~ which python
python: aliased to /usr/bin/python3
smart@smartMBP ~ which -a python
python: aliased to /usr/bin/python3
/Users/smart/opt/anaconda3/bin/python
/usr/bin/python
smart@smartMBP ~ which -a python3
/Users/smart/opt/anaconda3/bin/python3
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
/usr/local/bin/python3
/usr/bin/python3
smart@smartMBP ~ conda --version
conda 4.7.12
smart@smartMBP ~ echo $PATH
/Users/smart/opt/anaconda3/bin
/Users/smart/bin
/opt/flutter/bin
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8
/Library/Frameworks/Python.framework/Versions/3.9/bin
/Library/Frameworks/Python.framework/Versions/3.8/bin
What shall I do? The path should use '/Library/Frameworks/Python.framework' or '/usr/bin/' ?
Will Zsh only read the first effective path, or will it continue to read the overwritten path?
I want to delete and reinstall, but I'm afraid it will be bad
Thanks for any suggestions
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
pip3.x
(例如pip3.10
)在最新/当前使用的Python版本上安装包:或者
并确保程序由相同的python运行可执行文件
Use
pip3.x
(e.gpip3.10
) to install the package on the latest/currently used version of Python:or
And make sure the program is run by the same python executable
您应该使用 pyenv 来隔离每个项目之间的环境
you should use pyenv to isolate environment between each project