Python

Python

Python

 View Only
Expand all | Collapse all

venvs break after python 3.10 upgrade

  • 1.  venvs break after python 3.10 upgrade

    Posted Thu December 29, 2022 01:48 PM
    Hello!  
    I recently upgraded python in our zOS environment from 3.8 to 3.10.  I use the pax version.  

    After install, any existing python venvs created in 3.8 no longer work.  The packages appear to be missing, or uninstalled, although I think what really is happening is that the sys.path variable does not contain the path to the site-packages directory.  If I back out to python 3.8 it works fine. No intervention needed. 

    After upgrading to 3.10, if I try to run code in the venv,  I get messages that modules are no longer found, including pip:
    (env6) @ITE1:/home/grahaj7/env6:$pip list
    Traceback (most recent call last):
      File "/home/grahaj7/env6/bin/pip", line 5, in <module>
        from pip._internal.cli.main import main
    ModuleNotFoundError: No module named 'pip'

    The value of sys.path in a non-working venv looks like this:

    env6) @ITE1:/home/grahaj7/env6:$python

    Python 3.10.7 (heads/pyz_dev-3.10:6206341958, Oct 20 2022, 15:46:55) [Clang 4.0.1 (tags/RELEASE_401/final)] on zos

    Type "help", "copyright", "credits" or "license" for more information.

    >>> import sys

    >>> print(sys.path)

    ['', '/usr/lpp/IBM/cyp/v3r10/pyz/lib/python310.zip', '/usr/lpp/IBM/cyp/v3r10/pyz/lib/python3.10', '/usr/lpp/IBM/cyp/v3r10/pyz/lib/python3.10/lib-dynload']

    >>>


    In a working venv it looks like this:
    (env3) @ITE1:/home/grahaj7/env3:$python
    Python 3.10.7 (heads/pyz_dev-3.10:6206341958, Oct 20 2022, 15:46:55) [Clang 4.0.1 (tags/RELEASE_401/final)] on zos
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import sys
    >>> print(sys.path)
    ['', '/usr/lpp/IBM/cyp/v3r10/pyz/lib/python310.zip', '/usr/lpp/IBM/cyp/v3r10/pyz/lib/python3.10', '/usr/lpp/IBM/cyp/v3r10/pyz/lib/python3.10/lib-dynload', '/home/grahaj7/env3/lib/python3.10/site-packages']

    In a working venv, the lib/python3.10/site-packages directory is present. So of course the modules are found.  I'm guessing that since the directory isn't present initially python can't find it and so doesn't add it to sys.path....


    The way I have found to fix this problem is to reinstall pip in the venv.  Once pip is re-installed the sys.path variable has the needed path. I this is because the install of pip creates the new lib/python3.10/site-packages directory, which wasn't there before.   Once pip is back then I use the requirements.txt file to reinstall all the packages and it's all back to normal. 


    This is not difficult but my fear is that I don't have knowledge of all the venvs (eg. that others have created) in order to find and update.  If there are many then adds in a lot of manual intervention potentially.  Has anyone else run into this? Is it preventable?

    Thanks!


    ------------------------------
    Jennifer Graham
    ------------------------------


  • 2.  RE: venvs break after python 3.10 upgrade

    Posted Tue January 03, 2023 10:43 AM
    Hi Jennifer,

    In general, venv's are not compatible between major Python releases (3.8, 3.9, 3.10, 3.11). We recommend not attempting to reuse a venv created from a different release, but to create a new one and reinstall any packages into that.

    Regards,

    ------------------------------
    Steven Pitman
    ------------------------------