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
[email protected]:~$ python -V
Python 3.8.5

# Test pip
[email protected]:~$ 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 
[email protected]:~$ python -m venv test_env

# cd in
[email protected]:~$ cd test_env/

# Activate, see (test_env)
[email protected]:~/test_env$ source bin/activate

# Test pip again,point now to test_env folder
(test_env) [email protected]:~/test_env$ pip -V
pip 20.1 from /home/tom/test_env/lib/python3.8/site-packages/pip (python 3.8)
(test_env) [email protected]:~/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
to[email protected]:~$ python -V
Python 3.8.5

# Test pip
[email protected]:~$ 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 
[email protected]:~$ python -m venv test_env

# cd in
[email protected]:~$ cd test_env/

# Activate, see (test_env)
[email protected]:~/test_env$ source bin/activate

# Test pip again,point now to test_env folder
(test_env) [email protected]:~/test_env$ pip -V
pip 20.1 from /home/tom/test_env/lib/python3.8/site-packages/pip (python 3.8)
(test_env) [email protected]:~/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
  import statement in a virtual environment leodavinci1990 1 379 Mar-04-2021, 12:57 AM
Last Post: snippsat
  Virtual environment and upgrading python 3.5 to 3.9 NeilUK 4 625 Jan-24-2021, 01:02 PM
Last Post: snippsat
  pip and venv virtual environments soupworks 2 412 Dec-30-2020, 11:38 PM
Last Post: soupworks
  Do I need to make a virtual environment? Pedroski55 5 701 Sep-21-2020, 12:10 AM
Last Post: seandepagnier
  sys.path for virtual environment ErnestTBass 2 558 Sep-10-2020, 06:36 PM
Last Post: ErnestTBass
  Cannot get to virtual environment in Jupyter IDE ErnestTBass 6 897 Sep-09-2020, 05:56 PM
Last Post: ErnestTBass
  [PyCharm] Working with virtual environment AndrzejB 1 487 Jul-18-2020, 06:22 PM
Last Post: AndrzejB
  Has anyone figured out how to get pywin32 into a virtual environment yet? RobR 6 926 Jun-04-2020, 01:26 PM
Last Post: RobR
  Unable to install virtual environment on python 3.8.3 Allen10 4 832 Jun-04-2020, 04:22 AM
Last Post: Larz60+
  Pycharm Virtual environment Bark52 0 457 May-27-2020, 02:40 AM
Last Post: Bark52

Forum Jump:

User Panel Messages

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