Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't activate Python venv in Windows 10

I created a virtual environment with python -m venv myenv from the command prompt, but I don't know how to activate it. I tried executing activate.bat from the command prompt but it does not activate.

In other words, I don't see the current path changed to (myenv) C:\Pathname... to indicate that myenv has been activated. When I execute activate.bat the venv is not activated.

like image 738
Sunny Avatar asked Aug 02 '15 08:08

Sunny


1 Answers

This thread it old but I had the same problem today and found a working answer for it. I've been using python 3.6 venv for a few months now without issues but today I ran across a new error message:

C:\test>python -m venv vm
Error: Command '['C:\\test\\vm\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1

I scoured Stack and other resources for an answer but didn't find anything specific to Windows 10. (AskUbunto had a solution that was specific to Linux). I did find breadcrumbs spread out across the InterWebs and pieced this together.

You need this python script: https://bootstrap.pypa.io/get-pip.py

  1. Install your virtual environment as usual but without pip:

    python -m venv virtual --without-pip

This method will create all of the necessary files including the activate bat files.

  1. Copy the get-pip.py file into the virtual\Scripts subdirectory

  2. cd into the Scripts subdirectory and "activate" python Note: the cmd line should name the directory from which python was activated:

    (virtual) C:\test\virtual\Scripts>

(if it says (root), it's activated your core installation)

  1. now execute the script

    C:\test\virtual\Scripts>python get-pip.py

once run, I typed:

(virtual) C:\test\virtual\Scripts>pip freeze

to generate a freeze list and verify proper installation. It should return nothing, no error msg, no freeze list.

  1. Then I installed flask, tried pip freeze and noted the return was only for flask and dependent files:

(virtual) C:\test\virtual\Scripts>pip freeze
click==6.7
Flask==0.12.2
itsdangerous==0.24
Jinja2==2.9.6
MarkupSafe==1.0
Werkzeug==0.12.2

like image 129
mf.cummings Avatar answered Oct 16 '22 05:10

mf.cummings