【问题标题】:Error installing python package with Visual Studio 2015使用 Visual Studio 2015 安装 python 包时出错
【发布时间】:2015-12-22 06:17:00
【问题描述】:

我是 Python 新手,因为我熟悉 VS,所以我尝试在 Visual Studio 2015 中使用 Python。我可以成功创建一个示例程序,但是当我尝试使用 pip 安装包 rpi.gpio 时,它给了我以下错误。我正在使用 Python 2.7 64 位和 Visual Studio 2015。有人可以帮忙吗?

----- Installing 'rpi.gpio' -----
You are using pip version 7.0.1, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Collecting rpi.gpio
  Using cached RPi.GPIO-0.5.11.tar.gz
Installing collected packages: rpi.gpio
  Running setup.py install for rpi.gpio
    Complete output from command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\30201610\\appdata\\local\\temp\\pip-build-6yfuyd\\rpi.gpio\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\30201610\appdata\local\temp\pip-ovjyww-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build\lib.win-amd64-2.7
    creating build\lib.win-amd64-2.7\RPi
    copying RPi\__init__.py -> build\lib.win-amd64-2.7\RPi
    running build_ext
    building 'RPi.GPIO' extension
    creating build\temp.win-amd64-2.7
    creating build\temp.win-amd64-2.7\Release
    creating build\temp.win-amd64-2.7\Release\source
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python27\include -IC:\Python27\PC /Tcsource/py_gpio.c /Fobuild\temp.win-amd64-2.7\Release\source/py_gpio.obj
    py_gpio.c
    source/py_gpio.c(81): error C2143: syntax error: missing ';' before '{'
    source/py_gpio.c(109): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
    source/py_gpio.c(113): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
    source/py_gpio.c(194): error C2143: syntax error: missing ';' before '{'
    source/py_gpio.c(218): warning C4047: 'return': 'PyObject *' differs in levels of indirection from 'int'
    source/py_gpio.c(270): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
    source/py_gpio.c(272): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
    source/py_gpio.c(326): error C2373: 'output': redefinition; different type modifiers
    c:\users\30201610\appdata\local\temp\pip-build-6yfuyd\rpi.gpio\source\constants.h(29): note: see declaration of 'output'
    source/py_gpio.c(326): error C2143: syntax error: missing ';' before '{'
    source/py_gpio.c(340): warning C4047: 'return': 'PyObject *' differs in levels of indirection from 'int'
    source/py_gpio.c(387): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
    source/py_gpio.c(389): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
    source/py_gpio.c(391): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
    source/py_gpio.c(393): warning C4244: '=': conversion from 'Py_ssize_t' to 'int', possible loss of data
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\cl.exe' failed with exit status 2

    ----------------------------------------
Command "C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\30201610\\appdata\\local\\temp\\pip-build-6yfuyd\\rpi.gpio\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\30201610\appdata\local\temp\pip-ovjyww-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\30201610\appdata\local\temp\pip-build-6yfuyd\rpi.gpio
----- Failed to install 'rpi.gpio' -----

【问题讨论】:

  • 请考虑将错误复制到代码块中,而不是向我们显示图像。
  • 抱歉,我已经用错误文本更新了问题。
  • 我想我有点困惑。为什么要在 Windows 上的 Raspberry Pi 上安装控制 GPIO 的库?
  • 好问题。因为在树莓派上无法安装 Visual Studio。
  • 其实我也有同样的问题。我只想在 Windows 上安装这个库,因为我正在 Visual Studio 中为我的 Pi 编写代码,并且我想摆脱它触发的错误。显然不会在 Windows 中“使用”该库,但我希望它作为我的 Python 代码的参考,就像所有其他 pip 安装的模块一样。

标签: python visual-studio pip


【解决方案1】:

relevant sourceforge issue

RPi.GPIO 设计为仅在运行 Linux 的 Raspberry Pi 上运行。 - Ben Croston(维护者)

【讨论】:

  • 我怀疑的那种,自动完成。
【解决方案2】:

您可能不需要 rpi.gpio 包来远程访问 Pi 的引脚。如果没有通过 PIGPIO_ADDR 环境变量配置远程 pigpio 服务器,则 Pin factory 丢失,因此它回退到 localhost,那里什么都没有。

  • 将 pigpio 安装到 Pi
  • 在 Pi Configuration 的 Interfaces 选项卡上启用远程 GPIO
  • 使用 sudo pigpiod 启动守护进程
  • pip 将 gpiozero 和 pigpio 包安装到 Windows 机器上
  • 设置 PIGPIO_ADDR 环境变量,如 SET PIGPIO_ADDR=192.168.1.3
  • 在 PC 上启动您的 Python 应用程序,同时可以通过 网络。

通过这种方式,我能够在我的 PC 上使用与 Pi 上完全相同的代码。

如果您使用 ANSI 控制序列,请考虑使用来自 te store 的新 MS Windows Terminal

更多细节、替代方案、远程操作系统:https://gpiozero.readthedocs.io/en/stable/remote_gpio.html

【讨论】:

    猜你喜欢
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多