如何修复“由于 EnvironmentError 无法安装软件包:[WinError 123]”?

Posted

技术标签:

【中文标题】如何修复“由于 EnvironmentError 无法安装软件包:[WinError 123]”?【英文标题】:How to fix "Could not install packages due to an EnvironmentError: [WinError 123]"? 【发布时间】:2020-05-16 03:18:38 【问题描述】:

我正在尝试使用 python 3.8 下载一些软件包,但每次我尝试安装 sklearnscipy 之类的软件包时都会收到此错误:

Could not install packages due to an EnvironmentError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:'

我重新安装了 Visual Studios,认为它必须使用构建工具做一些事情,但我仍然得到错误。我也尝试过以管理员身份运行 pycharm 并使用 --user 但无济于事。我也尝试在我的家用电脑上下载相同的包,但我得到了同样的错误。

这是我得到的完整错误

  Using cached https://files.pythonhosted.org/packages/1e/7a/dbb3be0ce9bd5c8b7e3d87328e79063f8b263b2b1bfa4774cb1147bfcd3f/sklearn-0.0.tar.gz
Collecting scikit-learn (from sklearn)
  Using cached https://files.pythonhosted.org/packages/18/28/5a48b00599b476875415b97bdfdb3849bafb31183c1d785501dbc8a77aa2/scikit-learn-0.22.1.tar.gz
Requirement already satisfied: numpy>=1.11.0 in c:\users\hp omen\pycharmprojects\evaltrade\venv\lib\site-packages (from scikit-learn->sklearn) (1.18.1)
Collecting scipy>=0.17.0 (from scikit-learn->sklearn)
  Using cached https://files.pythonhosted.org/packages/04/ab/e2eb3e3f90b9363040a3d885ccc5c79fe20c5b8a3caa8fe3bf47ff653260/scipy-1.4.1.tar.gz
  Installing build dependencies: started
  Installing build dependencies: still running...
  Installing build dependencies: finished with status 'error'
  Complete output from command "C:\Users\HP Omen\PycharmProjects\evalTrade\venv\Scripts\python.exe" "C:\Users\HP Omen\PycharmProjects\evalTrade\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip" install --ignore-installed --no-user --prefix "C:\Users\HP Omen\AppData\Local\Temp\pip-build-env-4p9slqe7\overlay" --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- wheel setuptools Cython>=0.29.13 "numpy==1.13.3; python_version=='3.5' and platform_system!='AIX'" "numpy==1.13.3; python_version=='3.6' and platform_system!='AIX'" "numpy==1.14.5; python_version=='3.7' and platform_system!='AIX'" "numpy==1.17.3; python_version>='3.8' and platform_system!='AIX'" "numpy==1.16.0; python_version=='3.5' and platform_system=='AIX'" "numpy==1.16.0; python_version=='3.6' and platform_system=='AIX'" "numpy==1.16.0; python_version=='3.7' and platform_system=='AIX'" "numpy==1.17.3; python_version>='3.8' and platform_system=='AIX'" pybind11>=2.4.0:
  Ignoring numpy: markers 'python_version == "3.5" and platform_system != "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.6" and platform_system != "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.7" and platform_system != "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.5" and platform_system == "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.6" and platform_system == "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version == "3.7" and platform_system == "AIX"' don't match your environment
  Ignoring numpy: markers 'python_version >= "3.8" and platform_system == "AIX"' don't match your environment
  Collecting wheel
    Using cached https://files.pythonhosted.org/packages/81/44/db78754a73d9a88c5bd1bb692b40004410970e88aa0c5dff20b57f231505/wheel-0.34.1-py2.py3-none-any.whl
  Collecting setuptools
    Using cached https://files.pythonhosted.org/packages/a7/c5/6c1acea1b4ea88b86b03280f3fde1efa04fefecd4e7d2af13e602661cde4/setuptools-45.1.0-py3-none-any.whl
  Collecting Cython>=0.29.13
    Using cached https://files.pythonhosted.org/packages/9c/9b/706dac7338c2860cd063a28cdbf5e9670995eaea408abbf2e88ba070d90d/Cython-0.29.14.tar.gz
  Collecting numpy==1.17.3
    Using cached https://files.pythonhosted.org/packages/b6/d6/be8f975f5322336f62371c9abeb936d592c98c047ad63035f1b38ae08efe/numpy-1.17.3.zip
  Collecting pybind11>=2.4.0
    Using cached https://files.pythonhosted.org/packages/4b/4d/ae1c4d8e8b139afa9682054dd42df3b0e3b5c1731287933021b9fd7e9cc4/pybind11-2.4.3-py2.py3-none-any.whl
  Installing collected packages: wheel, setuptools, Cython, numpy, pybind11
    Running setup.py install for Cython: started
      Running setup.py install for Cython: finished with status 'done'
    Running setup.py install for numpy: started
      Running setup.py install for numpy: still running...
      Running setup.py install for numpy: finished with status 'done'
  Could not install packages due to an EnvironmentError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '"C:'


  ----------------------------------------

