Skip to main content
 首页 » 编程设计

如果我去 bash 然后 tcsh (anaconda),则 Python3 只在 tcsh 中打开

2024年10月01日5bonelee

我使用标准设置安装了 anaconda3,主要使用 tcsh。 如果终端在 tcsh 中打开,然后我输入“conda”,它就会工作。 如果我输入“python”,它会显示

Python 2.7.10 (default, Feb  7 2017, 00:08:15)  
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 

但是,如果我输入“bash”,然后输入“tcsh”,然后输入“python”,它会显示:

Python 3.6.2 |Anaconda, Inc.| (default, Sep 21 2017, 18:29:43)  
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin 
Type "help", "copyright", "credits" or "license" for more information. 

作为引用,我的 .tcshrc 文件包含以下内容:

set path  = ( $path anaconda3/bin . /opt/local/bin /opt/local/ncbi/blast ) 
 
alias python2 '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7' 
 
alias python3 '/opt/local/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5' 

.bashrc 包含:

export PATH=~/anaconda3/bin:$PATH 

.bash_profile 包含:

source ~/.bashrc 
PATH=$PATH:$HOME/anaconda3/bin 
export PATH="/anaconda3/bin:$PATH" 

我是 Unix 和 Python 的新手,但需要在 bash 和 tcsh 中为一个类设置 anaconda。有什么想法吗?

更新:

当我在 tcsh 中启动终端时,“which python”产生“/usr/bin/python”

如果我切换到 bash,“which python”会产生“/anaconda3/bin/python”

tcsh 中的“echo $PATH”产生“/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:anaconda3/bin:.:/opt/local/bin:/opt/local/ncbi/blast"

bash 中的“echo $PATH” "/anaconda/bin:/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:anaconda3/bin:.:/opt/local/bin:/opt/本地/ncbi/爆炸”

请您参考如下方法:

首先,请看一下这个问题及其答案,以了解 PATH 环境变量的工作原理:https://unix.stackexchange.com/questions/77898/how-does-the-path-enviroment-variable-work-in-linux .

你的问题是,在你的 ~/.tcshrc 中,你没有将 Anaconda 目录添加到你的 PATH 前面,所以 tcsh 发现首先安装系统并使用它。要解决此问题,您可以将该文件的第一行修改为:

setenv PATH ~/anaconda3/bin:$PATH:.:/opt/local/bin:/opt/local/ncbi/blast 

在 tcsh 中,setenv 与 bash 中的 export 有相似的用途,因此只需使用 set 不会可靠地更改您的 PATH。

作为旁注,您似乎一遍又一遍地对 bash PATH 进行相同的修改……您可以稍微清理一下。