Why is python saying I have "no module named venv"? - python

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?

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.

venv is a module introduced in python3
venv is New in version 3.3.

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

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.

I changed python -> python3:
python3 -m venv flask

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

Do the following for this issue.
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
python -m venv <>
if this has got the same issue so use below one.
python -m virtualenv <>

sudo apt-get install python3-pip
python3 -m pip install virtualenv
python3 -m virtualenv venv
source venv/bin/activate

Related

Python not using proper pip

I'm running CentOS 8 that came with native Python 3.6.8. I needed Python 3.7 so I installed Python 3.7.0 from sources. Now, python command is unknown to the system, while commands python3 and python3.7 both use Python 3.7.
All good until now, but I can't seem to get pip working.
Command pip returns command not found, while python3 -m pip, python3.7 -m pip, python3 -m pip3, and python3.7 -m pip3 return No module named pip. Only pip command that works is pip3.
Now whatever package I install via pip3 does not seem to install properly. Example given, pip3 install tornado returns Requirement already satisfied, but when I try to import tornado in Python 3.7 I get ModuleNotFoundError: No module named 'tornado'. Not the same thing can be said when I try to import it in Python 3.6, which works flawlessly. From this, I understand that my pip only works with Python 3.6, and not with 3.7.
Please tell me how can I use pip with Python 3.7, thank you.
It looks like your python3.7 does not have pip.
Install pip for your specific python by running python3.7 -m easy_install pip.
Then, install packages by python3.7 -m pip install <package_name>
Another option is to create a virtual environment from your python3.7. The venv brings pip into it by default.
You create venv by python3.7 -m venv <venv_name>
I think the packages you install will be installed for the previous version of Python. I think you should update the native OS Python like this:
Install the python3.7 package using apt-get
sudo apt-get install python 3.7
Add python3.6 & python3.7 to update-alternatives:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
Update python3 to point to Python 3.7:
`sudo update-alternatives --config python3
Test the version:
python3 -V

ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data' when I created new env by virtualenv

I was creating a new virtual environment on Ubuntu 20.04:
$ virtualenv my_env
But it gave an error:
ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data'
Other info:
$ virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
#yushulx
I also ran into the same issue. I installed both via pip3 and via sudo apt install python3-virtualenv and it gave me an error but after I ran pip3 uninstall virtualenv I could create a virtualenv without issue
Try to create the virtual environment using directly venv module
python3 -m venv my_env
To fix this on Ubuntu 20.04, I had to uninstall virtualenv from the system: apt remove python3-virtualenv, and reinstall it using pip: pip install --user virtualenv --force-reinstall. I had errors about dependencies conflicts, I fixed them by calling pip install --user ${package} --force-reinstall for every package involved.
virtualenv is installed by default with python itself and when you install virtualenv via pip3 and try to create virtual environment using pipenv you will get this error:
ModuleNotFoundError: No module named 'virtualenv.seed.embed.via_app_data
check the version of installed virtualenv using apt list --installed
mine is:
python3-virtualenv/focal,focal,now 20.0.17-1 all [installed,automatic]
with the installed virtualenv by pip3
min is :
virtualenv 20.4.0
default installation of virtualenv is different with pip3 installed virtualenv
so when you try to create a virtual environment using pipenv for example installing django in a directory home/user/djano with pipenv install django~=3.1.5 you will get that error
the solution is remove installed virtualenv using pip3 uninstall virtualenv and use the default installation of virtualenv this time when you create virtual environment with pipenv it will create it successfully.
I want to have virtualenvwrapper. On Debian 10 testing I did:
apt remove python3-virtualenvwrapper # not purge, I want no changes in ~/.virtualenvs/
apt purge python3-virtualenv
/usr/bin/python3.8 -m pip install --force-reinstall virtualenvwrapper
/usr/bin/python3.8 -m pip install --force-reinstall virtualenv==20.0.23
.24 no longer works. I hope it will be solved sometimes...
EDIT 2021.01: I have changed my stack to: pyenv + pyenv-virtualenvwrapper + poetry. Ie. I use no apt or pip installation of virtualenv or virtualenvwrapper, and instead I install pyenv's plugin pyenv-virtualenvwrapper. This is easier way.
If someone encounters this problem inside existing env (when for example using pyenv) you can also use command below (found on GitHub when tried to fix poetry virtual env installation):
pip install --force-reinstall virtualenv
When I installed virtualenv via pip3, it failed to run virtualenv command. Then I changed the installation via:
sudo apt install python3-virtualenv
The virtualenv command can normally work.
I too had this issue. What I found is it is a permissions issue. For some unknown reason ownership of my home directory was off. I did a chown -R for the directory I was using for my project making myself the owner of my own directory and now everything works as normal.
I also had same issue, seems installed version has different user level so I followed their doc and below one work for me:
python3 -m virtualenv --help
To create new environment:
python3 -m virtualenv my_env
I also faced the same issue but after removing virtualenv which was installed with pip3, I could get rid of this error. Uninstall virtualenv with below command (don't forget to use sudo)
sudo pip3 uninstall virtualenv
After this, virtualenv command works totally fine.
It means that there are two virtualenv in your system.
One is "pip install" by sudo or root, the other may be installed by apt(if you are using ubuntu os)
Just uninstall one of them and the error should be fixed.
I fixed this error by removing all virtualenv and virtualenvwrapper related packages on system and reinstall the virtualenv and virtualenvwrapper with pip with below command(as i use ubuntu, so below only show apt)
remove all packages shown in below result
apt list --installed | grep virtualenvwrapper
apt list --installed | grep virtualenvwrapper
install virtualenv virtualenvwrapper with pip
pip install virtualenvwrapper virtualenvwrapper
set ~/.zshrc
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/amd
export VIRTUALENVWRAPPER_SCRIPT=/home/robot/.local/bin/virtualenvwrapper.sh
export VIRTUALENVWRAPPER_PYTHON=$(which python3)
source /home/robot/.local/bin/virtualenvwrapper.sh
When we use pip3 or python3 to install virtualenv then I got that error too. I had to run each time to create virtualenv (my_env is virtual environment name)
python3 -m virtualenv my_env
But if I install it using
sudo apt install virtualenv
Then virtualenv command works fine.
virtualenv my_env

How to setup virtual environment for python(2.7, 3.5, 3.6) on Ubuntu16.04 LTS?

I've read a lot of blog post about this and I'm still confused as to what is "best" way to set it up. Most of the blog posts I've read are out-dated. I'm new to Linux and have messed up my system twice now and still can't setup the virtual environments properly. According to what I've read, Virtualenv and Virtualenvwrapper combination is the most widely used setup. So, After a fresh Ubuntu 16.04 LTS install, I do the following:
Install Python 3.6 as shown in the following link.
https://tecadmin.net/install-python-3-6-ubuntu-linuxmint/
The current state of the system now is,
$ python3.6 -V
Python 3.6.4
$ pip3.6 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
pip3 (python3.5) and pip(python2.7) do not come pre-installed. To install them , I do:
$ sudo apt-get install python-pip
$ sudo apt-get install python3-pip
$ which pip
/usr/bin/pip
$ which pip3
/usr/bin/pip3
Now, the pip-version installed through apt-get method is old(version 8.1.1). We need to update it to (version 9.0.1). This is where it all goes wrong.
Question 1: How do I update the two different pip versions without breaking anything?
Assume, both pip versions are upgraded to version 9.0.1
Now, I have to install virtualenv and virtualenvwrapper.
Which pip version do I use to install it?
$ pip install --user virtualenv and $ pip install --user virtualenvwrapper
or
$ pip3 install --user virtualenv and $ pip3 install --user virtualenvwrapper
ps: I'm following this link-
http://chrisstrelioff.ws/sandbox/2016/09/21/python_setup_on_ubuntu_16_04.html
With python 3.6 virtual environments come built-in with the venv module:
python3.6 -m venv my-venv
To create a virtual environment for python 3.5:
virtualenv -p python3.5 env
To create a virtual environment for python 2.7:
virtualenv -p python2.7 env
Try using conda to set up virtual environments ?
With conda you can create a virtual environment and keep each of them separate from the root environment.

How to have python 2 and 3 in virtualenv

I have a virtualenv (python2api) made in python2.7 on Ubuntu 16.04. In the virtualenv I installed python3.5:
$ virtualenv -p python3.5 python2api
Then I installed pip3:
$ sudo apt-get install python3-pip
But when I run 'which pip' it shows that pip3 installed outside of the virtualenv and any pip3 packages I install go to '/usr/lib/python2.7' instead of '/var/env/python2api/lib/python3.5/site-packages/'.
(python2api) user#comp:/var/env/python2api/lib$ which pip
/var/env/python2api/bin/pip
(python2api) user#comp:/var/env/python2api/lib$ which pip3
/usr/bin/pip3
Is there a way to make pip3 install packages in the virtualenv? It seems like only python2 or only python3 packages can exist in the virtualenv.
A virtualenv encapsulates one version of Python.
You can't use it to manage more than one version, and Python 2.x and Python 3.x are separate versions here.
Use two separate virtualenvs, one for each Python version.

Ubuntu says virtualenv is not installed but pip says it is

I am trying to create another virtual environment (I already installed one using the typical instructions found here: http://docs.python-guide.org/en/latest/dev/virtualenvs/) so I run:
$ virtualenv experimental
-> The program 'virtualenv' is currently not installed. You can install it by typing: sudo apt install virtualenv
I checked to see if perhaps the program needed to be updated:
$ pip install virtualenv --upgrade
-> Requirement already up-to-date: virtualenv in /home/uniside/.local/lib/python2.7/site-packages
Any ideas about what is going on here?
Use sudo. Currently it's being install in your local directory.
sudo pip install virtualenv
The answer by #khrm didn't worked for me.
I was able to do this with :
sudo apt install virtualenv
I had problems activating my virtualenv projects with Ubuntu's system version, so I just use pip's virtualenv. Works with python2 as well:
$ pip3 install virtualenv
Just call virutalenv via python3 -m:
$ python3 -m virtualenv --help
Usage: virtualenv.py [OPTIONS] DEST_DIR

Categories