Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3.10 source venv has changed

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?

like image 918
Michael Paccione Avatar asked Jul 14 '26 22:07

Michael Paccione


2 Answers

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)
like image 129
Amin Avatar answered Jul 21 '26 01:07

Amin


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
like image 23
NeilG Avatar answered Jul 21 '26 00:07

NeilG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!