Python provides you with a package installer called ‘pip.’ ‘Pip’ allows you to write a line of code to install packages and manage them. Although sometimes, when you are installing some packages, you might get an ‘error: legacy-install-failure.’ For example, if you are trying to install the gensim package in python. To know more about ‘pip’ check out this post.
pip install gensim
Output:
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> gensim
In this article, we will discuss how we can solve this error.
Solve error: legacy-install-failure For Gensim
Pip is a package installer and manager, and the wheel is a way that pip prefers to install packages because the wheel allows fast and efficient installations and are smaller in comparison to eggs. Hence upgrading wheels might also solve the problem of ‘error: legacy-install-failure.’ The setuptools enhance the over-installation by enhancing the python standard library distribution utilities. Therefore if you update these modules, it might solve your error because this error can also arise if one of these modules is not up-to-date. Let us see how we can upgrade these modules.
- First, update your pip installer as shown below.
python - m pip install – upgrade pip
- Then upgrade your wheel by using:
pip install - upgrade wheel
- Then finally upgrade the setuptools.
pip install - upgrade setuptools
- And then again try to install the package which was throwing error in the first place.
Solve error: legacy-install-failure In Pandas
Pandas is an open-source library in python which allows users to perform high-level data manipulation. It is one of the most important libraries in python in the sense of data structure programming and data analysis because it provides flexible, fast and expressive data structures. However, sometimes when you try to install this library using pip, you can get an ‘error: legacy-install-failure,’ which can prevent us from using this very important library. Let us see how we can solve this error in python.
To solve this problem, you need to install ‘pipwin’ because it may happen that the ‘pandas’ wheel might not support the python version you are working on; therefore, first, install ‘pipwin’.
pip install pipwin
And further, when you install ‘pipwin,’ install ‘pandas’ using ‘pipwin.’
pipwin install pandas
This should probably solve the ‘error: legacy-install-failure’ and allow you to install the pandas library and use it.
Solve error: legacy-install-failure For Basemap
Basemap is a tool in python that provides you to create maps in a very easy and simple way. It is an extension of the ‘matplotlib‘ library; therefore, it contains all the features for carrying out data visualization. It further adds geographical projections and some other additional data sets in order to enable plotting coastlines, countries, states, boundaries and etc., directly from the library. Similarly, when you try to install this library through ‘pip,’ you might face a Solve ‘ error: legacy-install-failure’. We will discuss how we can solve this error for the basemap library.
Solving For Windows Operating System
If you are using Windows operating system and encounter this error you need to follow some steps. The steps are as given below:
- First, go this path https://www.lfd.uci.edu/~gohlke/pythonlibs/#basemap
- You will be directed to the file directory. If you’re using python 3.10.x, download the file named ‘basemap‑1.3.2‑cp310‑cp310‑win_amd64.whl‘
- Now go to this wheel file and run the following command:
pip install basemap‑1.3.2‑cp310‑cp310‑win_amd64.whl
Doing this should solve the ‘error: legacy-install-failure’ error.
Solving For MAC Operating System
If you are using MAC Operating System and encounter this error, you need to follow some steps. The steps are as given below:
- First, make sure you install all the packages as shown below:
brew install geos
brew install matplotlib
brew install numpy
brew install proj
- Then you have to add GEOS_DIR = “/ user / local / Cellar / geos / 3.10.2 /” to your .bash profile and reload it via: source ~/.bash_profile. You can do that by :
git clone --depth 1 https://github.com/matplotlib/basemap.git
- Further, go to the basemap directory from the path: basemap/packages/ basemap. And finally, run the install code from that directory.
pip3 install
This should solve the ‘error: legacy-install-failure’ error.
Solving For Google Colab
To solve this error in google colab, you need to run the commands given below, and doing that should solve the ‘error: legacy-install-failure’ error.
!sudo apt-get install libgeos-3.6.2
!sudo apt-get install libgeos-dev
!pip install git+https://github.com/matplotlib/basemap#subdirectory=packages/basemap
Solve error: legacy-install-failure For MySQL
MySQL provides services for handling and managing databases. When you connect your python application to an active server, you can manage all your database using MySQL. Although when installing using an ‘Error: legacy-install-failure’ error might occur. It can display something like this.
note: This error originates from a subprocess, and is likely not a problem with
pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> mysqlclient
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
To solve this following error, you will need to follow the steps given below:
- First, run the commands given below
xcode-select --install
brew install zstd
pip install pymysql
pip install wheel
CFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" pip install mysqlclient==<version>
- Further, make some changes in the settings file if you are using some framework like Django or any other. To make this change run these commands.
import pymysql
pymysql.install_as_MySQLdb()
Further, install all other dependencies in the env/lib/python3.8/site-packages/django/db/backends/mysql/base.py directory. These dependencies can be installed like:
pip install mysql-connector-python
pip install cryptography
- Now try to install MySQL again, as following these steps should solve the error.
Solve error: legacy-install-failure For Wxpython
Wxpython is a cross-platform Graphical User Interface toolkit for python language. It enables the users to program independent and robust code, which provides a very high graphical user interface very easily and quite simply. This library, like many other libraries, is open source. Although sometimes, while installing ‘wxPython,’ you might face an ‘error: legacy-install-failure’ error.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> wxPython
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
This error might occur because you might be using a python version that is not compatible with ‘wxPython.’ Therefore the easiest solution is to downgrade your python version to 3.9.13 because the last version of ‘wxPython’ came before python 3.10. There might be an alternative solution to this, but right now, this is the easiest solution.
Solve error: legacy-install-failure For Psycopg2-binary
To solve this error, you have to follow some steps. You can solve this problem by upgrading some packages.
pip uninstall psycopg2
pip list --outdated
pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2
This code will upgrade some outdated packages and might solve the problem.
Solve Error legacy-install-failure For Cffi
When you are programming on Django, you might get an error while installing libraries. You can solve this error by the following code.
RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
apk add --update alpine-sdk && \
apk add --update --no-cache postgresql-client && \
apk add --update --no-cache --virtual .tmp-build-deps \
build-base gcc python3-dev postgresql-dev musl-dev libffi-dev openssl-dev cargo && \
/py/bin/pip install -r /tmp/requirements.txt && \
if [ $DEV = "true" ]; \
then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp && \
apk del .tmp-build-deps && \
adduser \
--disabled-password \
--no-create-home \
django-user
Solve error: legacy-install-failure For Dlib
You can also get an error while installing the ‘dlib’ library through pip. To solve this error, try to install the library from scratch by following the steps.
- First, install ‘anaconda.’
- Further activate the virtual environment through a command prompt.
- Install ‘opencv’ using pip.
- Install ‘dlib’ using pip.
This will eventually solve your error.
Solve Error legacy-install-failure For Fbprophet
You can encounter an error while installing Facebook prophet using pip. This error occurs because you might not have installed dependencies for the wheel to be installed. You can solve this error by installing all the dependencies and then installing the ‘fbprophet’ using pip.
Solve error: legacy-install-failure For Horovod
When you are trying to install ‘horvord’ with ‘PyTorch,’ you might encounter an error of sort ‘error: legacy-install-failure’.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> horovod
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
This error occurs because an older version of ‘horovord’ than 0.24.0 is not compatible with PyTorch. Therefore you can solve this error by upgrading ‘horovord’ to newer versions.
FAQs on Error: legacy-install-failure
There are many ways you can solve this error, and we have discussed some of them in this article. You can follow those solutions to solve this error depending upon the library you want to install.
You can upgrade setuptool with pip using the following command:pip install - upgrade setuptools
You can pip install pandas from PyPI.
Conclusion
Finally conclude, we can say that we have discussed various methods in this article to solve the ‘error: legacy-install-failure’ error which occurs for different libraries and modules. You can use any of the methods according to your requirements and according to the library or modules, you want to install for your program.