win10环境下python安装cython-bbox模块出错的解决

一、现象描述

在win10  python3.10 环境下安装cython-bbox,用pip install cython-bbox出现无法安装的问题,报错如下图:

win10环境下python安装cython-bbox模块出错的解决_第1张图片

报错文字:

Processing c:\users\administrator\cython_bbox-0.1.3.tar.gz
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: cython-bbox
  Building wheel for cython-bbox (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [11 lines of output]
      running bdist_wheel
      running build
      running build_ext
      building 'cython_bbox' extension
      creating build
      creating build\temp.win-amd64-cpython-310
      creating build\temp.win-amd64-cpython-310\Release
      creating build\temp.win-amd64-cpython-310\Release\src
      "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site
-packages\numpy\core\include -IC:\Users\Administrator\AppData\Local\Programs\Python\Python310\include -IC:\Users\Administrator\AppData\Local\Programs\Python\Python310\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019
\BuildTools\VC\Tools\MSVC\14.29.30133\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\
include\10.0.19041.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" /Tcsrc/cython_bbox.c /Fobuild\temp.win-amd64-cpython-310\Rele
ase\src/cython_bbox.obj -Wno-cpp
      cl: 命令行 error D8021 :无效的数值参数“/Wno-cpp”
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.29.30133\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for cython-bbox
  Running setup.py clean for cython-bbox
Failed to build cython-bbox
ERROR: Could not build wheels for cython-bbox, which is required to install pyproject.toml-based projects

 错误主要出现在: ERROR: Failed building wheel for cython-bbox,翻译出来就是构建cython-bbox失败。

分析原因:语句提示:     Preparing metadata (setup.py) ... done 

                                        cl: 命令行 error D8021 :无效的数值参数“/Wno-cpp”

打开 setup.py文件,内容如下:

ext_modules = [
    Extension(
        name='cython_bbox',
        sources=['src/cython_bbox.pyx'],
        extra_compile_args = [-Wno-cpp],
        include_dirs=[numpy_include]
    )

经过查询资料,将extra_compile_args = [-Wno-cpp] 语句改换为 extra_compile_args = {'gcc': ['/Qstd=c99']}。如下:

ext_modules = [
    Extension(
        name='cython_bbox',
        sources=['src/cython_bbox.pyx'],
        extra_compile_args = {'gcc': ['/Qstd=c99']},
        include_dirs=[numpy_include]
    )

保存退出,重新安装,仍然不行。于是:

二、安装步骤

1.下载cython-bbox包:

pip download -i https://pypi.tuna.tsinghua.edu.cn/simple cython_bbox 

# 下载cython-bbox模块
pip download -i https://pypi.tuna.tsinghua.edu.cn/simple cython_bbox

2.解压后找到setup.py,更改前面的语句。

extra_compile_args = [-Wno-cpp],    改为:extra_compile_args = {'gcc': ['/Qstd=c99']},

3.下载dev-cpp并安装

下载地址:https://download.csdn.net/download/qq_58168857/88152647?spm=1001.2014.3001.5501

4.在cmd或powershell中,进入cython-bbox文件夹

cd C:\Users\Administrator\cython_bbox-0.1.3

在cython_ccox-0.13目录下,

5. 输入以下命令进行安装

python setup.py build_ext install

一般情况下,都能正确安装 了。安装结果如下:

PS C:\Users\Administrator\cython_bbox-0.1.3> python setup.py build_ext install
Compiling src/cython_bbox.pyx because it changed.
[1/1] Cythonizing src/cython_bbox.pyx
C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\Cython\Compiler\Main.py:381: FutureW
arning: Cython directive 'language_level' not set, using '3str' for now (Py3). This has changed from earlier releases! File: C:\Users\Administrator\cython_bbox-0.1.3\src\cython_bbox.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)
running build_ext
building 'cython_bbox' extension
creating build
creating build\temp.win-amd64-cpython-310
creating build\temp.win-amd64-cpython-310\Release
creating build\temp.win-amd64-cpython-310\Release\src
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IC:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packa
ges\numpy\core\include -IC:\Users\Administrator\AppData\Local\Programs\Python\Python310\include -IC:\Users\Administrator\AppData\Local\Programs\Python\Python310\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Build
Tools\VC\Tools\MSVC\14.29.30133\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\includ
e\10.0.19041.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.19041.0\cppwinrt" /Tcsrc/cython_bbox.c /Fobuild\temp.win-amd64-cpython-310\Release\sr
c/cython_bbox.obj gcc
cl: 命令行 warning D9024 :无法识别的源文件类型“gcc”,假定为对象文件
cl: 命令行 warning D9027 :源文件“gcc”被忽略
cython_bbox.c
C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_API NPY_1
_7_API_VERSION
src/cython_bbox.c(4280): warning C4244: “=”: 从“npy_intp”转换到“unsigned int”,可能丢失数据
src/cython_bbox.c(4290): warning C4244: “=”: 从“npy_intp”转换到“unsigned int”,可能丢失数据
creating C:\Users\Administrator\cython_bbox-0.1.3\build\lib.win-amd64-cpython-310
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:C:\Users\Administrator\AppData\L
ocal\Programs\Python\Python310\libs /LIBPATH:C:\Users\Administrator\AppData\Local\Programs\Python\Python310 /LIBPATH:C:\Users\Administrator\AppData\Local\Programs\Python\Python310\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Mi
crosoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.19041.0\um\x64" /EXPOR
T:PyInit_cython_bbox build\temp.win-amd64-cpython-310\Release\src/cython_bbox.obj /OUT:build\lib.win-amd64-cpython-310\cython_bbox.cp310-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-310\Release\src\cython_bbox.cp310-win_amd
64.lib
  正在创建库 build\temp.win-amd64-cpython-310\Release\src\cython_bbox.cp310-win_amd64.lib 和对象 build\temp.win-amd64-cpython-310\Release\src\cython_bbox.cp310-win_amd64.exp
正在生成代码
已完成代码的生成
running install
C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\_distutils\cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\setuptools\_distutils\cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` and ``easy_install``.
        Instead, use pypa/build, pypa/installer or other
        standards-based tools.

        See https://github.com/pypa/setuptools/issues/917 for details.
        ********************************************************************************

!!
  self.initialize_options()
running bdist_egg
running egg_info
writing cython_bbox.egg-info\PKG-INFO
writing dependency_links to cython_bbox.egg-info\dependency_links.txt
writing top-level names to cython_bbox.egg-info\top_level.txt
reading manifest file 'cython_bbox.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'cython_bbox.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
creating build\bdist.win-amd64
creating build\bdist.win-amd64\egg
copying build\lib.win-amd64-cpython-310\cython_bbox.cp310-win_amd64.pyd -> build\bdist.win-amd64\egg
creating stub loader for cython_bbox.cp310-win_amd64.pyd
byte-compiling build\bdist.win-amd64\egg\cython_bbox.py to cython_bbox.cpython-310.pyc
creating build\bdist.win-amd64\egg\EGG-INFO
copying cython_bbox.egg-info\PKG-INFO -> build\bdist.win-amd64\egg\EGG-INFO
copying cython_bbox.egg-info\SOURCES.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying cython_bbox.egg-info\dependency_links.txt -> build\bdist.win-amd64\egg\EGG-INFO
copying cython_bbox.egg-info\top_level.txt -> build\bdist.win-amd64\egg\EGG-INFO
writing build\bdist.win-amd64\egg\EGG-INFO\native_libs.txt
zip_safe flag not set; analyzing archive contents...
__pycache__.cython_bbox.cpython-310: module references __file__
creating dist
creating 'dist\cython_bbox-0.1.3-py3.10-win-amd64.egg' and adding 'build\bdist.win-amd64\egg' to it
removing 'build\bdist.win-amd64\egg' (and everything under it)
Processing cython_bbox-0.1.3-py3.10-win-amd64.egg
creating c:\users\administrator\appdata\local\programs\python\python310\lib\site-packages\cython_bbox-0.1.3-py3.10-win-amd64.egg
Extracting cython_bbox-0.1.3-py3.10-win-amd64.egg to c:\users\administrator\appdata\local\programs\python\python310\lib\site-packages
Adding cython-bbox 0.1.3 to easy-install.pth file

Installed c:\users\administrator\appdata\local\programs\python\python310\lib\site-packages\cython_bbox-0.1.3-py3.10-win-amd64.egg
Processing dependencies for cython-bbox==0.1.3
Finished processing dependencies for cython-bbox==0.1.3

6.检模块包安装情况

pip list

win10环境下python安装cython-bbox模块出错的解决_第2张图片

三、注意事项

1.python 版本最好高于3.8,到www.python.org下载并安装原生python包。

2. 安装cyphon-bbox前,记得先安装cython,(pip install cython),这个是安装cython-bbox的另一个前置条件。

3.安装 cython-bbox时,注意所选默认python的版本(安装目录)。

你可能感兴趣的:(踩坑经验,python,开发语言)