Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 to the dependencies. So in order to run my scripts, I use python3.8 app.py. No problem so far. But when I want to install new packages via pip:

python3.8 -m pip install pylint

It throws an error:

AttributeError: module 'platform' has no attribute 'linux_distribution'

So far, I tried:

sudo update-alternatives --config python3

and chose python3.8 and run command by starting with python3 but no luck.

Then:

sudo ln -sf /usr/bin/python3.5 /usr/bin/python3

I also tried running the command by starting with python3 but it did not work either.

How can I fix it so that I can install new packages to my new version of Python?

like image 976
EmreAkkoc Avatar asked Nov 07 '19 23:11

EmreAkkoc


3 Answers

It looks like at least on my Ubuntu 16.04, pip is shared for all Python versions in /usr/lib/python3/dist-packages/pip.

This is what I did to get it working again:

  • sudo apt remove python3-pip
  • sudo python3.8 -m easy_install pip

You might want to install the python 3.5 version of pip again with sudo python3.5 -m easy_install pip.

like image 82
Dave Halter Avatar answered Nov 19 '22 15:11

Dave Halter


Python 3.8 removed some stuff. I solved my problems with pip (specifically pip install) by installing pip with curl

What worked for me was:
cd ~/Downloads
Downloading get-pip.py
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Then running it with python 3.8:
python3.8 get-pip.py

Solved it for me.

Source: https://pip.pypa.io/en/stable/installing/

like image 38
Gur Telem Avatar answered Nov 19 '22 15:11

Gur Telem


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]
like image 13
Mark Puddephat Avatar answered Nov 19 '22 17:11

Mark Puddephat