I'm running Mountain Lion and the basic default Python version is 2.7. I downloaded Python 3.3 and want to set it as default.
我正在运行Mountain Lion,基本的默认Python版本是2.7。我下载了Python 3.3,并希望将其设置为默认值。
Currently:
目前:
$ python
version 2.7.5
$ python3.3
version 3.3
How do I set it so that every time I run $ python
it opens 3.3?
我如何设置它,以便每次运行$ python时,它将打开3.3?
6 个解决方案
#1
267
Changing the default python version system wide would break some applications that depend on python2.
改变默认的python版本系统将会破坏一些依赖于python2的应用程序。
You can alias the commands in most shells, Mac OS X uses bash by default, if you also do put this into your ~/.bash_profile
:
您可以在大多数shell中别名命令,Mac OS X在默认情况下使用bash,如果您也将其放到~/.bash_profile中:
alias python='python3'
python
command now refers to python3
. If you want the original python (that refers to python2), you can escape the alias i.e. doing \python
will launch python2 leaving the alias untouched)
python命令现在指的是python3。如果您想要原始的python(指的是python2),您可以摆脱别名,即执行\python将启动python2,使别名保持不变。
If you launch interpreters more often (I do), better is to:
如果你更经常地启动译员(我做),最好是:
alias 2='python2'
alias 3='python3'
Tip: Instead of doing:
提示:而不是做:
#!/usr/bin/env python
use:
使用:
#!/usr/bin/env python3
system will use python3 for running python executables.
系统将使用python3来运行python可执行程序。
#2
32
You can solve it by symbolic link.
你可以通过符号链接来解决它。
unlink /usr/local/bin/python
ln -s /usr/local/bin/python3.3 /usr/local/bin/python
#3
8
Go to 'Applications', enter 'Python' folder, there should be a bash script called 'Update Shell Profile.command' or similar. Run that script and it should do it.
进入“应用程序”,输入“Python”文件夹,应该有一个名为“更新Shell Profile.command”或类似的bash脚本。运行那个脚本,它应该这样做。
Edit: Hey, just come across this how to change default python version?, it looks like you should not update it.
编辑:嘿,遇到这个如何改变默认的python版本?看起来你不应该更新它。
#4
2
I'm not sure if this is available on OS X, but on linux I would make use of the module
command. See here.
我不确定这是否在OS X上可用,但是在linux上我将使用模块命令。在这里看到的。
Set up the modulefile correctly, then add something like this to your rc file (e.g. ~/.bashrc):
正确设置modulefile,然后向rc文件(例如~/.bashrc)中添加类似的内容。
module load python3.3
This will make it so that your paths get switched around as required when you log in without impacting any system defaults.
这将使您的路径在不影响任何系统默认值的情况下按需要被转换。
#5
1
I think when you install python it puts export path statements into your ~/.bash_profile file. So if you do not intend to use Python 2 anymore you can just remove that statement from there. Alias as stated above is also a great way to do it.
我认为,当您安装python时,它会将导出路径语句放入您的~/中。bash_profile文件。所以如果你不打算使用Python 2,你可以从那里删除它。如上所述的别名也是一个很好的方法。
Here is how to remove the reference from ~/.bash_profile - vim ./.bash_profile - remove the reference (AKA something like: export PATH="/Users/bla/anaconda:$PATH") - save and exit - source ./.bash_profile to save the changes
下面是如何删除~/的引用。bash_profile——vim。/。bash_profile -删除引用(类似于:export PATH="/Users/bla/anaconda:$PATH") -保存和退出源。bash_profile以保存更改。
#6
0
I believe most of people landed here are using ZSH thorugh iterm or whatever, and that brings you to this answer.
我相信这里的大多数人都是用ZSH thorugh iterm或者别的什么,这就引出了这个答案。
You have to add/modify your commands in ~/.zshrc
instead.
你必须在~/修改你的命令。zshrc代替。
#1
267
Changing the default python version system wide would break some applications that depend on python2.
改变默认的python版本系统将会破坏一些依赖于python2的应用程序。
You can alias the commands in most shells, Mac OS X uses bash by default, if you also do put this into your ~/.bash_profile
:
您可以在大多数shell中别名命令,Mac OS X在默认情况下使用bash,如果您也将其放到~/.bash_profile中:
alias python='python3'
python
command now refers to python3
. If you want the original python (that refers to python2), you can escape the alias i.e. doing \python
will launch python2 leaving the alias untouched)
python命令现在指的是python3。如果您想要原始的python(指的是python2),您可以摆脱别名,即执行\python将启动python2,使别名保持不变。
If you launch interpreters more often (I do), better is to:
如果你更经常地启动译员(我做),最好是:
alias 2='python2'
alias 3='python3'
Tip: Instead of doing:
提示:而不是做:
#!/usr/bin/env python
use:
使用:
#!/usr/bin/env python3
system will use python3 for running python executables.
系统将使用python3来运行python可执行程序。
#2
32
You can solve it by symbolic link.
你可以通过符号链接来解决它。
unlink /usr/local/bin/python
ln -s /usr/local/bin/python3.3 /usr/local/bin/python
#3
8
Go to 'Applications', enter 'Python' folder, there should be a bash script called 'Update Shell Profile.command' or similar. Run that script and it should do it.
进入“应用程序”,输入“Python”文件夹,应该有一个名为“更新Shell Profile.command”或类似的bash脚本。运行那个脚本,它应该这样做。
Edit: Hey, just come across this how to change default python version?, it looks like you should not update it.
编辑:嘿,遇到这个如何改变默认的python版本?看起来你不应该更新它。
#4
2
I'm not sure if this is available on OS X, but on linux I would make use of the module
command. See here.
我不确定这是否在OS X上可用,但是在linux上我将使用模块命令。在这里看到的。
Set up the modulefile correctly, then add something like this to your rc file (e.g. ~/.bashrc):
正确设置modulefile,然后向rc文件(例如~/.bashrc)中添加类似的内容。
module load python3.3
This will make it so that your paths get switched around as required when you log in without impacting any system defaults.
这将使您的路径在不影响任何系统默认值的情况下按需要被转换。
#5
1
I think when you install python it puts export path statements into your ~/.bash_profile file. So if you do not intend to use Python 2 anymore you can just remove that statement from there. Alias as stated above is also a great way to do it.
我认为,当您安装python时,它会将导出路径语句放入您的~/中。bash_profile文件。所以如果你不打算使用Python 2,你可以从那里删除它。如上所述的别名也是一个很好的方法。
Here is how to remove the reference from ~/.bash_profile - vim ./.bash_profile - remove the reference (AKA something like: export PATH="/Users/bla/anaconda:$PATH") - save and exit - source ./.bash_profile to save the changes
下面是如何删除~/的引用。bash_profile——vim。/。bash_profile -删除引用(类似于:export PATH="/Users/bla/anaconda:$PATH") -保存和退出源。bash_profile以保存更改。
#6
0
I believe most of people landed here are using ZSH thorugh iterm or whatever, and that brings you to this answer.
我相信这里的大多数人都是用ZSH thorugh iterm或者别的什么,这就引出了这个答案。
You have to add/modify your commands in ~/.zshrc
instead.
你必须在~/修改你的命令。zshrc代替。