Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change default Anaconda python environment

People also ask

How do I change my Python to anaconda by default?

Scroll down until you find Path, select it, and click edit. In the screen that appears, update the path that is pointing to your original python.exe to the one that is in the anaconda path. Close any open command window for update to take effect. Thanks.

What is base environment conda?

Conda has a default environment called base that include a Python installation and some core system libraries and dependencies of Conda. It is a “best practice” to avoid installing additional packages into your base software environment.


If you just want to temporarily change to another environment, use

source activate environment-name

ETA: This may be deprecated. I believe the current correct command is:

source conda activate 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.


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:

First, make sure you have the latest version of conda by running

conda update conda

Then run

conda install 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.

If you installed packages with pip, you'll have to reinstall them.


Overview
Some people have multiple Anaconda environments with different versions of python for compatibility reasons. In this case, you should have a script that sets your default environment. With this method, you can preserve the versions of python you use in your environments.

The following assumes environment_name is the name of your environment

Mac / Linux:
Edit your bash profile so that the last line is source activate environment_name. In Mac OSX this is ~/.bash_profile, in other environments this may be ~/.bashrc

Example:
Here's how i did it on Mac OSX

  1. Open Terminal and type:

    nano ~/.bash_profile

  2. Go to end of file and type the following, where "p3.5" is my environment:

    source activate p3.5

  3. Exit File. Start a new terminal window.

  4. Type the following to see what environment is active

    conda info -e

The result shows that I'm using my p3.5 environment by default.

For Windows:
Create a command file (.cmd) with activate environment_name and follow these instructions to have it execute whenever you open a command prompt

  1. Create a batch file command, e.g. "my_conda.cmd", put it in the Application Data folder.
  2. Configure it to be started automatically whenever you open cmd. This setting is in Registry:
    key: HKCU\SOFTWARE\Microsoft\Command Processor
    value: AutoRun
    type: REG_EXPAND_SZ
    data: "%AppData%\my_conda.cmd"

from this answer: https://superuser.com/a/302553/143794


Under Linux there is an easier way to set the default environment by modifying ~/.bashrc or ~/.bash_profile At the end you'll find something like

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

Replace it with

# set python3 as default
export PATH="~/anaconda/envs/python3/bin:$PATH"

and thats all there is to it.


For windows Anaconda comes with Anaconda Prompt which is a shortcut to cmd and can be used run conda commands without adding anaconda in PATH variable. Find the location of it, copy and rename the copy (say myenv_prompt). Right click myenv_prompt and select properties in the context menu.

enter image description here

The Target form of Properties window should already be filled with text, something like %windir%\system32\cmd.exe "/K" C:\Users\xxx\AppData\Local\Continuum\Miniconda3\Scripts\activate.bat C:\Users\xxx\AppData\Local\Continuum\Miniconda3\ There are three parts of this command 1)start ...\cmd.exe 2)run ...\acitvate.bat with environment 3)...\Miniconda3\

Change 3rd part to path of the environment (say myenv) you want as default i.e. fill the Target form something like %windir%\system32\cmd.exe "/K" C:\Users\xxx\AppData\Local\Continuum\Miniconda3\Scripts\activate.bat C:\Users\xxx\AppData\Local\Continuum\Miniconda3\envs\myenv

Now myenv_prompt will act as shortcut to start cmd with myenv as the default environment for python. This shortcut you can keep in start menu or pinned in taskbar.

One advantage of this method is that you can create a few shortcuts each having different environment as default environment. Also you can set the default folder by filling Start in form of the Properties window

Hope this helps

PS:It is not required to find Anaconda Prompt and can be done by changing target of any shortcut. But you will require to know path of cmd.exe and activate.bat


The correct answer (as of Dec 2018) is... you can't. Upgrading conda install python=3.6 may work, but it might not if you have packages that are necessary, but cannot be uninstalled.

Anaconda uses a default environment named base and you cannot create a new (e.g. python 3.6) environment with the same name. This is intentional. If you want your base Anaconda to be python 3.6, the right way to do this is to install Anaconda for python 3.6. As a package manager, the goal of Anaconda is to make different environments encapsulated, hence why you must source activate into them and why you can't just quietly switch the base package at will as this could lead to many issues on production systems.