Python Forum
Not able to set up a virtual environment with venv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not able to set up a virtual environment with venv
#1
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.
Reply
#2
Can you show the exact command you ran that generated this error?
Reply
#3
(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
Reply
#4
(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$ 
Reply
#5
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?
Reply
#6
(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.
Reply
#7
(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...
Reply
#8
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with creating folder and "virtual environment" AudunNilsen 1 171 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  my venv is not loading njoki 1 182 Mar-20-2024, 10:41 AM
Last Post: snippsat
  Installing python packages in a virtual environment Led_Zeppelin 1 714 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,160 May-10-2023, 02:13 PM
Last Post: Calab
  Problem with virtual environment standenman 2 955 Feb-23-2023, 07:09 PM
Last Post: standenman
  Python venv and PIP version issue JanOlvegg 2 1,201 Feb-22-2023, 02:22 AM
Last Post: JanOlvegg
Question Virtual Environment (using VS Code) Ashcora 4 12,536 Feb-15-2023, 07:17 PM
Last Post: snippsat
  Visual Studio Code venv ibm_db error mesi1000 7 2,664 Nov-13-2022, 12:36 AM
Last Post: snippsat
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,332 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  Project structure with a virtual environment gdbengo 1 1,392 Jan-26-2022, 03:22 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020