HexTxt

Multiple Python Installations

Technology
cyberpunk software developer and a pink python hacking from sidewalk chair

Image generated by deepai.org -- three happy, friendly, pythons writing software

When did Python 1.52 make an appearance in the programming world? Python 1.52 was the first version I used. Still have an old reference book for that version. Time keeps rolling along.

Having spent a couple years or so recovering from my last cubicle burnout experience I feel ready to get back into some tech fun. Having served me well all these years I decided to get my Python mojo back.

What to install? Python3 is the current major version, Python2 is no longer being developed. There are a number of choices for Python3 including alternatives like Anaconda.

A few of these Pythons sounded like they would be fun to get to know again. So I started looking around for a way to install and manage them without having too many headaches in the process.

Installing Python Package

My MX Linux system already has Python3. A quick update and upgrade gets my system Python up-to-date. If you don’t have the latest Python for you Linux system you can go ahead and install, too.

$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install python3

Pretty easy. One snag. With MX Linux being Debian based the Python version is not the latest release. Since I wanted to use the latest release that was a problem.

Compile Python from Source

What do you do if you want the most current Python and your package repository doesn’t track the latest version? One option is to download the source code and compile your own.

What I don’t like about compiling is removing the compiled version can be messy finding all the files to remove. Sure uninstalling might be possible via:

$ sudo make uninstall 

I don’t trust this approach enough to rely on it. Too many things going on during the installation process to keep track of let alone remember in six months.

Luckily, there is a solution (see below) which allows me to keep the version of Python I am compiling in one spot away from my system installations. Then if I want to remove it I can just delete one directory. No file hunting!

Just down load the source, extract it, and switch to the source directory. And do the following:

$ ./configure --prefix=/opt/python/3.11.2 --enable-optimizations
$ make -j3
$ sudo make altinstall

What is going on here?

Somewhere online I found a suggestion I really like and is working out nicely for keeping multiple versions of Python. Setting the prefix option to /opt/python/ puts all the files in one easy to find spot. Very handy!

The enable-optimizations option was just something I wanted to play around with. I haven’t had a chance yet to measure the impact.

With make -j3 the compiler uses 3 of my 4 cores. It did appear to compile pretty fast.

Finally, Python gets installed in the prefix directory.

Anaconda3

The third Python I installed is really much more than Python. Anaconda3 from https://anaconda.com is a suite of software which includes not only Python but a number of other tools and packages of interest to data scientists. If data science is your thing it is worth a look. Plus it is really easy to install on whatever major operating system you use.

The question is where to install Anaconda3? The default location for installing on Linux is the user home directory. Personally, I attempt to keep my home directory from getting too full. Keeping with the same generaly idea of using /opt when compiling form source I installed Anaconda3 into my ~/opt directory.

Pick Your Python

Looks like we are all set to do some programming! But which python do we use and how do we get our system to use it for our project?

This is where python environments come in handy. I will write more later on how I set up my environments. Basically, I activate the environment I want to use for the project I am working on. That environment already knows which python I want to use. And I start programming.

Share with Friends!
LinkedIn
Reddit
Hacker News