3

I went to do some python leetcode on a personal repo and after I upgraded my Kubuntu to 22.04 I realized the current venv wasn't working.

I had figured I would need to recreate the venv. Installed python3.10-venv but I cant source and activate it.

In fact venv/bin/activate doesn't exist anymore.

The folder only contains three files

python python3 python3.10

I had tried but no dice

source venv/bin/python3.10

So naturally source venv/bin/activate doesn't work. Ideas?

Michael Paccione
  • 2,467
  • 6
  • 39
  • 74

3 Answers3

6

I've installed Ubuntu 22.0.4 and I've had the same problem as yours and I solved that problem in this way.

install venv:

  1. sudo apt-get update

  2. sudo apt-get install python3-virtualenv

Create venv:

  1. virtualenv --python=/usr/bin/python3.10 (VENV-NAME)
  2. python3.10 -m venv (VENV-NAME)
  3. source (VENV-NAME)/bin/activate

check & update pip:

  1. pip list
  2. and update pip for example(in my pc): (/home/amin/Desktop/prog/Django/moein/coffeinrider.com/Project/A/(VENV-NAME)/bin/python3.10 -m pip install --upgrade pip)
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Amin
  • 181
  • 2
  • 5
  • Okay I had solved this issue previously but I cant remember exactly lol...I'm going to mark yours as the answer however. Additionally for convenience: https://docs.python.org/3/library/venv.html – Michael Paccione Jun 20 '22 at 18:28
  • What? The package name is changed from python3-venv to python3-virtualenv? I've tried python3-venv, and found serious problem on version unmet! Anyone know any difference between venv and virtualenv???? Are they mistakes made by Ubuntu maintaining team? – Clock ZHONG Dec 03 '22 at 14:16
2

When trying to create a virtual env using venv for Python, a version of Python that is already installed system-wide must be used, but a version of the venv library from the system must also be used. These are two pre-requisites for setting up a virtual environment.

WARNING: I did this in a hurry because I needed it but please be warned: this may break your system Python with a result that applications that rely on it may break.

The problem I had, matching symptoms given here, seems to be that when trying to create a venv using Python 3.10.8, the venv module for Python 3.8.10 was being used.

So, given Python 3.8 and Python 3.10 are already installed using apt, first of all I uninstalled these packages:

sudo apt purge python3-venv python3.8-venv
sudo apt autoremove

Then I linked python3 to point to Python 3.10:

cd /usr/bin
sudo rm python3
sudo ln python3.10 python3

Then I installed the venv for Python3.10:

sudo apt install python3.10-venv

This now means creating a virtual environment for Python 3.8 doesn't work (because Python3.8 venv has just been removed). I'm not sure if there is a means to have them both working, and I haven't yet tried to just install python3.8-venv again and try them both, as I need my 3.10 environment working quickly, right now ;-). But it seems possible there has been some conflict introduced when following the usual upgrade route within Ubuntu 20.

However, venv for Python 3.10 should now work as expected:

$ python3 -m venv .venv
$ source .venv/bin/activate
(.venv) $ python -V
Python 3.10.8
(.venv) $ pip install --upgrade pip
...
(.venv) $ pip list
Package    Version
---------- -------
pip        22.3
setuptools 63.2.0
NeilG
  • 3,886
  • 2
  • 22
  • 30
  • This worked for me: `sudo apt install python3.10-venv`. If apt cannot find an install candidate, you might need to do `sudo apt update` before. – mdev Nov 09 '22 at 11:45
  • Wow , This worked for me after struggling for 2 days , Thank you so much. – ParSa Dec 07 '22 at 23:12
0

It has been updated to source venv/local/bin/activate