11

I can't activate the venv on my new project (new to Python too),

If I do python --version: Python 3.7.2

I created the venv using ' $ python -m venv ./venv ' in my editor (vs code).

and now to activate is where I have a problem,

Attempt 1:

$ ./venv/Scripts/activate.bat

error : 'C:\Users\name' is not recognized as an internal or external command, operable program or batch file.
The system cannot find the path specified.

My user name is formatted from 2 names "name & name" with space between them! Is that a problem? It just show first name and not the second.

Attempt 2:

$ C:\Users/name & name/Desktop/ProjectFolder/venv/Scripts/activate.bat

error: 
[1] 15160
bash: C:Users/name: No such file or directory
bash: name/Desktop/ProjectFolder/venv/Scripts/activate.bat: No such file or directory
[1]+  Exit 127                C:\Users/name
halfer
  • 19,824
  • 17
  • 99
  • 186
TextError
  • 339
  • 3
  • 5
  • 11

2 Answers2

12

Try using the terminal to navigate to the folder that contains your virtual environment using the change directory (cd) command. Once there, try typing:

source ./venv/Scripts/activate

Also, try opening the venv folder and make sure your activate file is in the 'Scripts' folder and not the 'bin' folder. When I create a virtual environment, I use:

source ./venv/bin/activate
Justin
  • 707
  • 7
  • 13
  • $ source ./venv/Scripts/activate.bat bash: @echo: command not found bash: rem: command not found bash: ./venv/Scripts/activate.bat: line 4: syntax error near unexpected token `"tokens=2 delims=:"' bash: ./venv/Scripts/activate.bat: line 4: `for /f "tokens=2 delims=:" %%a in ('"%SystemRoot%\System32\chcp.com"') do ( this is the error i have – TextError Jan 22 '19 at 16:35
  • Are you in the directory where your venv folder is in your terminal (i.e. the folder that holds your venv folder)? Try removing .bat also – Justin Jan 22 '19 at 16:37
  • 1
    its in Scripts ... i open the activate file and on top is # This file must be used with "source bin/activate" *from bash* – TextError Jan 22 '19 at 16:38
  • yes i`m in the dir inside terminal....i did w/ .bat , this is the error : $ source ./Scripts/activate bash: ./Scripts/activate: No such file or directory – TextError Jan 22 '19 at 16:40
  • Try to cd all the way into the Scripts folder where your activate file is and type `source activate`. Does that work? Make sure not to use the '.bat' extension. – Justin Jan 22 '19 at 16:42
  • cd venv/ , cd Scripts/ : $ source activate(venv) i think its working.$ python --version Python 3.7.2 (venv) but (venv) is not in front of the name but that is ok i gues – TextError Jan 22 '19 at 16:46
  • `source ./venv/Scripts/activate` (not `source ./venv/Scripts/activate.bat`) works for me in git bash on a Windows 10 machine. – L.Wu Jul 25 '19 at 02:34
  • 1
    source is definitely not windows... – Hansang Oct 11 '21 at 11:54
  • source neither works in cmd nor in powershell – Soumyajit Mar 22 '23 at 18:56
3

Try C:/Users/name & name/Desktop/ProjectFolder/venv/Scripts/activate.bat. Note the exclamation marks and backslash file separator changed to forward slash.

Another way is:

C:/Users/name\ &\ name/Desktop/ProjectFolder/venv/Scripts/activate.bat

Note the \ as escape character and backslash file separator changed to forward slash.

And as another option, you can go to directory:

cd 'C:/Users/name & name/Desktop/ProjectFolder/venv/Scripts'

and than run activate.bat from directory.

IliassA
  • 95
  • 2
  • 8
tbalaz
  • 159
  • 3