简体   繁体   English

Python软件包在需要C源代码编译的软件包上安装失败(Visual Studio 2017)

[英]Python package(s) install failure on packages that requires C source compiling (Visual Studio 2017)

In Visual Studio's Python, i can install packages, which as far as i know doesn't require C source compiling. 在Visual Studio的Python中,我可以安装程序包,据我所知,这些程序不需要C源代码编译。 When it comes to packages that requires compiling, it's always fail. 当涉及需要编译的软件包时,它总是会失败。 My installation attempts are always done via pip install package-name inside the Visual Studio. 我的安装尝试总是通过Visual Studio中的pip install package-name完成的。 This is what i have tried : 这是我尝试过的:

  • Installing Visual Studio 2015 (VS 14.0) C/C++ Standalone compiler 安装Visual Studio 2015(VS 14.0)C / C ++独立编译器
  • Try to re-install the package after compiler installation, still fail 尝试在编译器安装后重新安装软件包,仍然失败
  • Restarting the machine, then try to re-install the package, still fail 重新启动计算机,然后尝试重新安装软件包,仍然失败

Specifically, i have tried to install RPIO and RPi.GPIO , more or less it give similar error message : 具体来说,我尝试安装RPIORPi.GPIO ,或多或少它会给出类似的错误消息:

error: command 'C:\\\\Program Files (x86)\\\\Microsoft Visual Studio 14.0\\\\VC\\\\BIN\\\\x86_amd64\\\\cl.exe' failed with exit status 2

Here is the full log from the RPIO installation attempt : 这是RPIO安装尝试的完整日志:

----- Installing 'RPIO==0.10.0' -----
Collecting RPIO==0.10.0
  Using cached RPIO-0.10.0.tar.gz
Installing collected packages: RPIO
  Running setup.py install for RPIO: started
    Running setup.py install for RPIO: finished with status 'error'
    Complete output from command "C:\Program Files\Python36\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\ELEMEN~1\\AppData\\Local\\Temp\\pip-build-4lvb_8wu\\RPIO\\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\ELEMEN~1\AppData\Local\Temp\pip-oqz8bi8d-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-3.6
    creating build\lib.win-amd64-3.6\RPIO
    copying source\RPIO\Exceptions.py -build\lib.win-amd64-3.6\RPIO
    copying source\RPIO\_RPIO.py -build\lib.win-amd64-3.6\RPIO
    copying source\RPIO\__init__.py -build\lib.win-amd64-3.6\RPIO
    creating build\lib.win-amd64-3.6\RPIO\PWM
    copying source\RPIO\PWM\__init__.py -build\lib.win-amd64-3.6\RPIO\PWM
    running build_ext
    building 'RPIO._GPIO' extension
    creating build\temp.win-amd64-3.6
    creating build\temp.win-amd64-3.6\Release
    creating build\temp.win-amd64-3.6\Release\source
    creating build\temp.win-amd64-3.6\Release\source\c_gpio
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\x86_amd64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD "-IC:\Program Files\Python36\include" "-IC:\Program Files\Python36\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\winrt" /Tcsource/c_gpio/py_gpio.c /Fobuild\temp.win-amd64-3.6\Release\source/c_gpio/py_gpio.obj
    py_gpio.c
    source/c_gpio/py_gpio.c(361): error C2373: 'setmode': redefinition; different type modifiers
    C:\Program Files (x86)\Windows Kits\10\include\10.0.10586.0\ucrt\corecrt_io.h(528): note: see declaration of 'setmode'
    source/c_gpio/py_gpio.c(431): warning C4028: formal parameter 1 different from declaration
    source/c_gpio/py_gpio.c(431): warning C4028: formal parameter 2 different from declaration
    source/c_gpio/py_gpio.c(431): warning C4047: 'initializing': 'PyCFunction' differs in levels of indirection from 'int (__cdecl *)(int,int)'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\cl.exe' failed with exit status 2

    ----------------------------------------
