When working with Python and using the pip install command to add packages, you might come across the “error: legacy-install-failure.” This error often arises because the package you're trying to install isn't compatible with your Python version.
What is the “error: legacy-install-failure” error?
Common reasons for this error include outdated build tools, package name changes, missing developer tools on macOS, or the absence of Microsoft C++ Build Tools on Windows.
How to fix Python's “error: legacy-install-failure”
To resolve this issue, consider these steps:
- Upgrade pip and other build tools: Ensure your pip, setup tools, and wheel packages are up-to-date with these commands:
pip install –upgrade pip
pip install –upgrade setuptools wheel - Check for package renaming: Sometimes, the package you want to install might have a new name. Check the error output for hints about the new name, and use it in the pip install command if necessary.
- For macOS users: Make sure you have an active developer path by installing Xcode Command Line Tools:
xcode-select –install - For Windows users: Install Microsoft C++ Build Tools if you encounter a “Microsoft Visual C++ 14.0 or greater is required” error. Follow these steps:
- Download the appropriate version from the Microsoft Visual Studio website.
- Install the build tools, selecting the Python development workload during installation.
- If you have Visual Studio installed, activate the Python development workload from the “Tools > Get Tools and Features” menu.
- Check for a wheel distribution: If the previous solutions don't work, download the wheel distribution of the package from pypi.org. Follow these steps:
- Go to the package's page.
- In the “Files” section, find the suitable wheel distribution for your operating system.
- Download the .whl file.
- Navigate to the directory with the wheel file and run:
pip install package-name.whl
Replace “package-name” with the actual package name.
In conclusion, the “error: legacy-install-failure” error in Python often results from compatibility issues. By following these steps, you should be able to resolve the error and successfully install your desired package. Happy coding!