What is the simplest way to install an older version of Python?

Module

Name of that module?

You have to ensure that pyenv is first in the path before the actual python, this is common across different OSs. If not python command will always detect the system python. I faced this issue 3 weeks ago on windows too.

It really only needs to insert itself into your path so it knows where to find its files. For switching to a particular version of python with pyenv, you would use pyenv shell python_version.

Here’s an example from my machine:

$ pyenv versions
* system (set by /home/ajgringo619/.pyenv/version)
  3.6.15
  3.10.12
  3.11.2
  3.11.11
  3.12.3
  3.12.8
  3.13.1
┌╼ [ajgringo619@eos-host]╾╼[/media/host/shared-files/nixos]╾╼[15:11:21]
└─╼ $ pyenv shell 3.10.12
┌╼ [ajgringo619@eos-host]╾╼[/media/host/shared-files/nixos]╾╼[15:11:29]
└─╼ $ python3 --version
Python 3.10.12

To revert back to the default version of python, run pyenv shell --unset. Now, if pyenv is not in your path, then there’s your issue in a nutshell. At a minimum, your PATH should have added /home/username/.pyenv/bin:/home/username/.pyenv/shims.

And @ajgringo619

Thanks both. That’s reassuring. Late now. I’ll try it out in the morning.

## Install correct version to ~/.pyenv
pyenv install 3.11.11

## Setup venv with correct version:
virtualenv -p ~/.pyenv/versions/3.11.11/bin/python3.11 venv

## Change directory into venv:
cd venv/

## Activate it:
. bin/activate

# if using Fish:
. bin/activate.fish

## Install something needed by my script:
pip install pysimplegui

## Copy my script in:
cp ~/scripts/pysimplegui/variety/v.py .
## Then:
deactivate

To run the script:
~/pyenv/venv/bin/python3.11 ~/pyenv/venv/v.py

I added a print(sys.version) to my script to print the running version.

:Edit: Typo and added fish to the instructions.

2 Likes

Perhaps I’m misunderstanding the context, but wouldn’t simply typing python at a terminal already provide you with the version in conjunction with the interactive prompt?

1 Like

Thank you so much for this. It’s working (the environment, that is).
I now have

(venv) [me ~]$ python --version
Python 3.11.11

No to see if the actual module will install… but that’s another matter altogether

Probably would, it was late :smiley:

Had some coffee :smiley: I added it so that when I ran it with the venv deactivated it proved (to me!) I was running under the correct version.

The script is just a button bar to control variety wallpaper changer.

## venv not running:
~/pye/venv ❱ ./v.py                                                                                                          10:17:32
3.13.1 (main, Dec  4 2024, 18:05:56) [GCC 14.2.1 20240910]

## venv activated:
~/pye/venv 9.8s ❱ . bin/activate.fish                                                                                        10:17:47

## venv still activated:
(venv) ~/pye/venv ❱ ./v.py                                                                                                   10:17:57
3.11.11 (main, Jan 25 2025, 22:57:05) [GCC 14.2.1 20240910]

## Deactivate venv:
(venv) ~/pye/venv 3.7s ❱ deactivate                                                                                          

## Run script with paths specified and no venv:
~/pye/venv ❱ cd ~                                                                                                            

~ ❱ ~/pyenv/venv/bin/python3.11 ~/pyenv/venv/v.py                                                                            
3.11.11 (main, Jan 25 2025, 22:57:05) [GCC 14.2.1 20240910]

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.