Anaconda/MacOS:更改默认Python版本
我在使用Anaconda的Python时,Spyder这个工具崩溃了。当我尝试重新启动它时,启动器显示它已经被卸载了。我觉得Anaconda可能出了问题,于是重启了电脑,但问题还是没解决。
我查看了一下,发现默认的Python版本被改变了:
$ python --version
Python 3.4.1 :: Continuum Analytics, Inc.
我尝试用苹果的defaults write
命令把它改回来,还用ln -sf
重新链接Python,或者简单地设置了一个alias python=python2.7
,但都没有效果。
然后我试着用conda删除Python3,但conda remove python3
并没有成功。搜索包的时候得到了这个结果:
$ conda search python
Fetching package metadata: ..
(...)
python 1.0.1 0 defaults
(...)
. 2.7.5 2 defaults
. 2.7.5 3 defaults
(...)
* 3.4.1 0 defaults
我还查了Continuum的文档,他们建议把2.7版本作为标准版本,如果我想用不同的版本,就使用Anaconda环境,这对我没有帮助。
有没有人知道怎么把默认版本改回2.7?
(我的配置是:Anaconda 1.7.0,OSX 10.8.5,conda 3.5.2)
1 个回答
7
好的,我在Continuum的邮件列表中发现了一个类似的问题。
这个问题是通过用conda重新安装python解决的。
$ conda install python=2.7
Fetching package metadata: ..
Solving package specifications: .
Package plan for installation in environment /Users/kadu/anaconda:
The following packages will be downloaded:
package | build
---------------------------|-----------------
conda-3.5.2 | py27_0 135 KB
pycosat-0.6.1 | py27_0 57 KB
python-2.7.6 | 2 16.5 MB
pyyaml-3.11 | py27_0 149 KB
requests-2.3.0 | py27_0 564 KB
------------------------------------------------------------
Total: 17.4 MB
The following packages will be UN-linked:
package | build
---------------------------|-----------------
conda-3.5.2 | py34_0
pycosat-0.6.1 | py34_0
python-3.4.1 | 0
pyyaml-3.11 | py34_0
requests-2.3.0 | py34_0
The following packages will be linked:
package | build
---------------------------|-----------------
conda-3.5.2 | py27_0 hard-link
pycosat-0.6.1 | py27_0 hard-link
python-2.7.6 | 2 hard-link
pyyaml-3.11 | py27_0 hard-link
requests-2.3.0 | py27_0 hard-link
Proceed ([y]/n)?
这也可以用来改变在anaconda环境中哪个包是默认的:
$ conda install python=3.4
Fetching package metadata: ..
Solving package specifications: .
Package plan for installation in environment /Users/kadu/anaconda:
The following packages will be UN-linked:
package | build
---------------------------|-----------------
conda-3.5.2 | py27_0
pycosat-0.6.1 | py27_0
python-2.7.6 | 2
pyyaml-3.11 | py27_0
requests-2.3.0 | py27_0
The following packages will be linked:
package | build
---------------------------|-----------------
conda-3.5.2 | py34_0 hard-link
pycosat-0.6.1 | py34_0 hard-link
python-3.4.1 | 0 hard-link
pyyaml-3.11 | py34_0 hard-link
requests-2.3.0 | py34_0 hard-link
Proceed ([y]/n)?
不过,这样做需要手动更改你使用的其他包的版本。我不得不重新安装spyder,因为它似乎是导致这个问题的原因,而我在尝试用错误的版本启动它时,可能也重新安装了它。其他我没有尝试重新安装的库在2.7版本下仍然运行得很好。