Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@Nishnha
Copy link

Nishnha commented Feb 5, 2018

Virtualenv doesn't require root permissions to install:

Then install virtualenv using pip3:

pip3 install virtualenv

@guruvishnuvardan
Copy link

guruvishnuvardan commented Feb 15, 2018

HI I am getting an error while installing virutal environment or any installation, Can you please help me. Please find the screen shot below
venv error

I have tried to rectify by searching and installing all the related fixes shown in the Internet.

@alphaCTzo7G
Copy link

alphaCTzo7G commented Mar 18, 2018

@guruvishnuvardan, I have a feeling this is related to you trying to install virtualenv as a root.

Unlike apt-get, you shouldn't use sudo to use pip

@mishafeingold
Copy link

mishafeingold commented Apr 20, 2018

When I installed without sudo I got an error. I had to use the --user option.
Error:

pip3 install virtualenv
Collecting virtualenv
  Downloading https://files.pythonhosted.org/packages/ed/ea/e20b5cbebf45d3096e8138ab74eda139595d827677f38e9dd543e6015bdf/virtualenv-15.2.0-py2.py3-none-any.whl (2.6MB)
    100% |████████████████████████████████| 2.6MB 8.8MB/s 
Installing collected packages: virtualenv
Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/usr/local/lib/python3.5/dist-packages/virtualenv.py'
Consider using the `--user` option or check the permissions.

Solution using --user:

pip3 install virtualenv --user
Collecting virtualenv
  Using cached https://files.pythonhosted.org/packages/ed/ea/e20b5cbebf45d3096e8138ab74eda139595d827677f38e9dd543e6015bdf/virtualenv-15.2.0-py2.py3-none-any.whl
Installing collected packages: virtualenv
Successfully installed virtualenv-15.2.0

@ArthKate
Copy link

ArthKate commented Jun 12, 2018

am using mint rosa and whenever I try to install the venv, all goes well until I get msg E: unable
to locate package python3-env. Am stuck at this point. I really need help

@amitjoshi9627
Copy link

amitjoshi9627 commented Jun 15, 2018

Thanks --user worked for me..

@arnold-parge
Copy link

arnold-parge commented Jun 15, 2018

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

@ivotron
Copy link

ivotron commented Jun 27, 2018

I was getting the following:

Exception:
Traceback (most recent call last):
  File "/home/ivo/venvs/sk3/lib/python3.5/site-packages/pip/_internal/basecommand.py", line 228, in main
    status = self.run(options, args)
  File "/home/ivo/venvs/sk3/lib/python3.5/site-packages/pip/_internal/commands/install.py", line 335, in run
    use_user_site=options.use_user_site,
  File "/home/ivo/venvs/sk3/lib/python3.5/site-packages/pip/_internal/req/__init__.py", line 49, in install_given_reqs
    **kwargs
  File "/home/ivo/venvs/sk3/lib/python3.5/site-packages/pip/_internal/req/req_install.py", line 748, in install
    use_user_site=use_user_site, pycompile=pycompile,
  File "/home/ivo/venvs/sk3/lib/python3.5/site-packages/pip/_internal/req/req_install.py", line 961, in move_wheel_files
    warn_script_location=warn_script_location,
  File "/home/ivo/venvs/sk3/lib/python3.5/site-packages/pip/_internal/wheel.py", line 216, in move_wheel_files
    prefix=prefix,
  File "/home/ivo/venvs/sk3/lib/python3.5/site-packages/pip/_internal/locations.py", line 165, in distutils_scheme
    i.finalize_options()
  File "/usr/lib/python3.5/distutils/command/install.py", line 388, in finalize_options
    ('build_lib', 'build_lib'))
  File "/usr/lib/python3.5/distutils/cmd.py", line 286, in set_undefined_options
    src_cmd_obj = self.distribution.get_command_obj(src_cmd)
  File "/usr/lib/python3.5/distutils/dist.py", line 857, in get_command_obj
    self._set_command_options(cmd_obj, options)
  File "/usr/lib/python3.5/distutils/dist.py", line 901, in _set_command_options
    % (source, command_name, option))
distutils.errors.DistutilsOptionError: error in setup.cfg: command 'build' has no such option 'i18n'

Since I don't mind to use 2.7, this is what ended up working for me:

sudo apt install python-pip python-distutils-extra python-elib.intl
sudo pip install virtualenv 

Something similar might be available for python3

@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

BillyZafack commented Jul 6, 2018

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

@GitauHarrison
Copy link

GitauHarrison commented Sep 24, 2018

Thank Y'all! This was helpful

@MohammedNagdy
Copy link

MohammedNagdy commented Jan 22, 2019

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

connelevalsam commented Mar 14, 2019

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

Mamu9-zz commented Sep 22, 2019

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

bhatbhupendra commented Jul 1, 2020

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

mursalatul commented Mar 30, 2021

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

amanprakashsingh commented Apr 3, 2021

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

@OjiboVictor
Copy link

OjiboVictor commented Jul 10, 2021

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

Almistro12 commented Jan 18, 2022

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

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