我正在尝试使用 pip 安装适用于 python 的 Selenium 包,但在“获取构建轮子的要求”时不断收到此错误。
PS C:\Users\Oisin\repositories\Scraper> python .\scrapeData.py
Traceback (most recent call last):
File "C:\Users\Oisin\repositories\Scraper\scrapeData.py", line 7, in <module>
from selenium import webdriver
ModuleNotFoundError: No module named 'selenium'
PS C:\Users\Oisin\repositories\Scraper> python -m pip install selenium
Collecting selenium
Using cached selenium-4.21.0-py3-none-any.whl.metadata (6.9 kB)
Requirement already satisfied: urllib3<3,>=1.26 in c:\msys64\mingw64\lib\python3.10\site-packages (from urllib3[socks]<3,>=1.26->selenium) (2.2.1)
Collecting trio~=0.17 (from selenium)
Using cached trio-0.25.1-py3-none-any.whl.metadata (8.7 kB)
Collecting trio-websocket~=0.9 (from selenium)
Using cached trio_websocket-0.11.1-py3-none-any.whl.metadata (4.7 kB)
Requirement already satisfied: certifi>=2021.10.8 in c:\msys64\mingw64\lib\python3.10\site-packages (from selenium) (2024.2.2)
Collecting typing_extensions>=4.9.0 (from selenium)
Using cached typing_extensions-4.11.0-py3-none-any.whl.metadata (3.0 kB)
Collecting attrs>=23.2.0 (from trio~=0.17->selenium)
Using cached attrs-23.2.0-py3-none-any.whl.metadata (9.5 kB)
Collecting sortedcontainers (from trio~=0.17->selenium)
Using cached sortedcontainers-2.4.0-py2.py3-none-any.whl.metadata (10 kB)
Requirement already satisfied: idna in c:\msys64\mingw64\lib\python3.10\site-packages (from trio~=0.17->selenium) (3.7)
Collecting outcome (from trio~=0.17->selenium)
Using cached outcome-1.3.0.post0-py2.py3-none-any.whl.metadata (2.6 kB)
Collecting sniffio>=1.3.0 (from trio~=0.17->selenium)
Using cached sniffio-1.3.1-py3-none-any.whl.metadata (3.9 kB)
Collecting cffi>=1.14 (from trio~=0.17->selenium)
Using cached cffi-1.16.0.tar.gz (512 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [24 lines of output]
Traceback (most recent call last):
File "C:\msys64\mingw64\lib\python3.10\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
main()
File "C:\msys64\mingw64\lib\python3.10\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\msys64\mingw64\lib\python3.10\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\build_meta.py", line 325, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\build_meta.py", line 295, in _get_build_requires
self.run_setup()
File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\build_meta.py", line 311, in run_setup
exec(code, locals())
File "<string>", line 126, in <module>
File "<string>", line 105, in uses_msvc
File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\_distutils\command\config.py", line 220, in try_compile
self._compile(body, headers, include_dirs, lang)
File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\_distutils\command\config.py", line 132, in _compile
self.compiler.compile([src], include_dirs=include_dirs)
File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\_distutils\_msvccompiler.py", line 343, in compile
self.initialize()
File "C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\overlay\lib\python3.10\site-packages\setuptools\_distutils\_msvccompiler.py", line 246, in initialize
raise DistutilsPlatformError(
distutils.errors.DistutilsPlatformError: --plat-name must be one of ('win32', 'win-amd64', 'win-arm32', 'win-arm64')
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
PS C:\Users\Oisin\repositories\Scraper>
我尝试查看这个目录
C:\Users\Oisin\AppData\Local\Temp\pip-build-env-f8yun7ic\
,但它不存在,唯一类似的目录是pip-uninstall-tk4rop8y
我尝试了各种类似的命令,而不是
python -m pip install selenium
,我做了pip install selenium
/ python3 -m pip install selenium
/ pip3 install selenium
等。所有结果都相同。
尝试更新pip无济于事
python.exe -m pip install --upgrade pip
。
python --version
Python 3.10.11
python -m pip --version
pip 24.0 from C:\msys64\mingw64\lib\python3.10\site-packages\pip (python 3.10)
除了重新安装 python 和 pip 之外,不知道该去哪里......
似乎与版本有关的问题。我建议您为您的项目创建一个单独的 pyhon 环境,以避免这些不兼容问题。
我想你是 Windows 11,所以打开 git bash 并执行以下命令来创建一个新的环境并激活它
conda create -n myproject python=3.11
conda activate myenv
pip install selenium
然后打开 anaconda navigator,选择这个新环境,并启动笔记本。现在应该可以了。