我嘗試運行 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 會只讀取第一個有效路徑,還是會繼續讀取被覆寫的路徑?
想洗掉重裝,怕是壞了
感謝您的任何建議
uj5u.com熱心網友回復:
使用pip3.x(例如pip3.10)在最新/當前使用的 Python 版本上安裝包:
pip3.10 install django
要么
python3.10 -m pip install django
并確保程式由相同的 python 可執行檔案運行
python3.10 manage.py makemigrations
uj5u.com熱心網友回復:
您應該使用 pyenv 來隔離每個專案之間的環境
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/434781.html
標籤:Python python-3.x 重击 贝壳 zsh
