Solving Python Ignoring Invalid Distribution

In the following article, we will cover Python ignoring invalid distribution. Why does it occur, and what is the way to resolve this warning. This is an obscure error. In other words, there is little chance to come across this warning. However, since you are here, that implies you have indeed come bumped into it. Don’t worry. This article covers it in detail and will try to resolve this error.

Why does Python ignoring invalid distribution occur?

Sometimes when you try to pip install a package, you may run across an error similar to this, for instance.

Warning: Ignoring invalid distribution
Warning: Ignoring invalid distribution

This happens because when pip updates or deletes a package, it renames the package name by replacing the first letter with a ‘ ~ ‘ or ’tilde,’ which is normal behavior. The problem here is that pip is renaming its own package (pip -> ~ip) without restoring it.

Whenever a pip update is executed, the default pip package is renamed to ~ip, and then a new pip package is installed following the removal of ~ip. So, if your update stops in between, it’ll leave the ~ip as it is.

This broken pip can be easily fixed or suppressed. But until you fix it, it’ll display the above error.

How to suppress ignoring invalid distribution warnings?

In order to suppress all the warnings, you can do the following. However, it is important to realize that suppressing the warnings doesn’t resolve the error. It merely hides the warning message.

pip --disable-pip-version-check install <module_name>

How to Resolve Python Ignoring Invalid Distribution Warning?

pip

It occurs due to multiple versions installation of libraries. At times conda or pip failed to uninstall the versions. Instead, it renames it to “~ip”.

Therefore it is recommended that you should find site-packages in the python installation (usually located in pythoninstallation/Lib/site-packages/) and search for “~ip” and delete such folders which begin with ~ip. After that, the problem of ignoring invalid distribution will get resolved, and you will not get any such warnings.

Ignoring invalid distribution on pip installing a library
Ignoring invalid distribution on pip installing a library

after deleting ~<package_name>

pip install successful, no warnings raised
pip install successful, no warnings raised

anaconda

Anaconda is an open-source package manager similar to pip. Moreover, the chances of warning python ignoring invalid distribution appearing in anaconda is very little as they use their own executable conda. This allows for stable and quicker installation with very few chances of errors popping up. If your site library does not have ~ip, there is no reason for this warning to pop up.

pycharm

Similarly, pycharm has a dedicated GUI for installing and uninstalling packages for a project. When a package doesn’t work as expected, simply remove it and reinstall it. Therefore it is unlikely that ignoring invalid distribution will occur in pycharm.

How to fix a broken pip?

Use the steps given below in order to fix a broken pip.

  • Download the following file and save it as get-pip.py
  • Open the command prompt.
  • Open the directory where the file get-pip.py has been saved.
  • Thereafter, run the get-pip.py as python get-pip.py. This will install the wheel and the pip.
  • Use pip –version to check whether it is installed correctly.

FAQs

How do I force reinstall PIP?

In order to force reinstall a pip package, you will need to do the following, for instance:
pip install pandas –no-cache-dir

Why should we not ignore Python ignoring invalid distribution warnings?

We should not ignore Python ignoring invalid distribution warnings because a few dependent packages might not be installed. Moreover, it could lead to more unwanted errors.

Conclusion

In the following article, we discussed why Python’s warning, i.e., ignoring invalid distribution, occurs and looked at a way to resolve the warning message. In modern IDEs like Pycharm and Anaconda, this error is highly unlikely to appear since these IDEs have their own package installation flow.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments