3

conda env list or conda info -e shows

py35 python=3.5 as one of the environment.

How to activate conda env which has space in its name?

Joel
  • 1,650
  • 2
  • 22
  • 34
  • 1
    Possible duplicate of [Using virtualenv with spaces in a path](http://stackoverflow.com/questions/15472430/using-virtualenv-with-spaces-in-a-path) – Jossie Calderon Jul 23 '16 at 15:16
  • Where is the space? `py35` appears to be the name – OneCricketeer Jul 23 '16 at 15:18
  • @JossieCalderon This is specific to conda and not python virtualenv – Joel Jul 23 '16 at 15:23
  • @cricket_007 the env is in folder `py35 python=3.5` and `activate py35` doesn't work – Joel Jul 23 '16 at 15:26
  • Have you tried to quote the environment name or create one without spaces or rename that one? – OneCricketeer Jul 23 '16 at 15:27
  • @cricket_007 I have since created a new conda env with only `py35` and have been using it. But need to find a way to remove or use in any fashion. Quoting doesn't seem to solve. – Joel Jul 23 '16 at 15:31
  • 1
    `py35` is the environment name and `python=3.5` is the version. You cannot create an environment with space in name. You should be able to activate it using `activate py35`. If it doesn't work, there is a problem with your environment. – CentAu Jul 23 '16 at 15:53

3 Answers3

3

tl;dr Surround the environment name with DOUBLE quotes.

@centau you can most definitely create environments with spaces in the name.

Duplicating the problem:

conda create -n "foo bar" python=3.5

Then inspecting the environments:

conda info -e

produces:

# conda environments:
#
foo bar                  C:\Users\edill\AppData\Local\Continuum\Miniconda3\envs\foo bar
root                  *  C:\Users\edill\AppData\Local\Continuum\Miniconda3

So you can see that there is an environment with the name "foo bar"

Then to activate it:

activate "foo bar"

Which modifies the command line to show:

(foo bar) C:\Users\edill>

So at this point I am reasonably confident that all is working properly with a space in the environment name, but let's just double check to make sure. Check the file that one of the built in modules is coming from:

(foo bar) C:\Users\edill>python -c "import os; print(os.__file__)"

Shows that this built in os module is indeed coming from the foo bar environment

C:\Users\edill\AppData\Local\Continuum\Miniconda3\envs\foo bar\lib\os.py
Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
Eric Dill
  • 2,166
  • 2
  • 17
  • 15
0

I've found a solution while trying to install conda environment in my Windows.

I have a space in one of my directory's name between My and MS.

C:\Users\My MS\python\project_1\env

So I put " " to encase the whole directory to activate the environment:

$ conda activate "C:\Users\My MS\python\project_1\env"

toolic
  • 57,801
  • 17
  • 75
  • 117
-1

Enter the name of the environment in double quotes.

e.g. when I activate my environment named - deep learning I use following command:

conda activate "deep learning"
Jason Aller
  • 3,541
  • 28
  • 38
  • 38