問題描述
我安裝了 Anaconda 并創建了兩個額外的環境:py3k(包含 Python 3.3)和 py34(包含 Python 3.4).除此之外,我還有一個名為root"的默認環境,Anaconda 安裝程序默認創建該環境并保存 Python 2.7.最后一個是默認設置,每當我從終端啟動ipython"時,它都會給我 2.7 版.為了使用 Python 3.4,我需要發出命令(在 shell 中)
I've installed Anaconda and created two extra environments: py3k (which holds Python 3.3) and py34 (which holds Python 3.4). Besides those, I have a default environment named 'root' which the Anaconda installer created by default and which holds Python 2.7. This last one is the default, whenever I launch 'ipython' from the terminal it gives me version 2.7. In order to work with Python 3.4, I need to issue the commands (in the shell)
source activate py34
ipython
將默認環境更改為 Python 3.4.這很好用,但很煩人,因為我大部分時間都在使用 Python 3.4,而不是 Python 2.7(我持有它是為了教學目的,這是一個相當長的故事).無論如何,我想知道如何將默認環境更改為 Python 3.4,記住我不想從頭開始重新安裝所有內容.
which change the default environment to Python 3.4. This works fine, but it's annoying since most of the time I work on Python 3.4, instead of Python 2.7 (which I hold for teaching purposes, it's a rather long story). Anyway, I'll like to know how to change the default environment to Python 3.4, bearing in mind that I don't want to reinstall everything from scratch.
推薦答案
如果你只是想暫時換個環境,用
If you just want to temporarily change to another environment, use
source activate environment-name
ETA:這可能已被棄用.我相信當前正確的命令是:
ETA: This may be deprecated. I believe the current correct command is:
source conda activate environment-name
(您可以使用 conda create
創建 environment-name
)
(you can create environment-name
with conda create
)
要永久更改,除了創建一個運行上述代碼的啟動腳本之外別無他法.
To change permanently, there is no method except creating a startup script that runs the above code.
通常最好只創建新環境.但是,如果你真的想在默認環境下更改 Python 版本,你可以這樣做:
Typically it's best to just create new environments. However, if you really want to change the Python version in the default environment, you can do so as follows:
首先,通過運行確保您擁有最新版本的 conda
First, make sure you have the latest version of conda by running
conda update conda
然后運行
conda install python=3.5
這將嘗試將根環境中的所有包更新到 Python 3 版本.如果不可能(例如,因為某些包不是為 Python 3.5 構建的),它會給您一條錯誤消息,指出是哪個包導致了問題.
This will attempt to update all your packages in your root environment to Python 3 versions. If it is not possible (e.g., because some package is not built for Python 3.5), it will give you an error message indicating which package(s) caused the issue.
如果您使用 pip 安裝軟件包,則必須重新安裝它們.
If you installed packages with pip, you'll have to reinstall them.
這篇關于如何更改默認 Anaconda python 環境的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!