简体   繁体   English

Mac默认Python路径更改

[英]Mac Default Python Path Change

Hi I have a Mac and happen to have many different flavors of Python installed everywhere. 嗨,我有一台Mac,碰巧到处都安装了许多不同口味的Python。

right now when I opened up python in terminal, type in 现在,当我在终端中打开python时,输入

which python

the return result is: 返回结果是:

//anaconda/bin/python

I am wondering what should I do to change the default python to a python that I like, so next time when I do: 我想知道应该怎么做才能将默认python更改为我喜欢的python,所以下次我这样做时:

which python

the path should be: 路径应为:

/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

Thanks! 谢谢!

When you installed Anaconda it should have added a new item to your PATH variable, right at the front. 当您安装Anaconda时,它应该已经在前面的PATH变量中添加了一个新项。 You should see something like this in your *~/.bash_profile* file: 您应该在*〜/ .bash_profile *文件中看到以下内容:

# added by Anaconda 1.8.0 installer
export PATH="//anaconda/bin:$PATH"

You can remove these lines, reopen any terminal window you have and your default Python should have been restored. 您可以删除这些行,重新打开任何终端窗口,并且应该已经恢复了默认的Python。

which command uses the directories listed in $PATH to search for the first occurrence of a command. which命令使用$PATH列出的目录搜索命令的第一个匹配项。 If you want to list all instances of executables, use -a option. 如果要列出可执行文件的所有实例,请使用-a选项。

which python2.7

Output: 输出:

/usr/bin/python2.7

This will display symbolic link to /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 这将显示到/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7符号链接

to resolve symbolic link use 解决符号链接的使用

readlink $(which python2.7)  

output: 输出:

../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

尝试创建符号链接

ln -s /anaconda/bin/python /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

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

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