Using a Different Python Version on Linux
This note shows how to run an application with a different Python version without changing the system-wide Python installation. The example below uses Python 3.11 alongside a system default of Python 3.14.
Why this matters specifically for Informix work
Pure-Python packages usually just work on whatever interpreter you have —
worst case, pip resolves an older version. Informix®
connectivity from Python is different, because the packages involved
(pyodbc, IfxPy, and similar) are not pure Python:
they're C extensions built against a specific CPython ABI and linked
against the Informix CSDK's own client libraries. That's two independent
compatibility surfaces that both have to line up, not one.
IBM/HCL's Informix driver releases don't move on the same schedule as CPython.
Fedora and most distros ship a new default python3 roughly every
six to twelve months; a given pyodbc release, and the CSDK build
it was tested against, can lag well behind that. The practical result is
exactly the shape this note walks through: the newest system Python has no
compatible wheel for the pyodbc version your integration needs,
and waiting for upstream to catch up isn't a plan — you pin the
interpreter the extension actually builds against, per application, and leave
the system Python alone for everything else that depends on it.
This is also why it's a per-application problem, not a one-time
system decision: a host can easily run several things against the same
Informix instance — a monitoring script, a data-migration job, an
admin tool — each written and tested against a different
pyodbc/Python pairing over time. A venv per application keeps
each one on the interpreter it was actually verified against, without forcing
a single system-wide Python choice on all of them, and without a distro
upgrade silently breaking one that's been working fine for years.
Why use a virtual environment?
Some Python packages are not compatible with the newest Python release. For example:
- System Python: Python 3.14
- Required package:
pyodbc==4.0.39 pyodbc 4.0.39does not build against Python 3.14- Python 3.11 can be used specifically for the application that requires it
Using a virtual environment avoids changing /usr/bin/python3 or
affecting other applications on the server.
1. Check the current Python version
python3 --version
which python3
Example:
Python 3.14.7
/usr/bin/python3
2. Check whether the required Python version is installed
For Python 3.11:
which python3.11
python3.11 --version
If it is not installed on a Fedora/RHEL-family system:
sudo dnf install python3.11
Depending on the distribution, an additional venv package may also be required.
3. Create a virtual environment using that Python version
Example:
python3.11 -m venv /home/informix/venv-informix
This creates an isolated Python environment under:
/home/informix/venv-informix
The environment contains its own Python executable:
/home/informix/venv-informix/bin/python
4. Activate the virtual environment
source /home/informix/venv-informix/bin/activate
The shell prompt will normally change to show the environment name:
(venv-informix) zeus:[csdk]
5. Verify which Python is now active
which python
python --version
Expected:
/home/informix/venv-informix/bin/python
Python 3.11.x
Also check python3:
which python3
python3 --version
When the venv is active it should normally resolve to the virtual environment.
6. Install pip into the virtual environment if required
Some Python installations create a venv without pip. Check:
python -m pip --version
If this returns:
No module named pip
install pip into the venv:
python -m ensurepip --upgrade
Then:
python -m pip --version
Upgrade pip if desired:
python -m pip install --upgrade pip
Use:
python -m pip
rather than plain:
pip
until you have confirmed that pip resolves to the virtual environment.
7. Install packages into the selected Python environment
For the Informix/pyodbc compatibility test:
python -m pip install pyodbc==4.0.39
Verify:
python -c "import sys, pyodbc; print(sys.executable); print(sys.version); print(pyodbc.version)"
Example expected output:
/home/informix/venv-informix/bin/python
3.11.16 ...
4.0.39
This proves that:
- the correct Python interpreter is running
- the required package is installed in that environment
- the package version is correct
8. Run the application using the virtual environment
With the venv active:
python ./dbtest.py
If the script begins with:
#!/usr/bin/env python3
then this should also work while the venv is active:
./dbtest.py
because the virtual environment places its own python3 ahead of
/usr/bin/python3 in PATH. Verify this with:
which python3
9. Why #!/usr/bin/env python3 is useful
A script with #!/usr/bin/env python3 uses the first
python3 found in the current PATH.
Without a venv:
/usr/bin/python3
might be Python 3.14. With the Python 3.11 venv active:
/home/informix/venv-informix/bin/python3
is found first. This means the same script can use different Python versions depending on the activated environment.
10. Do not change the system Python
Avoid replacing:
/usr/bin/python
/usr/bin/python3
or changing the operating system's default Python symlinks. System tools may depend on the Python version shipped with the operating system. Use a virtual environment instead.
11. Deactivate the virtual environment
When finished:
deactivate
Then:
which python
python --version
will return to the normal system Python.
12. Reactivate it later
You do not need to recreate the environment. Simply run:
source /home/informix/venv-informix/bin/activate
Then:
python --version
should again show Python 3.11.
13. Optional environment file
For applications that also require Informix CSDK variables, an environment file can activate both the Informix environment and the Python venv. Example:
#!/bin/bash
export INFORMIXDIR=/home/informix/csdk
export INFORMIXSQLHOSTS=/home/informix/etc/sqlhosts
export LD_LIBRARY_PATH=$INFORMIXDIR/lib:$INFORMIXDIR/lib/esql:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/c++:$INFORMIXDIR/lib/dmi
export PATH=$INFORMIXDIR/bin:$PATH
source /home/informix/venv-informix/bin/activate
Save this as something such as:
dbtest.env
and load it with:
source ./dbtest.env
Then verify:
which python
python --version
python -c "import pyodbc; print(pyodbc.version)"
Quick Reference
Create the environment:
python3.11 -m venv /home/informix/venv-informix
Activate it:
source /home/informix/venv-informix/bin/activate
Install pip if missing:
python -m ensurepip --upgrade
Install the required package:
python -m pip install pyodbc==4.0.39
Verify:
python -c "import sys, pyodbc; print(sys.executable); print(sys.version); print(pyodbc.version)"
Run the application:
python ./dbtest.py
Leave the environment:
deactivate