Mac下如何通过命令行将chromedriver放入系统PATH路径?
Got it, let's fix this quickly! The issue is that your system can't find chromedriver when Selenium runs because it's not in a directory included in your system's PATH. Below are step-by-step command line solutions for different operating systems to move chromedriver to a valid PATH directory:
Windows
- First, open Command Prompt or PowerShell as Administrator (right-click the app and select "Run as administrator" to avoid permission errors).
- Replace
YourUsernamewith your actual Windows username in the command below, then run it:
For example, if your username is "Alice", the command becomes:copy "C:\Users\YourUsername\Downloads\chromedriver.exe" "C:\Windows\System32\"copy "C:\Users\Alice\Downloads\chromedriver.exe" "C:\Windows\System32\" - Close and reopen your Python terminal/IDE, then run your script again—Selenium should now locate
chromedriverautomatically.
macOS
- Launch the Terminal app.
- First, ensure the target directory exists (it usually does, but just in case):
sudo mkdir -p /usr/local/bin - Copy
chromedriverto the directory that's in your system PATH:sudo cp ~/Downloads/chromedriver /usr/local/bin/ - Grant executable permissions to the file (this ensures it runs properly):
sudo chmod +x /usr/local/bin/chromedriver - Refresh your PATH settings or restart the Terminal, then test your Python script. To refresh PATH immediately, run:
(If you use Bash instead of Zsh, runsource ~/.zshrcsource ~/.bash_profile.)
Linux
- Open your Terminal.
- Copy
chromedriverto a standard PATH directory like/usr/local/bin:sudo cp ~/Downloads/chromedriver /usr/local/bin/ - Add executable permissions to the file:
sudo chmod +x /usr/local/bin/chromedriver - Restart the Terminal or refresh your PATH, then run your Python code again.
内容的提问来源于stack exchange,提问作者The Walrus
相关产品推荐
相关产品推荐

