10

By default, anaconda is using my root environment. However, I'm always using another environment called py34 that I activate manually. Is it possible to change the default environment from root to another one?

Edit: I forgot to mention that I'm working on Windows. On Unix systems adding a line to .bashrc is a solution of course.

Lisa
  • 3,365
  • 3
  • 19
  • 30

3 Answers3

4

You could add the following line to the end of your ~/.bashrc or ~/.bash_profile file:

source activate py34

Unfortunately, I'm not familiar with developing on Windows, but this might help? Another possibility is to use an IDE such as pycharm, which I can really recommend for developing python. There, you can change your project settings to your py34 environment.

Community
  • 1
  • 1
Lisa
  • 3,365
  • 3
  • 19
  • 30
  • 1
    Yes indeed - but unfortunately not on Windows. –  Feb 23 '16 at 13:40
  • Yes, the link helps - but I still think there should be a more elegant way to change the default environment... –  Feb 23 '16 at 14:27
  • @pomodorochris Do you use an IDE? If yes, you can set the python interpreter accordingly. – Lisa Feb 23 '16 at 14:31
  • Maybe that's something you could look into? I can really recommend [pycharm](https://www.jetbrains.com/pycharm/)! I'm pretty sure you can use it on windows, too. – Lisa Feb 23 '16 at 14:33
  • You should be aware that cmd's ["AutoRun" command line](http://superuser.com/a/144348) (it's not just a script path) is executed every time cmd.exe runs, including every time the CRT's `system` function (i.e. `os.system`) is called. So if you run a script like this you should set a sentry environment variable to keep it from running multiple times. – Eryk Sun Feb 23 '16 at 14:36
  • @eryksun Thanks for pointing this out. Maybe you could resolve this in a separate answer? As I said, windows is not really my specialty. – Lisa Feb 23 '16 at 14:39
  • @Lisa, I've never used Anaconda. If it uses a shortcut to a batch file to set up the environment, pomodorochris can modify that batch file to activate the desired virtual environment. That would be preferable to modifying what *every instance* of cmd.exe does. – Eryk Sun Feb 23 '16 at 14:46
1

On Windows:

Search for the Activate.bat file, Usually it is in

"C:\Users\Your_UserName\AppData\Local\Continuum\anaconda3\Scripts"

Open Activate.bat file in any Text Editor and Append

activate Your_Environment_Name

Save it and after that whenever you will open Anaconda Prompt Your_Environment will get Activated by default instead of base environment.

Jayesh Baviskar
  • 295
  • 4
  • 3
1

You can use this link to create a new env - https://stackoverflow.com/a/60820687/11383333

Once your env is created, you can use the answer mentioned by Jayesh to update the activate.bat file -

Let's say the new env name is python39, then the original line in activate.bat looks like this - @CALL "%~dp0..\condabin\conda.bat" activate %*

Update it to this - @CALL "%~dp0..\condabin\conda.bat" activate python38

Save it and restart your anaconda prompt

Suv
  • 23
  • 6