How to fix “module 'platform' has no attribute 'linux_distribution'” when installing new packages with Python3.8?

前端 未结 5 1075
再見小時候
再見小時候 2020-12-10 11:28

I had Python versions of 2.7 and 3.5. I wanted the install a newer version of Python which is python 3.8. I am using Ubuntu 16.04 and I can not just uninstall Python 3.5 due

5条回答
  •  一生所求
    2020-12-10 11:51

    The problem is that package.linux_distribution was deprecated starting with Python 3.5(?). and removed altogether for Python 3.8.

    Use the distro package instead. This package only works on Linux however.

    I ran into this problem after installing OpenCobolIDE on Linux Mint 20, having upgraded Python to the latest level. have submitted a code fix to the OpenCobolIDE author to review and test. I was able to get the IDE to start up and run with this fix.

    Essentially the fix uses the distro package if available, otherwise it uses the old platform package. For example:

    This code imports distro if available:

    import platform
    using_distro = False
    try:
        import distro
        using_distro = True
    except ImportError:
        pass
    

    Then you can test the value of using_distro to determine whether to get the linux distro type from package or distro, for example:

    if using_distro:
        linux_distro = distro.like()
    else:
        linux_distro = platform.linux_distribution()[0]
    

提交回复
热议问题