Command ""C:\Users\HP Omen\PycharmProjects\evalTrade\venv\Scripts\python.exe" "C:\Users\HP Omen\PycharmProjects\evalTrade\venv\lib\site-packages\pip-19.0.3-py3.8.egg\pip" install --ignore-installed --no-user --prefix "C:\Users\HP Omen\AppData\Local\Temp\pip-build-env-4p9slqe7\overlay" --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- wheel setuptools Cython>=0.29.13 "numpy==1.13.3; python_version=='3.5' and platform_system!='AIX'" "numpy==1.13.3; python_version=='3.6' and platform_system!='AIX'" "numpy==1.14.5; python_version=='3.7' and platform_system!='AIX'" "numpy==1.17.3; python_version>='3.8' and platform_system!='AIX'" "numpy==1.16.0; python_version=='3.5' and platform_system=='AIX'" "numpy==1.16.0; python_version=='3.6' and platform_system=='AIX'" "numpy==1.16.0; python_version=='3.7' and platform_system=='AIX'" "numpy==1.17.3; python_version>='3.8' and platform_system=='AIX'" pybind11>=2.4.0" failed with error code 1 in None

【问题讨论】:

请不要发布图片。请编辑带有完整错误的帖子。还有你在运行什么命令? 尝试将--user 添加到安装中。或者以管理员身份运行 pycharm 并运行安装包。可能有帮助 @blueteeth 我已经编辑过了。该命令只是“pip install sklearn”。 @Kartheek 这些都不起作用。同样的错误。 你可以从命令行运行python -m pip install sklearn。还要检查它是否确实没有安装,尽管出现错误。 【参考方案1】:

我今天遇到了和你一样的错误,甚至查看了这篇文章寻求帮助!

看,您的用户名HP Omen 之间有一个空格。我删除了 Windows 中的用户名和 scipy 之间的空格,已成功安装。您可以以管理员身份新建一个帐号,修改当前帐号中的名称(包括C:\Users中的文件夹名称)。查看以下链接以获取更多关于how to modify the current username.的帮助

【讨论】:

这是 github 链接,详细说明了问题github.com/numpy/numpy/issues/11451【参考方案2】:

真正的答案是:你不应该修复它,Python / 包开发者应该修复它。您应该确定无法安装的确切软件包并将错误报告给其开发人员。 在你的情况下,NumPy 是原因,正如@eorochena 所说,已经有一个bug report。


至于您的问题,如果您使用过时或非常新的 Python 版本,它仍然可能发生,因为该包没有可用的***。 在这种情况下,您可以尝试两种选择:

使用以下命令从官方***强制安装较旧的软件包版本:(仅限过时的 Python)
pip install --only-binary :all: <failing_package>
 
从here下载非官方包wheel并使用following command安装它:
pip install <path\to\failing_package.whl>

编辑: 嗯,这很奇怪...According to PyPI 在您询问的时候,实际上有一个官方的 Python 3.8 ***可用于numpy==1.17.3... 您的日志说它正在使用缓存的 NumPy 源。也许您应该尝试使用--no-cache-dir 选项运行它?

【讨论】:

以上是关于如何修复“由于 EnvironmentError 无法安装软件包:[WinError 123]”?的主要内容,如果未能解决你的问题,请参考以下文章

由于 EnvironmentError 无法安装软件包:[Errno 2] 没有这样的文件或目录 \\METADATA

由于 EnvironmentError 无法安装软件包:[WinError 5] 访问被拒绝:

由于 EnvironmentError 无法安装软件包:[Errno 30] 只读文件系统:

Python sklearn 安装窗口

安装 pip 包或升级 pip 时出现环境错误 [Errno 2]

错误:由于环境错误而无法安装软件包:[Errno 28] 设备上没有剩余空间