如何在MAC上管理Python路径

发布于 2025-01-10 21:20:41 字数 1453 浏览 0 评论 0原文

我尝试运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温柔女人霸气范 2025-01-17 21:20:41

使用pip3.x(例如pip3.10)在最新/当前使用的Python版本上安装包:

pip3.10 install django

或者

python3.10 -m pip install django

并确保程序由相同的python运行可执行文件

python3.10 manage.py makemigrations

Use pip3.x (e.g pip3.10) to install the package on the latest/currently used version of Python:

pip3.10 install django

or

python3.10 -m pip install django

And make sure the program is run by the same python executable

python3.10 manage.py makemigrations
没︽人懂的悲伤 2025-01-17 21:20:41

您应该使用 pyenv 来隔离每个项目之间的环境

you should use pyenv to isolate environment between each project

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文