Command ""C:\Program Files\Python36\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\ELEMEN~1\\AppData\\Local\\Temp\\pip-build-4lvb_8wu\\RPIO\\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\ELEMEN~1\AppData\Local\Temp\pip-oqz8bi8d-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\ELEMEN~1\AppData\Local\Temp\pip-build-4lvb_8wu\RPIO\
----- Failed to install 'RPIO==0.10.0' -----

So am i missing something ? 那我错过了什么吗? Or is it the package's source that missing something ? 还是包装的来源缺少某些东西?

Thank you 谢谢

First, thank you @martineau for hinting the problems 首先,感谢@martineau提示问题

This is not a whole solution, but rather some workaround. 这不是一个完整的解决方案,而是一些解决方法。

1. Use Another IDE / Tool 1.使用另一个IDE /工具

While the library still not compatible with the Windows toolchain, you can try another tool or IDE that might do. 虽然该库仍与Windows工具链不兼容,但是您可以尝试使用其他可能兼容的工具或IDE。


2. Another library 2.另一个图书馆

This is the workaround that i take. 这是我要采取的解决方法。 Basically, i need Python library for accessing RPi GPIO, the said RPi.GPIO and RPIO won't be installed on the Windows ver. 基本上,我需要用于访问RPi GPIO的Python库,所述的RPi.GPIORPIO不会安装在Windows版本上。 of Python, so i move to another library called gpiozero . 的Python,所以我转到另一个名为gpiozero库。 It is compatible with the Windows Python (it's successfully pip -ed in VS) and so far provide functionalities that i need. 它是与Windows兼容的Python(它的成功pip -ed在VS),到目前为止提供了我需要的功能。

It looks like py_gpio.c is redefining setmode (line 361, used at line 431). 看起来py_gpio.c正在重新定义 setmode (第361行,第431行使用)。 This is a bug in their code, so you should find the team who owns it and report it to them. 这是他们代码中的错误,因此您应该找到拥有它的团队并将其报告给他们。 Most likely they added it to support older versions of MSVC, and should not add it for the current version. 他们很可能将其添加为支持MSVC的较早版本,并且不应为当前版本添加它。

It also appears that the code is using a different definition than what the C runtime has, which could later cause problems if the variable types do not match. 似乎代码使用的定义与C运行时的定义不同,如果变量类型不匹配,稍后可能会引起问题。 A full code review may be needed here. 这里可能需要完整的代码审查。

In any case, this appears to be a problem with the RPi.GPIO package and not with your install or the tools you are using. 无论如何,这似乎是RPi.GPIO软件包的问题,​​而不是您的安装或使用的工具的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Visual Studio 2017 中向 python 添加包 - How to add a package to python in Visual Studio 2017 如何捆绑Python软件包(案例研究:Microsoft Visual Studio 2017) - How to bundle Python packages (case study: Microsoft Visual Studio 2017) Windows上的Visual Studio 2017中的Python包(numpy / pandas / etc) - Python packages (numpy/pandas/etc) in Visual Studio 2017 on Windows 如何在python应用程序中的Visual Studio 2017中使用用户包 - How to use user packages in Visual Studio 2017 in a python application 如何在 Visual Studio 2017 的 Python 项目中添加现有的 package(用于 IntelliSense) - How to add existing package in Python project in Visual Studio 2017 (for IntelliSense) 检查 Python 包是否需要 Visual Studio 构建工具 - Check if Python Package requires Visual Studio Build Tools 为什么 python 使用 3.8.1 和 3.9,然后安装包失败(错误:Package pkg 需要不同的 Python: 3.9.0'1)? - Why is python using 3.8.1 and 3.9, then fail to install packages (ERROR: Package pkg requires a different Python: 3.8.1 not in '>=3.9.0')? Visual Studio 2017-Python工具 - Visual Studio 2017 - python tool C++ DLL 使用 SWIG 和 Visual Studio 2017 导入 python - C++ DLL import in python with SWIG and Visual Studio 2017 适用于Visual Studio 2017的Python工具 - Python tool for visual studio 2017
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM