簡體   English   中英

為什么我在激活 Python 3 Conda 環境后卡在系統默認的 Python 2 解釋器上?

[英]Why am I stuck with the system default Python 2 interpreter after activating a Python 3 Conda environment?

我使用命令在 x86-64 Linux 大型機上創建了一個新的 Conda 環境

conda create --name myenv --file somefile.txt --python=3.8

我在這個環境中使用 conda conda list仔細檢查了我的 Python 版本,它返回

...
python                    3.8.3                hcff3b4d_0
...

但是,激活此環境后,Python 3 個腳本沒有運行,運行which python顯示環境默認使用默認系統 Python 2 解釋器:

$ which python
/usr/bin/python

我迄今為止的努力

首先,我將行export PATH=$PATH:/home/miniconda3/envs/myenv/bin添加到我的~/.bashrc~/.profile文件中,但沒有效果。 which python仍然返回/usr/bin/python

然后我檢查了我的別名文件,看看python是否別名為 Python 2。但是別名文件中沒有關於python的條目。

供你參考

  1. 我的~/.bashrc看起來像這樣:
$ cat ~/.bashrc
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/miniconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/home/miniconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

alias julia="/home/julia-1.4.0/bin/julia"

export PATH=$PATH:/home/miniconda3/envs/myenv/bin
$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
$ cat ~/.profile
export PATH=$PATH:/home/miniconda3/envs/myenv/bin

我認為你需要將你的環境路徑添加到 PATH 變量的前面,這樣它就會首先在那里找到 python 。 操作系統將在 PATH 列表中查找文件或應用程序,並使用它找到的第一個匹配項。

改變

導出 PATH=$PATH:/home/qingyanz/miniconda3/envs/myenv/bin

對此:

導出 PATH=/home/qingyanz/miniconda3/envs/myenv/bin:$PATH

例如,以下是我的 conda 環境中的設置:

(ds_tensorflow) C:\Users\me>其中 python /c/Users/me/miniconda3/envs/ds_tensorflow/python

(ds_tensorflow) C:\Users\me>env | grep PATH... PATH=/c/Users/me/miniconda3/envs/ds_tensorflow:/mingw-w64/bin:/usr/bin:/bin:...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM