Search code examples
pythonpython-3.xvpython

Exception: The non-notebook version of vpython requires Python 3.5 or later


I just bought a new computer so I decided to install python. I installed the last version which is 3.10. Afterwards I decided to installed all the libraries I ussually use. One of my main projects require using a library called "vpython". It was very difficult to reinstall everything, but I managed to do it. Once i tried importing the library, this error came up:

Exception: The non-notebook version of vpython requires Python 3.5 or later.
vpython does work on Python 2.7 and 3.4 in the Jupyter notebook environment.

In the error, it clearly sais it requires Python 3.5 or later which I think it also includes my current version 3.10. Do I need to unintasall Python 3.10 and install an older version? There is any way to solve this without reinstalling?

Also, im not using jupyter notebook.


Solution

  • This is caused by bad version checking by the creator/s of the package.

    import platform
    __p = platform.python_version()
    
    # Delete platform now that we are done with it
    del platform
    
    __ispython3 = (__p[0] == '3')
    __require_notebook = (not __ispython3) or (__p[2] < '5') # Python 2.7 or 3.4 require Jupyter notebook
    
    if __require_notebook and (not _isnotebook):
            s = "The non-notebook version of vpython requires Python 3.5 or later."
            s += "\nvpython does work on Python 2.7 and 3.4 in the Jupyter notebook environment."
            raise Exception(s)
    

    platform.python_version() in this case is "3.10" so __p[2] < '5' will be True and fail the version check.

    The relevant code can be found here.

    This should probably get a bug report if it doesn't have one already.

    Ideally the check would look something like this:

    import sys
    __p = sys.version_info
    
    # Delete sys now that we are done with it
    del sys
    
    __ispython3 = (__p.major == 3)
    __require_notebook = (not __ispython3) or (__p.minor < 5) # Python 2.7 or 3.4 require Jupyter notebook
    
    if __require_notebook and (not _isnotebook):
            s = "The non-notebook version of vpython requires Python 3.5 or later."
            s += "\nvpython does work on Python 2.7 and 3.4 in the Jupyter notebook environment."
            raise Exception(s)