Linux环境Python2.7.14+执行python setup.py遇selenium安装错误求解决
That error pops up because Selenium stopped supporting Python 2.7 starting with version 4.x. Since Python 2.7 reached its end-of-life in 2020, almost all modern packages (including Selenium) no longer maintain compatibility with it. Here are your two main options to resolve this:
Solution 1: Upgrade to Python 3 (Highly Recommended)
Sticking with Python 2.7 means missing out on security patches, new features, and support for most modern libraries. Upgrading to Python 3 is the best long-term fix. Here's how to do it on Linux:
- Install Python 3 and its package manager using your distribution's tools:
- For Debian/Ubuntu-based systems:
sudo apt update && sudo apt install python3 python3-pip - For RHEL/CentOS/Fedora:
sudo dnf install python3 python3-pip
- For Debian/Ubuntu-based systems:
- Once installed, use
pip3to install the latest Selenium:pip3 install selenium
Solution 2: Install an Older Selenium Version (If You Must Stay on Python 2.7)
If upgrading isn't an option right now, you can install the last Selenium version that supports Python 2.7: 3.141.0. Here's how:
- First, make sure you're using Python 2's pip (often called
pip2):- Check if
pip2is available:pip2 --version - If not, install it:
- Debian/Ubuntu:
sudo apt install python-pip - RHEL/CentOS/Fedora:
sudo dnf install python2-pip
- Debian/Ubuntu:
- Check if
- Install the compatible Selenium version:
pip2 install selenium==3.141.0
Keep in mind that Selenium 3.x won't get any security updates or new features anymore, so upgrading to Python 3 should be your priority whenever possible.
Content of the question originates from Stack Exchange, question author ValentinaPink

