【问题标题】:Python3 only opens in tcsh if I go to bash and then tcsh (anaconda)如果我去 bash 然后 tcsh (anaconda),Python3 只会在 tcsh 中打开
【发布时间】:2018-03-20 06:50:17
【问题描述】:

我使用标准设置安装了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”

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

"echo $PATH" 在 bash 产量 "/anaconda/bin:/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:anaconda3/bin:.:/opt/local/bin:/opt/本地/ncbi/blast”

【问题讨论】:

  • 请为每种情况输入which python。这将显示 shell 将使用的 python 二进制文件的路径。对于每种情况,键入echo $PATH 也可能很有启发性。似乎在您的 bash 启动脚本中,您正在对PATH 进行很多 修改。
  • 在 bash 中键入:echo $PATH 和哪个 python 来查看你的 PATH 并查看你正在使用什么 python-interpreter。
  • @SethMMorton 以上更新
  • @AAA 我敢打赌,在切换到 bash 之前, 中的 PATH 不是这样的。
  • @SethMMorton 是的,你是对的。改变了^

标签: python bash python-3.x csh tcsh


【解决方案1】:

首先,请看一下这个问题及其答案,以了解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 进行相同的修改...您可以稍微清理一下。

【讨论】:

  • 当我尝试“setenv PATH ~/anaconda3/bin:$PATH:.:/opt/local/bin:/opt/local/ncbi/blast”但是当我改变时它给了我一个错误至此,它起作用了:“setenv PATH ~/anaconda3/bin:.:/opt/local/bin:/opt/local/ncbi/blast:$PATH” 我还按照您的建议清理了文件,非常感谢寻求帮助!
  • 好奇点——在 bash 中,更改环境中已有的任何变量都会自动更新环境副本,因此在修改 PATH 时通常不需要 export。我是否理解正确,csh 也不是这种情况?
  • @CharlesDuffy 在tcsh 中,不使用setenvset 就无法修改变量(即PATH=blah 不是合法语法)。 set 仅适用于局部变量,所以我不希望这种自动更新成为可能。
  • nod -- 我想问的问题是,如果环境中已经存在变量,set 是否会自动升级为setenv。这听起来像是一个相当投机的数字。
  • @CharlesDuffy 很高兴你接受了投机部分:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-16
  • 2012-09-21
  • 2016-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多