Python Forum
Not able to set up a virtual environment with venv - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Not able to set up a virtual environment with venv (/thread-30515.html)



Not able to set up a virtual environment with venv - mohanp06 - Oct-24-2020

I am new to Python. While going through the tutorials, I came to know that we should set up a virtual environment before installing any Python packages. So I tried it. It is creating the new environment directory but I am getting the following error:

Error:
Command '['/home/mohanp/programming/python/environments/test_env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
When I run the 'source' command to activate this newly created environment, it does not work because there is nothing inside the bin folder of the newly created environment directory test_env.

How do I overcome this hurdle and get started with Python?

System Details:

System: Linux Mint 18
Python: 3.7.4

Many Thanks.


RE: Not able to set up a virtual environment with venv - bowlofred - Oct-24-2020

Can you show the exact command you ran that generated this error?


RE: Not able to set up a virtual environment with venv - mohanp06 - Oct-24-2020

(Oct-24-2020, 07:09 AM)bowlofred Wrote: Can you show the exact command you ran that generated this error?

This is the command I entered inside the 'environments' folder in which I wish to create different environments.

python3 -m venv test_env


RE: Not able to set up a virtual environment with venv - snippsat - Oct-24-2020

(Oct-24-2020, 10:43 AM)mohanp06 Wrote: This is the command I entered inside the 'environments' folder in which I wish to create different environments.
test_env will be the environment folder,you shall not do this command inside other environments.
Quick demo with Mint 19.1.
# Test python
tom@tom-VirtualBox:~$ python -V
Python 3.8.5

# Test pip
tom@tom-VirtualBox:~$ pip -V
pip 20.2.3 from /home/tom/.pyenv/versions/3.8.5/lib/python3.8/site-packages/pip (python 3.8)

# Make environment 
tom@tom-VirtualBox:~$ python -m venv test_env

# cd in
tom@tom-VirtualBox:~$ cd test_env/

# Activate, see (test_env)
tom@tom-VirtualBox:~/test_env$ source bin/activate

# Test pip again,point now to test_env folder
(test_env) tom@tom-VirtualBox:~/test_env$ pip -V
pip 20.1 from /home/tom/test_env/lib/python3.8/site-packages/pip (python 3.8)
(test_env) tom@tom-VirtualBox:~/test_env$ 



RE: Not able to set up a virtual environment with venv - bowlofred - Oct-24-2020

Looking around suggests that mint/debian may have separate packages for portions of python. Can you see if you have the "python3.7-venv" package installed and install it if you don't?


RE: Not able to set up a virtual environment with venv - mohanp06 - Oct-27-2020

(Oct-24-2020, 06:11 PM)bowlofred Wrote: Looking around suggests that mint/debian may have separate packages for portions of python. Can you see if you have the "python3.7-venv" package installed and install it if you don't?

I tried to do it but it says no such package found.


RE: Not able to set up a virtual environment with venv - mohanp06 - Oct-27-2020

(Oct-24-2020, 01:25 PM)snippsat Wrote:
(Oct-24-2020, 10:43 AM)mohanp06 Wrote: This is the command I entered inside the 'environments' folder in which I wish to create different environments.
test_env will be the environment folder,you shall not do this command inside other environments.
Quick demo with Mint 19.1.
# Test python
tom@tom-VirtualBox:~$ python -V
Python 3.8.5

# Test pip
tom@tom-VirtualBox:~$ pip -V
pip 20.2.3 from /home/tom/.pyenv/versions/3.8.5/lib/python3.8/site-packages/pip (python 3.8)

# Make environment 
tom@tom-VirtualBox:~$ python -m venv test_env

# cd in
tom@tom-VirtualBox:~$ cd test_env/

# Activate, see (test_env)
tom@tom-VirtualBox:~/test_env$ source bin/activate

# Test pip again,point now to test_env folder
(test_env) tom@tom-VirtualBox:~/test_env$ pip -V
pip 20.1 from /home/tom/test_env/lib/python3.8/site-packages/pip (python 3.8)
(test_env) tom@tom-VirtualBox:~/test_env$ 

This is what I did but I was getting error, so this post...


RE: Not able to set up a virtual environment with venv - snippsat - Oct-27-2020

(Oct-27-2020, 11:08 AM)mohanp06 Wrote: This is what I did but I was getting error, so this post.
Have you build Python: 3.7.4 yourself?
A common mistake is do not include all build tool.
As mention bye bowlofred python3.7-venv.
Try:
apt-get update
apt-get install python3.7-dev python3.7-venv
I use pyenv as i have tutorial about here pyenv Simple Python Version Management.
Look at point .1 there you see all build needed before build yourself or use pyenv to do this.