Shury
Shury

Reputation: 578

Python venv not creating virtual environment

I'm trying to create a virtual environment for my current Django project using

python3 -m venv env

however the command doesn't create any directory with bin/include/lib folders. What exactly am I missing here?

enter image description here

Upvotes: 19

Views: 57967

Answers (10)

celine john
celine john

Reputation: 1

I just had the similar problem, and I realized changing the path directories names by removing the spaces in the name of the directories helps.

Upvotes: -2

Indrajeet Singh
Indrajeet Singh

Reputation: 70

I guess I am a bit late to answer the question, but before creating a virtual environment always check if we already have a .venv hidden folder

  1. Navigate to the directory where we want to create a virtual environment
  2. Check if we already have one by ls -la this command will show us the hidden folders, as .venv will be hidden by default Check hidden folder using Terminal/Command prompt
  3. If we do not have the .venv folder (name is up to us), then create one by mkdir .venv to follow the best convention, in this folder we can create multiple virtual environments
  4. Now we can create a virtual environment by python3 -m venv ./venv/drf
  5. In above folder we have created, inside that we are creating one more folder drf (Django Rest Rramework) enter image description here
  6. At last to run our virtual environment use source .venv/drf/bin/activate by this command we are running the script which is there in bin folder enter image description here

I hope I was able to explain, as I am also learning

Please feel free to edit or make any changes in the post, If something is wrong

Upvotes: 0

hru_d
hru_d

Reputation: 936

I have a Windows 10 machine and had a same problem. It was because I had multiple versions of python. Unknowingly windows had created a python.exe in the WindowsApps folder -

enter image description here

Then the solution is sometimes:(there is a huge chance that, the old %PATH% got renamed)

py -m venv venv

This python.exe had a size of 0 kb, so I deleted the python.exe in the WindowsApps folder, opened a new Command prompt and it started working.

Upvotes: 11

Chrisdelali
Chrisdelali

Reputation: 31

Try this (works for me)

python -m venv C:\<optional-EXISTING-directory-path>\<VENV-name-u-want-2-use>

For more info: https://docs.python.org/3/library/venv.html

Upvotes: 1

Tim Crammond
Tim Crammond

Reputation: 156

For anyone facing this issue now, simply changing the command to start python instead of python3 fixes this

Upvotes: 8

pythko
pythko

Reputation: 124

I was having this same problem. I was able to get venv working by uninstalling Python and reinstalling it (I'm using the Anaconda distribution). The py -m venv test command still doesn't have any output after running it, but now it creates a folder for me and I can activate the test environment.

Upvotes: 1

7wick
7wick

Reputation: 421

Install and create through:

pip install virtualenv

virtualenv <your_virtualenv_name>

Then activate the environment, by going to ./your_virtualenv_name/Scripts folder and then run:

activate

Upvotes: 1

Sammy J
Sammy J

Reputation: 1066

why do you have to write python3 -m venv env when you base is installed as python3.6 itself?

Just do pip install virtualenv this should install virtualenv package if not already installed, then

virtualenv envname this will run and should give you a message like this, I have created a env called testenv:

C:\Users\Admin\python_projects\venvs>virtualenv testenv
Using base prefix 'c:\\python37'
New python executable in C:\Users\Admin\python_projects\venvs\testenv\Scripts\python.exe
Installing setuptools, pip, wheel...
done.

If you get this, it is a success, else do let us know what you get, after this you must cd into the Scripts folder and then run activate

Upvotes: 2

Naveen Jain
Naveen Jain

Reputation: 1072

Sometime system's path environment is not aware of virtualenv.exe

solution:
install virtualenv

pip install virtualenv  

run command in the directory where you want virtual environment :

python3 -m virtualenv venv 

Upvotes: 15

Hangsia Hong
Hangsia Hong

Reputation: 1

pip install virtualenvwrapper-win try to install it and do it again

Upvotes: -1

Related Questions