[英]How to set a particular python version as default in terminal, but to keep the possibility to use another (e.g. conda) for a package
為了安裝外部軟件包,我必須安裝conda
並激活環境以使用該外部軟件包。 但是,現在python的conda版本是默認版本:
$ which python
/Users/mymac/miniconda3/bin/python
$ python
Python 3.7.3 (default, Mar 27 2019, 16:54:48)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
在我的.bash_profile
這兩個版本似乎並存:
export PS1="\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
alias ls='ls -GFh'
# Homebrew
export PATH=/usr/local/bin:$PATH
# Setting PATH for Python 3.7
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export PATH
export PATH="$HOME/.cargo/bin:$PATH"
export LC_ALL=en_US.UTF-8
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/Users/mymac/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/mymac/miniconda3/etc/profile.d/conda.sh" ]; then
. "/Users/mymac/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/Users/mymac/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
然后在我的.bashrc
添加以下行
alias python='/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
然后我重試了之前的命令
$ which python
/Users/mymac/miniconda3/bin/python
$ python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 16:52:21)
[Clang 6.0 (clang-600.0.57)] on darwin
版本似乎已更改,但來源仍然相同。
為了使非conda python版本在終端中成為默認版本,必須執行哪些精確命令,但要保留將conda版本用於該特定軟件包的可能性(通過鍵入source activate thepackage
)
首先,刪除alias命令,這只會在以后忘記創建別名時引起問題。 然后,添加conda配置選項,以便默認情況下不激活基本環境。 在您的終端中,鍵入:
conda config --set auto_activate_base false
這應該將系統Python還原為您在路徑中首次找到的Python。 現在,當您要使用conda環境時,只需鍵入
conda activate env-name
並且您應該可以訪問該環境的Python。 完成后,輸入
conda deactivate
將使您回到原始狀態。 如果您激活了多個環境,則可能需要多次運行conda deactivate
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.