30

I am trying to install python3 virtualenv. I get the following message when I try to run virtualenv.

virtualenv
Command 'virtualenv' not found, but can be installed with:
apt install python3-virtualenv

but if I run install command, I get the following error.

apt install python3-virtualenv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package python3-virtualenv

For python3 -m venv, I get message to install using apt-get install python3-venv but when I try it, I get the same message.

sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package python3-venv is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'python3-venv' has no installation candidate

I am running this as root. wget also works.

RedFox
  • 1,158
  • 2
  • 15
  • 28

11 Answers11

66

AFAIU the latest versions of Ubuntu removed Python2 altogether so Python3 is now just the Python. Try:

apt-get update
apt-get install python3-virtualenv
phd
  • 82,685
  • 13
  • 120
  • 165
  • 1
    On GCP shell, I get the following error ``` sudo apt-get install python-virtualenv Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package python-virtualenv ``` – RedFox Jun 10 '20 at 23:52
  • 12
    what if we get `Package python-virtualenv is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'python-virtualenv' has no installation candidate ` – T.Todua Oct 14 '20 at 20:38
  • 2
    @T.Todua I'm too getting your error on Digitalocean – Pavindu Oct 23 '20 at 01:59
  • This outputs Package 'python-virtualenv' has no installation candidate – Michael Rogers Feb 20 '21 at 23:30
  • 4
    @MichaelRogers Try `apt-get update && apt-get install python3-virtualenv` – phd Feb 21 '21 at 00:26
  • the only step missing for me was apt-get update – Aanish Amir Waseem Dec 06 '22 at 06:11
  • It also worked for me with `apt-get update`. But how is this related to Python 2 being removed from the latest versions of Ubuntu? – Loïs Talagrand Jul 15 '23 at 18:30
12

try type in terminal:

sudo apt-get install python3.8-venv

and then try again install virtualenv

artix97
  • 141
  • 6
  • 5
    This didnt help – Pavindu Oct 23 '20 at 02:01
  • 1
    I tried but got this error: sudo apt install python3.8-venv Reading package lists... Done Building dependency tree... Done Reading state information... Done Package python3.8-venv is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source E: Package 'python3.8-venv' has no installation candidate – Dat TT May 10 '22 at 16:58
  • 2
    Trying similar for Python 3.10 and I get `Package 'python3.10-venv' has no installation candidate` – InnocentBystander Dec 17 '22 at 02:55
10

This will definitely work:

sudo apt-get update
sudo apt-get install python3-virtualenv
Mahesh Jamdade
  • 17,235
  • 8
  • 110
  • 131
Mucks Won
  • 101
  • 1
  • 2
5

The below is very similar to the answer by phd, but my freshly installed Ubuntu 20.04 still requires the python version number:

apt-get update
apt-get install python3-virtualenv
dr.Pep
  • 51
  • 1
  • 2
3

I also got that problem and was able to solve it by follow means:

software-properties-gtk

After clicking enter a window pops up. Then you have to check the first 4 boxes, close it and refresh it. After that the problem should be solved and you're ready to go

2

I was getting the error E: Unable to locate package python3-virtualenv because I had to run apt-get update first. This was my brand new GCP instance.

Reference: first comment of the first answer in this thread. Unable to locate package virtualenv in ubuntu-13 on a virtual-machine

Thank you all.

RedFox
  • 1,158
  • 2
  • 15
  • 28
2
sudo apt install python3-virtualenv
vvvvv
  • 25,404
  • 19
  • 49
  • 81
Desarrollalab
  • 337
  • 2
  • 5
1

try the following

sudo apt install python3-pip
pip install virtualenv
virtualenv xyz-venv
1

Gotcha with the following:

sudo apt update
sudo apt install python3-virtualenv

But python3 -m venv no longer works. Use virtualenv venv instead. Activate using . venv/bin/activate per usual.

edc
  • 99
  • 1
  • 8
0

First get the updated information and then install the virtual environment with below two command simultaneously.

sudo apt update
sudo apt install python3-virtualenv
Tanvir Nayem
  • 702
  • 10
  • 25
0

For this issue:

sudo apt-get install python3-venv
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package python3-venv is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'python3-venv' has no installation candidate

I discovered that I had to first use sudo -s to use root privileges. And then run:

apt-get update
apt-get install python3-venv

And it worked. I was working on Ubuntu 18.04.5 LTS

AEChris
  • 11
  • 3