繁体   English   中英

os x,python,homebrew - >奇怪的事情发生了

[英]os x, python, homebrew -> something weird going on

希望有人可以帮助我。 我跟着几个关于为python开发设置新机器的指南。 )(

我几乎遵循了所有内容,但我对.bash_profile的更改感到困惑

当我在.bash_profile注释掉export PATH=/usr/local/bin:$PATH并输入which python到终端时,我看到了我的期望。

which python
/usr/local/bin/python
python
Python 2.7.11 (default, Jan 22 2016, 08:29:18) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

在bash_profile中发生了什么,如果我评论所有内容,保存并运行命令怎么回事?

更重要的是,我如何进入我的默认安装python并确保它仍在那里并且不受影响? 我是否正确理解上述版本是Homebrew安装的python?

.bash_profile仅在加载Bash shell时读取,因此在加载shell后更改此文件不会影响它。 要在修改和保存文件后查看更改,您需要重新启动shell或运行source ~/.bash_profile

修改PATH环境变量不会影响Python本身,它只会修改首先执行的搜索位置,当你运行python ... 例如,如果你在/a/python/b/python安装了/b/python ,那么:

  • 如果您的PATH设置为/a/python:/b/python:$PATH并且您运行python ....py实际上/a/python ....py被执行;

  • 如果您的PATH设置为/b/python:/a/python:$PATH并且您运行python ....py实际上执行/b/python ....py

如果你没有修改PATH (例如但是在shell中执行诸如export PATH=/usr/local/bin:$PATH之类的东西或者将它添加到.bash_profile ),那么执行which python应该显示默认的python路径。

在您描述的情况下,它会向您显示python,您可以通过修改PATH来设置它。 要查看默认值,请注释export...字符串,保存.bash_profile文件并运行source ~/.bash_profile或重新启动shell,然后才能看到which python输出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM