skip to Main Content

I had just upgraded to Ubuntu 22.04.1 LTS, which comes preinstalled with python3.10. I tried creating a virtual environment but it was unsuccessful. Trying to install the virtual env package gets an error E: Package 'python3-venv' has no installation candidate

python3 -m venv newpy310
The virtual environment was not created successfully because ensurepip is not
available.  On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.

    apt install python3.10-venv

You may need to use sudo with that command.  After installing the python3-venv
package, recreate your virtual environment.

Failing command: ['/home/user/Desktop/pyenvs/newpy310/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']

Following which i used sudo apt install python3.10-venv, and was returned with

sudo apt install python3.10-venv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package python3.10-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.10-venv' has no installation candidate

Something similar can be encountered if I used sudo apt install python3.10-virtualenv

sudo apt-get install python3.10-virtualenv
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package python3.10-virtualenv
E: Couldn't find any package by glob 'python3.10-virtualenv'
E: Couldn't find any package by regex 'python3.10-virtualenv'

My sudo apt-get update also looks suspicious, but i am not entirely sure if it is the culprit

sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease                                                 
Hit:2 http://security.ubuntu.com/ubuntu jammy-security InRelease                                       
Hit:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease                                         
Hit:4 http://archive.ubuntu.com/ubuntu focal-security InRelease                  
Hit:5 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease
Hit:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:7 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:8 http://archive.ubuntu.com/ubuntu jammy-updates InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
8 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en_SG) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11 (main/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11 (main/dep11/Components-all.yml) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons-small (main/dep11/icons-48x48.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons (main/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons-hidpi (main/dep11/[email protected]) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target CNF (main/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target CNF (main/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-amd64/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-i386/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Packages (main/binary-all/Packages) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en_US) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target Translations (main/i18n/Translation-en_SG) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11 (main/dep11/Components-amd64.yml) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11 (main/dep11/Components-all.yml) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons-small (main/dep11/icons-48x48.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons (main/dep11/icons-64x64.tar) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target DEP-11-icons-hidpi (main/dep11/[email protected]) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target CNF (main/cnf/Commands-amd64) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14
W: Target CNF (main/cnf/Commands-all) is configured multiple times in /etc/apt/sources.list:13 and /etc/apt/sources.list:14

I also have already added the deadsnakes ppa repos. I noticed some other questions were for python 3.6 or 3.8, which had worked in the past when i was using python 3.6 and 3.8 respectively. However, the methods described within does not work for my current setup with Ubuntu 22.04 and python3.10.

  1. python3.8-venv not working with python3.8 -m venv env
  2. python3.8-venv is no longer working after Pop OS upgraded to 21.04
  3. Trouble Installing Python3.6 Virtual Environment on Ubuntu 22.04

These are the other links that I have consulted but did not work for me. I have also tried reinstalling python3.10 itself.

  1. How to use Python3.10 on Ubuntu?
  2. Trouble Installing Python3.6 Virtual Environment on Ubuntu 22.04
  3. pyvenv not working because ensurepip is not available
  4. pyvenv not working because ensurepip is not available
  5. https://askubuntu.com/questions/879437/ensurepip-is-disabled-in-debian-ubuntu-for-the-system-python
  6. Python3.10 source venv has changed

Q: How to install python3.10 virtual environment when python3.10-venv has no installation candidate?

2

Answers


  1. Chosen as BEST ANSWER

    Found out from the comments over here in another question that the problem was because the venv package was not added yet at the time when i wrote the question

    Running sudo apt install python3.10-venv now allows me to install the package, and i can now make a python3.10 virtual environment on the default Ubuntu 22.04 LTS


  2. python3.10-venv is typically the package that provides the venv module for creating virtual environments in Python 3.10. If the package is not found when you try to install it, it may mean that it is not available in the package repository for your specific distribution or version of Linux.

    One way to create a virtual environment with Python 3.10 is by using the pyenv tool. pyenv allows you to easily install and manage multiple versions of Python on your system. You can install pyenv by following the instructions on the GitHub page: https://github.com/pyenv/pyenv

    Once you have pyenv installed, you can install Python 3.10 by running the following command:

    pyenv install 3.10.0
    

    You can the create your environement

    pyenv virtualenv 3.10.0 my_env
    
    

    This will create a new virtual environment called my_env that uses Python 3.10.0. To activate the virtual environment, run the following command:

    pyenv activate my_env
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search