Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Geoyi/d9fab4f609e9f75941946be45000632b to your computer and use it in GitHub Desktop.
Save Geoyi/d9fab4f609e9f75941946be45000632b 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
@skiz
Copy link

skiz commented Jul 3, 2018

pip installed binaries are located at ~/.local/bin, so you need to add that to your path.

echo "export PATH=~/.local/bin:$PATH" > ~/.profile 
source ~/.profile

@BillyZafack
Copy link

Just in case you are on running vagrant add '--always-copy'

@GitauHarrison
Copy link

Thank Y'all! This was helpful

@MohammedNagdy
Copy link

How do you make virtualenv global?

@vivonk
Copy link

vivonk commented Jan 24, 2019

virtualenv are not intended for global thing. If you want some dependency on global access, they are already @MohammeNagdy

@connelevalsam
Copy link

Yeah...
Just:
mkdir project
cd project
sudo apt-get install python3-pip
pip3 install virtualenv
python3 -m venv myenv

then you start installing all the libraries you need for that project

@0-admin
Copy link

0-admin commented Apr 15, 2019

I dob't care, guis) Im protecting as you are, but you can see it

@0-admin
Copy link

0-admin commented Apr 15, 2019

I don't have a terminal

@Mamu9-zz
Copy link

If you have Python3.3 and newer version, venv is already there. Here how it worked for me without installing virtualenv.

python -m venv .

python -m venv without period didn't work

Screenshot from 2019-09-22 05-29-47

ls command displayed bin include lib share and pyvenv.cfg files

Screenshot from 2019-09-22 05-40-40

After that I activated the venv and installed Django. And then run the server and created the project mamusite

Screenshot from 2019-09-22 06-19-16

@bhatbhupendra
Copy link

OSError: [Errno 9] Bad file descriptor
my error while creating the virtual env

@kibablu
Copy link

kibablu commented Nov 18, 2020

Steps I followed:

sudo apt-get install python3-pip
pip3 install virtualenv 
virtualenv venv 

But I get error as:

The program 'virtualenv' is currently not installed. You can install it by typing:
sudo apt install virtualenv

use sudo apt-get update then use sudo apt-get install virtualenv

@kibablu
Copy link

kibablu commented Nov 18, 2020

OSError: [Errno 9] Bad file descriptor
my error while creating the virtual env

could you please provide more details, like

  • what OS are you using

  • what command did you run and displayed an error

  • do you have any screenshots you can share

@mursalatul
Copy link

can anyone please tell me why i cant use virtualenv in this directory? i am using ubuntu LTS 20.04
image

@kibablu
Copy link

kibablu commented Mar 31, 2021

@mursalatul could you please name dele to venv your command should look like this source venv/bin/activate
you can create venv using this command python3 -m venv venv

@amanprakashsingh
Copy link

Screenshot from 2021-04-04 01-23-15
it is telling permission denied what to do ?

@OjiboVictor
Copy link

Hi ,I have installed pip3 and the virtual environment but I'm unable to activate it. I really tried running the pip3 install virtualenv and this is what it is displaying....

C:\Users\USER>pip3 install virtualenv
Requirement already satisfied: virtualenv in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (20.4.7)
Requirement already satisfied: filelock<4,>=3.0.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from virtualenv) (3.0.12)
Requirement already satisfied: six<2,>=1.9.0 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from virtualenv) (1.16.0)
Requirement already satisfied: distlib<1,>=0.3.1 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from virtualenv) (0.3.2)
Requirement already satisfied: appdirs<2,>=1.4.3 in c:\users\user\appdata\local\programs\python\python39\lib\site-packages (from virtualenv) (1.4.4)

Please can you help me out? Thank you

@Almistro12
Copy link

ice_screenshot_٢٠٢٢٠١١٨-٠٧٤٢١٤

@abhishekprajapati1
Copy link

Thanks. it worked for me in zorin os

@mursalatul
Copy link

@mursalatul could you please name dele to venv your command should look like this source venv/bin/activate you can create venv using this command python3 -m venv venv

thank you. i appreciate it.

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