Cant activate Python venv in Windows 10

2024/10/2 20:23:36

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.

Answer

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

https://en.xdnf.cn/q/70809.html

Related Q&A

Opening file path not working in python [duplicate]

This question already has answers here:open() gives FileNotFoundError / IOError: [Errno 2] No such file or directory(11 answers)Closed last year.I am writing a database program and personica is my test…

Cython: Segmentation Fault Using API Embedding Cython to C

Im trying to embed Cython code into C following Oreilly Cython book chapter 8. I found this paragraph on Cythons documentation but still dont know what should I do:If the C code wanting to use these fu…

Computing AUC and ROC curve from multi-class data in scikit-learn (sklearn)?

I am trying to use the scikit-learn module to compute AUC and plot ROC curves for the output of three different classifiers to compare their performance. I am very new to this topic, and I am struggli…

Nested dictionary

I am working on some FASTA-like sequences (not FASTA, but something I have defined thats similar for some culled PDB from the PISCES server).I have a question. I have a small no of sequences called nCa…

How to create a Python script to automate software installation? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.We don’t allow questi…

Using __str__() method in Django on Python 2

I am Learning Django using the Django project tutorial. Since I use python 2.7 I am unable to implement the following in python 2.7:from django.db import modelsclass Question(models.Model): # ...def _…

Losing merged cells border while editing Excel file with openpyxl

I have two sheets in an Excel file and the first one is a cover sheet which I dont need to edit. There are a few merged cells in the cover sheet, and when I edit the file using openpyxl, without even t…

Reset CollectorRegistry of Prometheus lib after each unit test

I have a class A that initializes a Counter in its initfrom prometheus_client import Counter class A:def __init__(self):self.my_counter = Counter(an_awesome_counter)def method_1(self):return 1def metho…

Why does Django ORM allow me to omit parameters for NOT NULL fields when creating an object?

Stupid question time. I seem to be able to create an object for a Django model even though I omit a column that was defined as NOT NULL and I dont understand why. Heres my model:class Movie(models.Mo…

Where should i do the django validations for objects and fields?

Im creating a django application which uses both the Django Rest Framework and the plain django-views as entrypoint for users.I want to do validation both independant fields of my models, and on object…