Skip to content

Instantly share code, notes, and snippets.

@frfahim
Last active April 28, 2024 17:13
Show Gist options
  • Save frfahim/73c0fad6350332cef7a653bcd762f08d to your computer and use it in GitHub Desktop.
Save frfahim/73c0fad6350332cef7a653bcd762f08d to your computer and use it in GitHub Desktop.
How to install virtual environment on ubuntu 16.04

How to install virtualenv:

Install pip first

sudo apt-get install python3-pip

Then install virtualenv using pip3

sudo pip3 install virtualenv 

Now create a virtual environment

virtualenv venv 

you can use any name insted of venv

You can also use a Python interpreter of your choice

virtualenv -p /usr/bin/python2.7 venv

Active your virtual environment:

source venv/bin/activate

Using fish shell:

source venv/bin/activate.fish

To deactivate:

deactivate

Create virtualenv using Python3

virtualenv -p python3 myenv

Instead of using virtualenv you can use this command in Python3

python3 -m venv myenv

Install pip3

sudo apt-get install -y python3-pip

to install package

pip3 install package_name

setup few more packages and development tools

sudo apt-get install build-essential libssl-dev libffi-dev python-dev

install venv module

sudo apt-get install -y python3-venv

create a enviornments

python3 -m venv project_env

@saeidalidadi
Copy link

very useful!!!!!:)

@Ishaan-Adarsh
Copy link

Direct and simple. very useful.

@mfalgorepublic
Copy link

Thanks buddy! It helped.

@kifirifis
Copy link

Simple y fácil. Gracias.

@Samuel-Njoroge
Copy link

The packages have been obsoleted for Ubuntu 20.0.

@sowrovsarkar63
Copy link

It was very useful and straight forward. Thank you

@DianaLozanoP
Copy link

DianaLozanoP commented Jul 31, 2023

Hello there,
When I try to install the python3-venv package using the following command.

sudo apt install python3.10-venv

I get this error:
" Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
python3.10-venv : Depends: python3.10 (= 3.10.4-3) but 3.10.6-1~22.04.2ubuntu1 is to be installed
E: Unable to correct problems, you have held broken packages. "

I'm using Ubuntu 22.04.2 LTS, Python 3.10.6.

If someone can help me or guide, I would appreciate it. I'm a newbie here. Thanks!

@BakrFrag
Copy link

@DianaLozanoP you don't have to use 3.10 version unless you have multiplie versions of python 3 on your system
also make sure pip python package index is installed
also make sure your software dependencies on system are up to date use blow commands
sudo apt update
sudo apt upgrade -y
to install python3 pip on ubuntu sudo apt install python3-pip
venv module now in python default packages so you don't have to install

@DianaLozanoP
Copy link

DianaLozanoP commented Jul 31, 2023

Hey @BakrFrag,
I followed your suggestions, and they worked wonders.
Now I can use a virtual environment.
Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment