11

Originally, my app crashed with error ERROR: Failed building wheel for pycairo (in the picture)

Failed to build pycairo

I tried to fix it by running several commands

  • sudo apt install libcairo2-dev
  • sudo apt install cloud-init

Gave the same error. No fix.

then I tried uninstalling the requirements.txt and reinstalled

  • pip uninstall -r requirements.txt
  • pip install -r requirements.txt

Did not solve the issue.

then I tried the below command, but I still got the same error "Failed building wheel for pycairo":

then I tried this command:

  • pip install --upgrade pip setuptools wheel

and I got this error in the picture: "Invalid version: '0.23ubuntu1'"

Invalid version: '0.23ubuntu1'

I tried to also delete this package but it's showing that package not found:

command I used: sudo apt-get remove distro-info

Error:

Reading package lists... Done

Building dependency tree

Reading state information... Done

Package 'distro-info' is not installed, so not removed

0 upgraded, 0 newly installed, 0 to remove and 283 not upgraded.

I searched for solutions but did not find any regarding the error "Invalid version: '0.23ubuntu1'". Now, when I run "flask run", I get error: -bash: /home/ktai/.local/bin/flask: No such file or directory

Would appreciate any help!

I tried several command lines but nothing worked

Ktai
  • 141
  • 1
  • 1
  • 6
  • Many problems can be solved by searching for the error message. In this case, a search for "Could not build wheels for pycairo" turns up https://stackoverflow.com/questions/70508775/error-could-not-build-wheels-for-pycairo-which-is-required-to-install-pyprojec , which appears to address your problem. – Dave W. Smith Jan 29 '23 at 05:29

6 Answers6

12

I learned from this answer that there is a "bug" with versions of setuptools causing this specific Invalid version: '0.23ubuntu1' error.

Despite seeing errors with all sorts of pip commands including pip install, I was surprised to see that this downgrade command (from the answer linked) appears to resolve the issue:

pip install --upgrade --user setuptools==58.3.0
sean
  • 367
  • 2
  • 12
5

This error arises from PEP 440 (Python Enhancement Proposal #440), which enforces conventions for naming of Python packages, and this error seems to really only happen on Debian-based distros like Ubuntu. For example, I have been trying to install a package via pip and get an error:

pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: '1.1build1' (package: distro-info)

So it's telling us that 1.1build1 is an invalid version name per PEP 440, and it's probably getting the distro-info package from, in my case, Ubuntu (came preinstalled).

I can get around this by using a Python virtual environment and not allowing it to use system-site-packages, sometimes called "global packages".

The solution is to remove the offending package and reinstall a version of it that meets PEP 440 requirements (e.g. following the "0.0.0" convention. "1.2.0" for example is fine, "1.2build3" is not).

pip uninstall -y distro-info
pip install distro-info==1.0

Additionally, within PyCharm, I can navigate to the Python Interpreter settings, choose the interpreter I am using from the Python Interpreter dropdown, and confirm that the version of distro-info it's trying to use is 1.1build1. To "upgrade" this to 1.0, I can double-click on the "1.0" under the "Latest Version" column and select "Install Package" from the modal that pops up.

If this or the above command to remove distro-info isn't working, you can use this same window to remove distro-info and then simply run pip install distro-info==1.0.

PyCharm's "Python Interpreter" settings

jspinella
  • 2,013
  • 3
  • 25
  • 39
  • Coming here from the [basic Docker-Python tutorial](https://docs.docker.com/language/python/build-images/). In typical Python fashion, the `docker build` was failing when `distro-info` in the `requirement.txt` violated this compliance rule, unjustifiably preventing installation. Changing the txt entry to `distro-info==1.0` allowed the `docker build` to go a bit forward (it still continued to fail due to other messy errors). The joys of working with Python. – alelom Apr 20 '23 at 08:25
  • 1
    This worked for me. Thanks. But no need to unintsall. I simply did `python3 -m pip install --upgrade distro-info` – Daniel Goldfarb Aug 13 '23 at 23:49
3

Are you using ubuntu 20.04 by chance? I had a similar issue but it had to do nothing with pycairo so the situation might be different for you. The existence of distro-info (with a version not compliant to PEP-440) among my Python packages was leading to the error message from your post's title whenever i tried to install another package.

For me, this one helped: (so you were close with the apt-get remove...)

python3 -m pip uninstall -y distro-info

In my case, it seems like it didnt break anything important so i will keep it like this. But there is no guarantee the same works for you as well. Also, you might get it back the next time you install packages from your requirements.txt file.

If I understood this thread correctly, there might be updates with a compliant version of this package depending on which Ubuntu version you are using.

3

For me the issue was being caused by the distro-info Python package having been installed via APT rather than by pip. Even after manually upgrading distro-info and playing around with the different versions of setuptools in other answers it kept reoccuring.

This solved my problem (on Ubuntu 20.04):

sudo apt remove python3-distro-info
samuelwcm
  • 86
  • 6
2

Thank you for all the answers. To answer my own question, I was finally able to fix the issue by updating all the required packages.

Now there are no updates needed, and the app works again.

0 updates can be applied immediately.

The list of available updates is more than a week old.
To check for new updates run: sudo apt update
mingaleg
  • 2,017
  • 16
  • 28
Ktai
  • 141
  • 1
  • 1
  • 6
2

For me doing what sean said broke my pip install, but upgrading setuptools to the current version (which is setuptools-67.6.0, as of answering) fixed my issue.

Delerowen
  • 21
  • 2