最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Install an old python (3.9) in a pipenv with non LTS Ubuntu - Stack Overflow

programmeradmin1浏览0评论

In order to use a scientific camera, I need to use an old python module that require python 3.9.
I use a PC with the last Ubuntu 24.10 (that comes with python3.12)
I thought a quick pipenv with python 3.9 would do the trick.
It doesn't seem to be straightforward though...

Compile python3.9 from the source

Since it has become impossible to install old version of python via apt install.
Even using the deadsnake ppa (add-apt-repository ppa:deadsnakes/ppa) doesnt work for non LTS Ubuntu... ()

If one wants to install an old python it has therefor to be from the source... (got the idea from )

1/ Install dependancies:

$ sudo apt install -y build-essential libssl-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libffi-dev zlib1g-dev

2/ Download and extract the last python 3.9

$ sudo wget .9.21/Python-3.9.21.tgz
$ sudo tar -xvf Python-3.9.21.tgz

3/ Compile and install:

$ cd Python-3.9.21
$ sudo ./configure --enable-optimizations
$ sudo make altinstall`

It instals in /usr/local/bin :

$ ls -la /usr/local/bin
total 15684
drwxr-xr-x  2 root root     4096 Mar 13 14:09 .
drwxr-xr-x 11 root root     4096 Oct  7 21:03 ..
-rwxr-xr-x  1 root root      101 Mar 13 14:09 2to3-3.9
-rwxr-xr-x  1 root root       99 Mar 13 14:09 idle3.9
-rwxr-xr-x  1 root root      229 Mar 13 14:09 pip3.9
-rwxr-xr-x  1 root root       84 Mar 13 14:09 pydoc3.9
-rwxr-xr-x  1 root root 16029664 Mar 13 14:08 python3.9
-rwxr-xr-x  1 root root     3053 Mar 13 14:09 python3.9-config

I have now two version of python installed!

$ python3 --version
Python 3.12.7

$ python3.9 --version
Python 3.9.21

I create my pipenv:

$ pipenv install --python '/usr/local/bin/python3.9'

Creating a Pipfile for this project...
Pipfile.lock not found, creating...
Locking [packages] dependencies...
Locking [dev-packages] dependencies...
Updated Pipfile.lock (702ad05de9bc9de99a4807c8dde1686f31e0041d7b5f6f6b74861195a52110f5)!
Installing dependencies from Pipfile.lock (2110f5)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

BUT:

$ pipenv run python --version
Python 3.12.7

instead of python 3.9.21 :'-(

What am I doing wrong??

NB: I also tryed

$ pipenv install --python3.9

but got a error message. Not sure why, not sure what it means...

the answer actually came in the comments. there was a space issue >< The correct command is:

$ pipenv install --python 3.9

then:

$ pipenv run python --version
Python 3.9.21

$ python3 --version
Python 3.12.7
$ python3.9 --version
Python 3.9.21

In order to use a scientific camera, I need to use an old python module that require python 3.9.
I use a PC with the last Ubuntu 24.10 (that comes with python3.12)
I thought a quick pipenv with python 3.9 would do the trick.
It doesn't seem to be straightforward though...

Compile python3.9 from the source

Since it has become impossible to install old version of python via apt install.
Even using the deadsnake ppa (add-apt-repository ppa:deadsnakes/ppa) doesnt work for non LTS Ubuntu... (https://github/deadsnakes/issues/issues/249)

If one wants to install an old python it has therefor to be from the source... (got the idea from https://askubuntu/questions/1539019/how-to-install-python-3-10-on-ubuntu-24-10)

1/ Install dependancies:

$ sudo apt install -y build-essential libssl-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libffi-dev zlib1g-dev

2/ Download and extract the last python 3.9

$ sudo wget https://www.python./ftp/python/3.9.21/Python-3.9.21.tgz
$ sudo tar -xvf Python-3.9.21.tgz

3/ Compile and install:

$ cd Python-3.9.21
$ sudo ./configure --enable-optimizations
$ sudo make altinstall`

It instals in /usr/local/bin :

