Programming these days has become far easier thanks to the number of different libraries and tools available to us. However, as simple as its supposed to be, there are still random bugs and errors that might hinder your progress.
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.
Why does this happen?
The error usually gets triggered when you try to install the gensim Python package. The error itself is most likely generated from a subprocess and is not a problem with Pip itself.
How to fix this?
Here are three fixes you can try out.
Update Pip and its dependencies
The first thing you should do in such situations is to update Pip, wheel and setuptools. Just enter the following commands one after another.
python -m pip install –upgrade pip pip install –upgrade wheel pip install –upgrade setuptools
Once you’re done updating everything, try to install the package again using either of the following commands.
pip install gensim
pip3 install gensim
Download Microsoft C++ build tools
Another solution to the problem, one that the error message itself will likely suggest is to download and install Microsoft C++ build tools. The download process is rather simple as well, just head over to this website and download the desktop environment with C++. Once the download is complete, run the installer and your error should be resolved.
Alternatively, you can use the following command in the Command Prompt.
vs_buildtools.exe --norestart --passive --downloadThenInstall --includeRecommended --add Microsoft.VisualStudio.Workload.NativeDesktop --add Microsoft.VisualStudio.Workload.VCTools --add Microsoft.VisualStudio.Workload.MSBuildTools
Once installation is complete, run the aforementioned command to install the gensim package again.
Using unofficial Windows Binaries
Although we don’t recommend downloading binaries or system files from third-party sources, this might be the last resort if you absolutely have to use gensim.
If you’re running Windows 10 or 11 (x64) and have Python 3.10 or above, you need to visit this link and download the gensim‑4.1.2‑cp310‑cp310‑win_amd64.whl file. Once downloaded, install the file with pip using the following command.
pip install [path to wheel file]
The problem should be gone now.
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.