For background: my end goal is to add a clean install of Python 3.11 onto my Ubuntu 20.04 machine so that I can test some code I wrote that uses some of Python 3.11's new features. I'm not trying to replace my system Python or anything like that, I just want Python 3.11 for testing purposes.
What I've tried: First, I tried installing Python 3.11 directly through apt, but when I did apt-get install python3.11; python3.11 --version
, the output Python version was Python 3.11.0rc1
. But I want to install the final, stable version of Python 3.11, not a release candidate, so I uninstalled the Python 3.11rc I'd just installed.
A quick search led me to the deadsnakes PPA, so I added the deadsnakes PPA, updated apt, and successfully installed Python 3.11.0, this time not a release candidate (verified by python3.11 --version
). I then tried to verify that I had a clean install by python3.11 -m pip list
, but it listed almost 70 packages. I tried removing all these packages using python3.11 -m pip remove <packages>
, but this failed because some of the packages in the newly-installed Python 3.11 were built using distutils. I tried to check if there was a workaround to uninstall Python packages that were built using distutils, but I quickly determined that that is too far beyond my knowledge for me to comfortably tinker, if not outright impossible.
Thus, here's what I did up until now:
# first attempt at installing Python 3.11
> python3.11 --version #to ensure that I don't already have Python 3.11 installed
Command 'python3.11' not found, but can be installed with:
apt install python3.11
> python3 --version #to double ensure that my system Python version isn't 3.11
Python 3.10.6
> apt-get install python3.11 -y
> python3.11 --version
Python 3.11.0rc1
> apt-get remove python3.11 -y #removing unwanted rc version
> apt autoremove #removing additional python3.11-minimal and other packages that came when installing python3.11
second attempt at installing Python 3.11
> add-apt-repository ppa:deadsnakes/ppa --yes
> apt update; apt-get update;
> apt-get install python3.11 -y
> python3.11 --version
Python 3.11.0
> python3.11 -m pip list
blinker 1.4
certifi 2020.6.20
chardet 4.0.0
<66 more packages cut for brevity...>
> python3.11 -m pip uninstall blinker certifi chardet <66 more packages cut for brevity> --yes
Found existing installation: blinker 1.4
ERROR: Cannot uninstall 'blinker'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
Not sure what to do, I read the deadsnakes main page more closely, and I saw this:
The packages provided here are loosely based on the debian upstream packages with some modifications to make them more usable as non-default pythons and on ubuntu.
Perhaps I wildly misinterpreted this, but I read this to mean "When you install Python from deadsnakes, we include the same set of packages that Ubuntu's system Python would include, plus a few extras." That appears to explain my problem, or at least, it would explain why the Python 3.11 I installed has all the same packages as my system Python, plus a few extra.
So I tried finding a way to install just a clean, empty version of Python 3.11. I saw during my earlier attempts that I was actually installing multiple packages, including python3.11-minimal
. I figured maybe that would be what I needed, so I uninstalled Python3.11 again and installed python3.11-minimal
. This installed Python3.11, but python3.11 -m pip list
again returned a list of 69 packages, and like before, I couldn't remove them because some or all of them were built with distutils.
I thought it might be an issue specifically with Python 3.11, so I tried installing older versions of python to see if they also came with extra packages, but when I installed Python 3.8 and Python 3.9, they came with a bunch of extra packages just like Python 3.11 did.
I tried to find any reference online to installing a truly empty version of Python, or at least one that you can remove the extra packages from after install, but I couldn't find anything. I can't imagine it's a terribly uncommon thing to want though, because surely someone else has wanted to install a clean copy of non-system Python that doesn't come with an additional 60+ packages at some point, right?
So how can I install a clean copy of Python in addition to my system Python, that doesn't come with a bunch of unremovable packages bundled? Is it possible?
Is it possible, in Ubuntu, to install a version of python in addition to your system python, and then create a virtual environment with that secondary python, and get that virtual environment to a state such that, when you issue a pip list from within that new virtual environment, pip lists no packages outside of the stdlib (except maybe pip/setuptools)?
apt-get install python3.11; python3.11 -m venv venv; . venv/bin/activate; pip list
shows 60+ packages. Is this just how it works on Ubuntu? – Nick Muise Dec 02 '22 at 20:25pip list
from within a freshly-created virtual environment created within the freshly-installed Python 3.11, are NOT part of the stdlib, so the stdlib has no bearing on why I'm seeing these packages. – Nick Muise Dec 02 '22 at 23:34pip list
from within that new virtual environment, pip lists no* packages outside of the stdlib (except maybe pip/setuptools)?* If no, then I guess Python fundamentally does not work the same as it does on Windows. – Nick Muise Dec 02 '22 at 23:36