Why is python saying I have "no module named venv"?
Asked Answered
P

9

49

I installed virtual env with sudo pip install virtualenv but when I run python -m venv flask I'm still getting this: /usr/bin/python: No module named venv

Versions, if that's relevant:

pip 1.5.6 from /usr/lib/python2.7/dist-packages (python 2.7)
Python 2.7.9

what am I missing here?

Peruzzi answered 16/10, 2015 at 23:38 Comment(1)
Note that virtualenv != venvRhombohedron
B
43

venv is a module introduced in python3

venv is New in version 3.3.

Boeotian answered 16/10, 2015 at 23:40 Comment(0)
R
64

Since you are on Python 2, you need to execute using the virtualenv module that you installed.

First step, as you originally tried to do, but this time you specify the "virtualenv" module and the name of the virtualenv. In this case flask:

python -m virtualenv flask

Then you activate your virtualenv like this:

source flask/bin/activate

Then install flask with pip inside the virtualenv

pip install flask

If you want to deactivate your virtualenv, simply type:

deactivate

If running on Python 3, the venv command is built-in and you can simply do:

python3 -m venv flask

Note, depending on how your Python 3 is installed, your python execution command might differ. You could be running it as python3, python3.5, python3.6.

Robertaroberto answered 16/10, 2015 at 23:41 Comment(0)
B
43

venv is a module introduced in python3

venv is New in version 3.3.

Boeotian answered 16/10, 2015 at 23:40 Comment(0)
B
18

The venv is ony available in python 3 version. If you are using python 2 then try to use virtualenv instead of venv.

1. Install virtualenv,

python -m pip install virtualenv

2. Create a virtual environment named venv using virtualenv,

Python 2

python -m virtualenv venv

Python3

python -m venv venv

3. Activate virtual environment,

.\venv\Scripts\activate.bat

4. Install flask package,

pip install flask
Beneath answered 18/6, 2021 at 13:3 Comment(0)
D
2

If are you using "windows". Try it in "cmd" navigate in cmd to the folder you want to install venv and do:

python3 -m venv project_env

You can change the name of the project to.

Ducal answered 19/4, 2021 at 1:6 Comment(3)
Pretty sure Windows doesn't have a sudo command! Either way, the answer to this 5yo question is in the accepted answer. venv is python3.Peruzzi
I'm sorry @Amanda. I'm new on the stack overflow, and english is not my native language. But, i was talking about the error "no module named venv", which also occurred on my windows system, and I thought it would be useful if any user of windows gets here through google.Ducal
Ahhh! I have been on this site a long time and every now and then a wildly old question will suddenly get new answers that don't even apply to the actual question. I bet a l lot of them are coming via a web search for the error message.Peruzzi
G
2

sudo apt-get install python3-pip

python3 -m pip install virtualenv

python3 -m virtualenv venv

source venv/bin/activate

Gorki answered 21/8, 2022 at 12:30 Comment(0)
S
1

For python3 users, just be sure that you installed pip and venv packages:

sudo apt install python3-pip
sudo apt install python3-venv

Then you can use it like this:

python3 -m venv ~/sample
. ~/sample/bin/activate
pip install flask
Sanskritic answered 2/2, 2022 at 16:42 Comment(0)
M
1

I changed python -> python3:

python3 -m venv flask
Manaus answered 3/3, 2022 at 6:35 Comment(0)
I
0

Do the following for this issue.

  1. pip install venv (If this has got some issue that means python version recognized by your machine don't have updated version) so use below command: pip install the virtualenv
  2. python -m venv <> if this has got the same issue so use below one. python -m virtualenv <>
Insane answered 15/4, 2022 at 10:21 Comment(0)
S
0

python3 comes with the venv package.

In linux: python3 -m venv yourenvname

In windows: py -m venv yourenvname

Striper answered 13/9, 2023 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.