$ ls -la /usr/local/bin
total 15684
drwxr-xr-x  2 root root     4096 Mar 13 14:09 .
drwxr-xr-x 11 root root     4096 Oct  7 21:03 ..
-rwxr-xr-x  1 root root      101 Mar 13 14:09 2to3-3.9
-rwxr-xr-x  1 root root       99 Mar 13 14:09 idle3.9
-rwxr-xr-x  1 root root      229 Mar 13 14:09 pip3.9
-rwxr-xr-x  1 root root       84 Mar 13 14:09 pydoc3.9
-rwxr-xr-x  1 root root 16029664 Mar 13 14:08 python3.9
-rwxr-xr-x  1 root root     3053 Mar 13 14:09 python3.9-config

I have now two version of python installed!

$ python3 --version
Python 3.12.7

$ python3.9 --version
Python 3.9.21

I create my pipenv:

$ pipenv install --python '/usr/local/bin/python3.9'

Creating a Pipfile for this project...
Pipfile.lock not found, creating...
Locking [packages] dependencies...
Locking [dev-packages] dependencies...
Updated Pipfile.lock (702ad05de9bc9de99a4807c8dde1686f31e0041d7b5f6f6b74861195a52110f5)!
Installing dependencies from Pipfile.lock (2110f5)...
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

BUT:

$ pipenv run python --version
Python 3.12.7

instead of python 3.9.21 :'-(

What am I doing wrong??

NB: I also tryed

$ pipenv install --python3.9

but got a error message. Not sure why, not sure what it means...

the answer actually came in the comments. there was a space issue >< The correct command is:

$ pipenv install --python 3.9

then:

$ pipenv run python --version
Python 3.9.21

$ python3 --version
Python 3.12.7
$ python3.9 --version
Python 3.9.21
Share Improve this question edited Mar 13 at 21:44 Mejdi asked Mar 13 at 18:01 MejdiMejdi 111 silver badge4 bronze badges 12
  • 2 What prevents you from explicitely calling the 3.9 version: python3.9 -m your_module, or python3.9 your_script.py? – Serge Ballesta Commented Mar 13 at 18:12
  • 1 Generally speaking, I'd suggest looking into why this module requires Python 3.9. If it uses syntax that's deprecated in later releases, that's generally easy to fix. If it depends on binaries that are only precompiled for 3.9, you can generally compile them yourself for a later interpreter as long as source is available. Instead of taking the lack of support for anything later than 3.9 as a given, you'll put yourself in a better place for the future if you treat that as a problem that a little effort can generally solve. – Charles Duffy Commented Mar 13 at 18:25
  • Once the python virtual environment is setup, the plan is to install (pip install) modules that where written many many years ago by a company that sold a camera to a university many years ago. – Mejdi Commented Mar 13 at 18:31
  • How about using a docker image instead? hub.docker/_/python – LMC Commented Mar 13 at 18:33
  • 2 Have you tried pipenv install --python 3.9? NB. Note the space. That's how the usage example on pypi./project/pipenv/#usage is given. Worked fine for me where I have local install of python3.13 installed. – Dunes Commented Mar 13 at 18:48
 |  Show 7 more comments

2 Answers 2

Reset to default 1

I commonly use various Python versions on my box. I just rely from the good old venv from the standard library:

cd path_to_your_project
python3.9 -m venv venv        # creates a virtual environment based on python3.9
. venv/bin/activate           # activates that environment

From that point, python will be the 3.9 version, and pip will install packages in the virtual environment.

If you don't mind using uv instead of pipenv, then the following steps might work for you.

Install uv

Issue a single command to install uv

curl -LsSf https://astral.sh/uv/install.sh | sh

Reference: https://docs.astral.sh/uv/getting-started/installation/

Install Python 3.9

uv python install 3.12

Reference: https://docs.astral.sh/uv/guides/install-python/#getting-started

Run Script

uv run --python 3.9 myscript.py

Reference: https://docs.astral.sh/uv/guides/scripts/

发布评论

评论列表(0)

  1. 暂无评论