首页 > 解决方案 > 无法在 Windows 上的虚拟环境中安装 sklearn - 错误:命令出错,退出状态为 1:

问题描述

谁能帮我将 sklearn 安装到 Windows 虚拟环境?

这样做的正常方法是

方法 1 - pip install 进入空环境

python -m venv venv
.\venv\Scripts\activate.bat
pip install sklearn

方法 2 - 使用系统设置创建虚拟环境

或者如果你的操作系统上已经安装了 sklearn,这个方法

python -m venv venv --system-site-packages
.\venv\Scripts\activate.bat

当我尝试安装 pip 时,这两种方法都会产生错误,或者如果我尝试运行 python/flask 文件,则会说 sklearn 模块丢失

尝试了 pip 安装方法

从我尝试过的命令行

pip install sklearn

我也尝试通过 requirements.txt 文件安装 sklearn

pip install -r requirements.txt

我还尝试隔离我需要的 sklearn 部分

pip install -U scikit-learn scipy linear_model

我也试过

pip3 install sklearn

我遇到的错误有好几页

使用缓存的 sklearn-0.0.tar.gz (1.1 kB) 收集 sklearn 使用缓存的 scikit-learn-0.23.2.tar.gz (7.2 MB) 收集 scikit-learn状态 1: 命令:'c:\users\owner\desktop\machine_learning_project\venv\scripts\python.exe' 'c:\users\owner\desktop\machine_learning_project\venv\lib\site-packages\pip' 安装 --忽略安装 --no-user --prefix 'C:\Users\Owner\AppData\Local\Temp\pip-build-env-whbbbe7h\overlay' --no-warn-script-location --no-binary :无:--only-binary:无:-i https://pypi.org/simple-- setuptools 轮 'Cython>=0.28.5' 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"' and platform_python_implementation == '"'"'CPython'"'"'' 'numpy==1.14 .0; python_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"' and platform_python_implementation != '"'"'CPython'"'"'' 'numpy==1.14 .5;python_version=='"'"'3.7'"'"' 和 platform_system!='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8' "'"' 和 platform_system!='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.6'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.7'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' and platform_system=='"'"'AIX'"'"'' 'scipy>=0.19.1' cwd: None 完整输出(280 行):忽略 numpy : 标记 'python_version == "3.6" 和 platform_system != "AIX" 和 platform_python_implementation == "

= "3.8" 和 platform_system == "AIX"' 与您的环境不匹配 收集 setuptools 使用缓存 setuptools-50.3.2-py3-none-any.whl (785 kB) 收集轮子 使用缓存轮子-0.35.1-py2 .py3-none-any.whl (33 kB) 收集 Cython>=0.28.5 使用缓存的 Cython-0.29.21-py2.py3-none-any.whl (974 kB) 收集 numpy==1.17.3 使用缓存的 numpy -1.17.3.zip (6.4 MB) 收集 scipy>=0.19.1 使用缓存的 scipy-1.5.4-cp39-cp39-win_amd64.whl (31.4 MB) 使用旧版 'setup.py install' 用于 numpy,因为包'轮子'未安装。安装收集的软件包:setuptools、wheel、Cython、numpy、scipy 运行 setup.py install for numpy:已启动 Running setup.py install for numpy:完成状态为“错误”错误:命令错误退出状态为 1:命令:'c :\users\owner\desktop\machine_learning_project\venv\scripts\python.exe' -u -c 'import sys,setuptools,tokenize;sys.argv[0] = '"'"'C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\setup.py'"'"'; file ='"'"'C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\setup.py'"'"';f=getattr(tokenize, '"'"'open' "'"', open)( file );code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"'); f.close();exec(compile(code, file , '"'"'exec'"'"'))' install --record 'C:\Users\Owner\AppData\Local\Temp\pip-record- _06ilpk2\install-record.txt' --single-version-externally-managed --prefix 'C:\Users\Owner\AppData\Local\Temp\pip-build-env-whbbbe7h\overlay' --compile --install -标题'C:\Users\Owner\AppData\Local\Temp\pip-build-env-whbbbe7h\overlay\include\site\python3.9\numpy' cwd: C:\Users\Owner\AppData\Local\Temp\pip-install- geaq7_mw\numpy
完整输出(254 行):从 numpy 源目录运行。

  Note: if you need reliable uninstall behavior, then install
  with pip instead of using `setup.py install`:

    - `pip install .`       (from a git repo or downloaded source
                             release)
    - `pip install numpy`   (last NumPy release on PyPi)


  blas_opt_info:
  blas_mkl_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries mkl_rt not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  blis_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries blis not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  openblas_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries openblas not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] get_default_fcompiler: 匹配类型: '['gnu', 'intelv', 'absoft', 'compaqv', 'intelev', 'gnu95', 'g95', 'intelvem', 'intelem', ' flang']' 自定义 GnuFCompiler 无法找到可执行文件 g77 无法找到可执行文件 f77 自定义 IntelVisualFCompiler 无法找到可执行文件 ifort 无法找到可执行文件 ifl 自定义 AbsoftFCompiler 无法找到可执行文件 f90 自定义 CompaqVisualFCompiler 找到可执行文件 C:\Program Files\Git\usr\bin \DF.exe 找不到可执行文件 C:\Program customize IntelItaniumVisualFCompiler 找不到可执行文件 efl customize Gnu95FCompiler 找不到可执行文件 gfortran 找不到可执行文件 f95 customize G95FCompiler 找不到可执行文件 g95 customize IntelEM64VisualFCompiler customize IntelEM64TFCompiler 找不到可执行文件 efort 找不到可执行文件 efc customize PGroupFlangCompiler 找不到可执行文件 flang don '不知道如何在平台'nt' 上编译 Fortran 代码不可用

  atlas_3_10_blas_threads_info:
  Setting PTATLAS=ATLAS
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries tatlas not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  atlas_3_10_blas_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries satlas not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  atlas_blas_threads_info:
  Setting PTATLAS=ATLAS
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries ptf77blas,ptcblas,atlas not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  atlas_blas_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries f77blas,cblas,atlas not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  accelerate_info:
    NOT AVAILABLE

  C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\numpy\distutils\system_info.py:690:

用户警告:未找到优化的(供应商)Blas 库。回退到性能更差的 netlib Blas 库。通过切换 Blas 库应该可以轻松获得更好的性能。self.calc_info() blas_info:numpy.distutils 中没有名为“numpy.distutils._msvccompiler”的模块;尝试从 distutils 自定义 MSVCCompiler 库 blas not found in ['c:\users\owner\desktop\machine_learning_project\venv\lib', 'C:\'] NOT AVAILABLE

  C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\numpy\distutils\system_info.py:690:

用户警告:找不到 Blas ( http://www.netlib.org/blas/ ) 库。可以在 numpy/distutils/site.cfg 文件([blas] 部分)或通过设置 BLAS 环境变量来指定搜索库的目录。self.calc_info() blas_src_info:不可用

  C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\numpy\distutils\system_info.py:690:

用户警告:找不到 Blas ( http://www.netlib.org/blas/ ) 源。可以在 numpy/distutils/site.cfg 文件([blas_src] 部分)或通过设置 BLAS_SRC 环境变量来指定搜索源的目录。self.calc_info() 不可用

  'svnversion' is not recognized as an internal or external command,
  operable program or batch file.
  non-existing path in 'numpy\\distutils': 'site.cfg'
  lapack_opt_info:
  lapack_mkl_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries mkl_rt not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  openblas_lapack_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries openblas not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  openblas_clapack_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries openblas,lapack not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  flame_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries flame not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  atlas_3_10_threads_info:
  Setting PTATLAS=ATLAS
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack_atlas not found in c:\users\owner\desktop\machine_learning_project\venv\lib
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries tatlas,tatlas not found in c:\users\owner\desktop\machine_learning_project\venv\lib
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack_atlas not found in C:\
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries tatlas,tatlas not found in C:\
  <class 'numpy.distutils.system_info.atlas_3_10_threads_info'>
    NOT AVAILABLE

  atlas_3_10_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack_atlas not found in c:\users\owner\desktop\machine_learning_project\venv\lib
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries satlas,satlas not found in c:\users\owner\desktop\machine_learning_project\venv\lib
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack_atlas not found in C:\
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries satlas,satlas not found in C:\
  <class 'numpy.distutils.system_info.atlas_3_10_info'>
    NOT AVAILABLE

  atlas_threads_info:
  Setting PTATLAS=ATLAS
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack_atlas not found in c:\users\owner\desktop\machine_learning_project\venv\lib
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries ptf77blas,ptcblas,atlas not found in c:\users\owner\desktop\machine_learning_project\venv\lib
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack_atlas not found in C:\
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries ptf77blas,ptcblas,atlas not found in C:\
  <class 'numpy.distutils.system_info.atlas_threads_info'>
    NOT AVAILABLE

  atlas_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack_atlas not found in c:\users\owner\desktop\machine_learning_project\venv\lib
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries f77blas,cblas,atlas not found in c:\users\owner\desktop\machine_learning_project\venv\lib
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack_atlas not found in C:\
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries f77blas,cblas,atlas not found in C:\
  <class 'numpy.distutils.system_info.atlas_info'>
    NOT AVAILABLE

  lapack_info:
  No module named 'numpy.distutils._msvccompiler' in numpy.distutils; trying from distutils
  customize MSVCCompiler
    libraries lapack not found in ['c:\\users\\owner\\desktop\\machine_learning_project\\venv\\lib',

'C:\'] 不可用

  C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\numpy\distutils\system_info.py:1712:

用户警告:

      Lapack (http://www.netlib.org/lapack/) libraries not found.
      Directories to search for the libraries can be specified in the
      numpy/distutils/site.cfg file (section [lapack]) or by setting
      the LAPACK environment variable.
    if getattr(self, '_calc_info_{}'.format(lapack))():
  lapack_src_info:
    NOT AVAILABLE

  C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\numpy\distutils\system_info.py:1712:

用户警告:

      Lapack (http://www.netlib.org/lapack/) sources not found.
      Directories to search for the sources can be specified in the
      numpy/distutils/site.cfg file (section [lapack_src]) or by setting
      the LAPACK_SRC environment variable.
    if getattr(self, '_calc_info_{}'.format(lapack))():
    NOT AVAILABLE

  C:\Users\Owner\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py:274:

UserWarning: Unknown distribution option: 'define_macros' warnings.warn(msg) running install running build running config_cc unifing config_cc, config, build_clib, build_ext, build commands --compiler options running config_fc unifing config_fc, config, build_clib, build_ext, build commands - -fcompiler 选项运行 build_src build_src 构建 py_modules 源 创建构建 创建构建\src.win-amd64-3.9 创建构建\src.win-amd64-3.9\numpy 创建构建\src.win-amd64-3.9\numpy\distutils 构建库 " npymath" 来源 numpy.distutils 中没有名为 'numpy.distutils._msvccompiler' 的模块;尝试从 distutils 错误:需要 Microsoft Visual C++ 14.0 或更高版本。使用“Microsoft C++ 构建工具”获取它: https ://visualstudio.microsoft.com/visual-cpp-build-tools/ ---------------------------------------- 错误:命令出错,退出状态为 1: 'c:\users\owner\desktop\machine_learning_project\venv\scripts\python.exe' -u -c 'import sys,setuptools,tokenize;sys.argv[0] = '"'"'C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\setup.py'"'"'; file ='"'"'C:\Users\Owner\AppData\Local\Temp\pip-install-geaq7_mw\numpy\setup.py'"'"';f=getattr(tokenize, '"'"'open' "'"', open)( file );code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"'); f.close();exec(编译(代码、文件, '"'"'exec'"'"'))' install --record 'C:\Users\Owner\AppData\Local\Temp\pip-record-_06ilpk2\install-record.txt' --single-version -externally-managed --prefix 'C:\Users\Owner\AppData\Local\Temp\pip-build-env-whbbbe7h\overlay' --compile --install-headers 'C:\Users\Owner\AppData\Local \Temp\pip-build-env-whbbbe7h\overlay\include\site\python3.9\numpy' 检查日志以获取完整的命令输出。
---------------------------------------- 错误:命令出错,退出状态为 1: 'c:\users\owner\desktop\machine_learning_project\venv\scripts\python.exe' 'c:\users\owner\desktop\machine_learning_project\venv\lib\site-packages\pip' 安装 --ignore-installed --无用户 --prefix 'C:\Users\Owner\AppData\Local\Temp\pip-build-env-whbbbe7h\overlay'https://pypi.org/simple -- setuptools 轮 'Cython>=0.28.5' 'numpy==1.13.3; python_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"' and platform_python_implementation == '"'"'CPython'"'"'' 'numpy==1.14 .0; python_version=='"'"'3.6'"'"' and platform_system!='"'"'AIX'"'"' and platform_python_implementation != '"'"'CPython'"'"'' 'numpy==1.14 .5;python_version=='"'"'3.7'"'"' 和 platform_system!='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' 和 platform_system!='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.6'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.7'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' 和 platform_system=='"'"'AIX'"'"'' 'scipy>=0.19.1' 检查日志以获取完整的命令输出。"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.6'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.7'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' 和 platform_system=='"'"'AIX'"'"'' 'scipy>=0.19.1' 检查日志以获取完整的命令输出。"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.6'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.7'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' 和 platform_system=='"'"'AIX'"'"'' 'scipy>=0.19.1' 检查日志以获取完整的命令输出。'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.7'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' 和 platform_system=='"'"'AIX'"'"'' 'scipy>=0.19.1' 检查日志以获取完整的命令输出。'AIX'"'"'' 'numpy==1.16.0; python_version=='"'"'3.7'"'"' 和 platform_system=='"'"'AIX'"'"'' 'numpy==1.17.3; python_version>='"'"'3.8'"'"' 和 platform_system=='"'"'AIX'"'"'' 'scipy>=0.19.1' 检查日志以获取完整的命令输出。

标签: scikit-learnpython-venv

解决方案


你的错误说明了一切”

按照步骤。

pip install numpy

然后

pip install scikit-learn

因为 numpy 是要求。


推荐阅读