Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activate venv (Python 3.7.2) for Windows [duplicate]

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
like image 965
TextError Avatar asked Jan 22 '19 16:01

TextError


2 Answers

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
like image 80
Justin Avatar answered Nov 18 '22 00:11

Justin


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.

like image 30
tbalaz Avatar answered Nov 18 '22 00:11

tbalaz