5

I am trying to create a virtual environment that can access GPIO pins. In order to do that, I need access to RPi.GPIO in the environment. I am unable to install that into the virtual environment. I managed to make it work by allowing the environment to have access to system packages, but I would like to avoid that.

I installed the latest clean copy of the Raspbian OS, connected to the internet and ran the following commands.

sudo apt-get update
sudo apt-get full-upgrade
python -m venv venv_sandbox
cd venv_sandbox
pip install rpi.gpio

The last command results in a very long error.

Installing collected packages: rpi.gpio
    Running setup.py install for rpi.gpio ... error
    ERROR: Command errored out with exit status 1:
     command: /home/pi/test_venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/setup.py'"'"'; __file__='"'"'/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vwjkwb7k/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/test_venv/include/site/python3.9/rpi.gpio
         cwd: /tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/
    Complete output (87 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-armv7l-3.9
    creating build/lib.linux-armv7l-3.9/RPi
    copying RPi/__init__.py -> build/lib.linux-armv7l-3.9/RPi
    creating build/lib.linux-armv7l-3.9/RPi/GPIO
    copying RPi/GPIO/__init__.py -> build/lib.linux-armv7l-3.9/RPi/GPIO
    running build_ext
    building 'RPi._GPIO' extension
    creating build/temp.linux-armv7l-3.9
    creating build/temp.linux-armv7l-3.9/source
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/c_gpio.c -o build/temp.linux-armv7l-3.9/source/c_gpio.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/common.c -o build/temp.linux-armv7l-3.9/source/common.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/constants.c -o build/temp.linux-armv7l-3.9/source/constants.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/cpuinfo.c -o build/temp.linux-armv7l-3.9/source/cpuinfo.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/event_gpio.c -o build/temp.linux-armv7l-3.9/source/event_gpio.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/py_gpio.c -o build/temp.linux-armv7l-3.9/source/py_gpio.o
    source/py_gpio.c: In function ‘PyInit__GPIO’:
    source/py_gpio.c:1046:4: warning: ‘PyEval_ThreadsInitialized’ is deprecated [-Wdeprecated-declarations]
     1046 |    if (!PyEval_ThreadsInitialized())
          |    ^~
    In file included from /usr/include/python3.9/Python.h:145,
                     from source/py_gpio.c:23:
    /usr/include/python3.9/ceval.h:129:36: note: declared here
      129 | Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
          |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
    source/py_gpio.c:1047:7: warning: ‘PyEval_InitThreads’ is deprecated [-Wdeprecated-declarations]
     1047 |       PyEval_InitThreads();
          |       ^~~~~~~~~~~~~~~~~~
    In file included from /usr/include/python3.9/Python.h:145,
                     from source/py_gpio.c:23:
    /usr/include/python3.9/ceval.h:130:37: note: declared here
      130 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
          |                                     ^~~~~~~~~~~~~~~~~~
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/py_pwm.c -o build/temp.linux-armv7l-3.9/source/py_pwm.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/soft_pwm.c -o build/temp.linux-armv7l-3.9/source/soft_pwm.o
    arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-z,relro -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-armv7l-3.9/source/c_gpio.o build/temp.linux-armv7l-3.9/source/common.o build/temp.linux-armv7l-3.9/source/constants.o build/temp.linux-armv7l-3.9/source/cpuinfo.o build/temp.linux-armv7l-3.9/source/event_gpio.o build/temp.linux-armv7l-3.9/source/py_gpio.o build/temp.linux-armv7l-3.9/source/py_pwm.o build/temp.linux-armv7l-3.9/source/soft_pwm.o -o build/lib.linux-armv7l-3.9/RPi/_GPIO.cpython-39-arm-linux-gnueabihf.so
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:41: multiple definition of `module_setup'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:41: first defined here
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:40: multiple definition of `setup_error'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:40: first defined here
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:39: multiple definition of `rpiinfo'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:39: first defined here
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:38: multiple definition of `gpio_direction'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:38: first defined here
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:37: multiple definition of `pin_to_gpio'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:37: first defined here

blabla lots of error logs that I can't post because number of characters are limited

    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/py_pwm.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:34: multiple definition of `pin_to_gpio_rev1'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:34: first defined here
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/py_pwm.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:33: multiple definition of `gpio_mode'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/common.h:33: first defined here
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/soft_pwm.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/soft_pwm.c:28: multiple definition of `threads'; build/temp.linux-armv7l-3.9/source/event_gpio.o:/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/source/event_gpio.c:60: first defined here
    collect2: error: ld returned 1 exit status
    error: command '/usr/bin/arm-linux-gnueabihf-gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/pi/test_venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/setup.py'"'"'; __file__='"'"'/tmp/pip-install-erugpti2/rpi-gpio_f96cc890e48a4d1cbcc15f9738db26ab/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-vwjkwb7k/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/test_venv/include/site/python3.9/rpi.gpio Check the logs for full command output.


As you can see in the first line of the error message, it said package wheel is not installed so I tried installing that.

pip install wheel
pip install rpi.gpio

The error here seems to be divided into 2 sections

Building wheels for collected packages: rpi.gpio
  Building wheel for rpi.gpio (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /home/pi/test_venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/setup.py'"'"'; __file__='"'"'/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-xwlaa_zg
       cwd: /tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/
  Complete output (87 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-armv7l-3.9
  creating build/lib.linux-armv7l-3.9/RPi
  copying RPi/__init__.py -> build/lib.linux-armv7l-3.9/RPi
  creating build/lib.linux-armv7l-3.9/RPi/GPIO
  copying RPi/GPIO/__init__.py -> build/lib.linux-armv7l-3.9/RPi/GPIO
  running build_ext
  building 'RPi._GPIO' extension
  creating build/temp.linux-armv7l-3.9
  creating build/temp.linux-armv7l-3.9/source
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/c_gpio.c -o build/temp.linux-armv7l-3.9/source/c_gpio.o
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/common.c -o build/temp.linux-armv7l-3.9/source/common.o
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/constants.c -o build/temp.linux-armv7l-3.9/source/constants.o
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/cpuinfo.c -o build/temp.linux-armv7l-3.9/source/cpuinfo.o
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/event_gpio.c -o build/temp.linux-armv7l-3.9/source/event_gpio.o
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/py_gpio.c -o build/temp.linux-armv7l-3.9/source/py_gpio.o
  source/py_gpio.c: In function ‘PyInit__GPIO’:
  source/py_gpio.c:1046:4: warning: ‘PyEval_ThreadsInitialized’ is deprecated [-Wdeprecated-declarations]
   1046 |    if (!PyEval_ThreadsInitialized())
        |    ^~
  In file included from /usr/include/python3.9/Python.h:145,
                   from source/py_gpio.c:23:
  /usr/include/python3.9/ceval.h:129:36: note: declared here
    129 | Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
        |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
  source/py_gpio.c:1047:7: warning: ‘PyEval_InitThreads’ is deprecated [-Wdeprecated-declarations]
   1047 |       PyEval_InitThreads();
        |       ^~~~~~~~~~~~~~~~~~
  In file included from /usr/include/python3.9/Python.h:145,
                   from source/py_gpio.c:23:
  /usr/include/python3.9/ceval.h:130:37: note: declared here
    130 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
        |                                     ^~~~~~~~~~~~~~~~~~
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/py_pwm.c -o build/temp.linux-armv7l-3.9/source/py_pwm.o
  arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/soft_pwm.c -o build/temp.linux-armv7l-3.9/source/soft_pwm.o
  arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-z,relro -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-armv7l-3.9/source/c_gpio.o build/temp.linux-armv7l-3.9/source/common.o build/temp.linux-armv7l-3.9/source/constants.o build/temp.linux-armv7l-3.9/source/cpuinfo.o build/temp.linux-armv7l-3.9/source/event_gpio.o build/temp.linux-armv7l-3.9/source/py_gpio.o build/temp.linux-armv7l-3.9/source/py_pwm.o build/temp.linux-armv7l-3.9/source/soft_pwm.o -o build/lib.linux-armv7l-3.9/RPi/_GPIO.cpython-39-arm-linux-gnueabihf.so
  /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:41: multiple definition of `module_setup'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:41: first defined here
  /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:40: multiple definition of `setup_error'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:40: first defined here
  /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:39: multiple definition of `rpiinfo'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:39: first defined here
  /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:38: multiple definition of `gpio_direction'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:38: first defined here

blabla lots of error logs that I can't post because number of characters are limited

gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:33: first defined here
  /usr/bin/ld: build/temp.linux-armv7l-3.9/source/soft_pwm.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/soft_pwm.c:28: multiple definition of `threads'; build/temp.linux-armv7l-3.9/source/event_gpio.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/event_gpio.c:60: first defined here
  collect2: error: ld returned 1 exit status
  error: command '/usr/bin/arm-linux-gnueabihf-gcc' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for rpi.gpio

This is then followed by

Running setup.py clean for rpi.gpio
Failed to build rpi.gpio
Installing collected packages: rpi.gpio
    Running setup.py install for rpi.gpio ... error
    ERROR: Command errored out with exit status 1:
     command: /home/pi/test_venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/setup.py'"'"'; __file__='"'"'/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-g4kccf4m/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/test_venv/include/site/python3.9/rpi.gpio
         cwd: /tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/
    Complete output (87 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-armv7l-3.9
    creating build/lib.linux-armv7l-3.9/RPi
    copying RPi/__init__.py -> build/lib.linux-armv7l-3.9/RPi
    creating build/lib.linux-armv7l-3.9/RPi/GPIO
    copying RPi/GPIO/__init__.py -> build/lib.linux-armv7l-3.9/RPi/GPIO
    running build_ext
    building 'RPi._GPIO' extension
    creating build/temp.linux-armv7l-3.9
    creating build/temp.linux-armv7l-3.9/source
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/c_gpio.c -o build/temp.linux-armv7l-3.9/source/c_gpio.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/common.c -o build/temp.linux-armv7l-3.9/source/common.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/constants.c -o build/temp.linux-armv7l-3.9/source/constants.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/cpuinfo.c -o build/temp.linux-armv7l-3.9/source/cpuinfo.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/event_gpio.c -o build/temp.linux-armv7l-3.9/source/event_gpio.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/py_gpio.c -o build/temp.linux-armv7l-3.9/source/py_gpio.o
    source/py_gpio.c: In function ‘PyInit__GPIO’:
    source/py_gpio.c:1046:4: warning: ‘PyEval_ThreadsInitialized’ is deprecated [-Wdeprecated-declarations]
     1046 |    if (!PyEval_ThreadsInitialized())
          |    ^~
    In file included from /usr/include/python3.9/Python.h:145,
                     from source/py_gpio.c:23:
    /usr/include/python3.9/ceval.h:129:36: note: declared here
      129 | Py_DEPRECATED(3.9) PyAPI_FUNC(int) PyEval_ThreadsInitialized(void);
          |                                    ^~~~~~~~~~~~~~~~~~~~~~~~~
    source/py_gpio.c:1047:7: warning: ‘PyEval_InitThreads’ is deprecated [-Wdeprecated-declarations]
     1047 |       PyEval_InitThreads();
          |       ^~~~~~~~~~~~~~~~~~
    In file included from /usr/include/python3.9/Python.h:145,
                     from source/py_gpio.c:23:
    /usr/include/python3.9/ceval.h:130:37: note: declared here
      130 | Py_DEPRECATED(3.9) PyAPI_FUNC(void) PyEval_InitThreads(void);
          |                                     ^~~~~~~~~~~~~~~~~~
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/py_pwm.c -o build/temp.linux-armv7l-3.9/source/py_pwm.o
    arm-linux-gnueabihf-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/home/pi/test_venv/include -I/usr/include/python3.9 -c source/soft_pwm.c -o build/temp.linux-armv7l-3.9/source/soft_pwm.o
    arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-z,relro -g -fwrapv -O2 -g -ffile-prefix-map=/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-armv7l-3.9/source/c_gpio.o build/temp.linux-armv7l-3.9/source/common.o build/temp.linux-armv7l-3.9/source/constants.o build/temp.linux-armv7l-3.9/source/cpuinfo.o build/temp.linux-armv7l-3.9/source/event_gpio.o build/temp.linux-armv7l-3.9/source/py_gpio.o build/temp.linux-armv7l-3.9/source/py_pwm.o build/temp.linux-armv7l-3.9/source/soft_pwm.o -o build/lib.linux-armv7l-3.9/RPi/_GPIO.cpython-39-arm-linux-gnueabihf.so
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:41: multiple definition of `module_setup'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:41: first defined here
    /usr/bin/ld: build/temp.linux-armv7l-3.9/source/constants.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:40: multiple definition of `setup_error'; build/temp.linux-armv7l-3.9/source/common.o:/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/source/common.h:40: first defined here

blabla lots of error logs that I can't post because number of characters are limited

    collect2: error: ld returned 1 exit status
    error: command '/usr/bin/arm-linux-gnueabihf-gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/pi/test_venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/setup.py'"'"'; __file__='"'"'/tmp/pip-install-397g_s4d/rpi-gpio_393bfb7d7ed344aea4d895fd7488d832/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-g4kccf4m/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/test_venv/include/site/python3.9/rpi.gpio Check the logs for full command output.

Notes:

  • Running pip freeze does not display wheel as installed after I installed it with pip
  • both python and pip are using version 3
  • everything works (the scripts using GPIO pins) if I set the venv to use system packages

Is there a way to install RPi.GPIO on virtual environments? There are a lot of answers suggesting it can be, but none discuss the issue that I'm having.

If there isn't, is there a way to set the virtual environment to just use this specific system package? I would prefer not to give it access to everything?

kimv
  • 155
  • 4
  • [Pi.GPIO](https://raspberrypi.stackexchange.com/a/117593/8697) is an enhanced version of RPi.GPIO with additions which has fixes for the python GCC in Bullseye – Milliways Jan 08 '22 at 23:29

2 Answers2

8

It looks like the latest release does not support Python 3.9 but the alpha releases do: https://www.piwheels.org/project/RPi.GPIO/

You can install the alpha version with:

pip install rpi-gpio --pre
ben_nuttall
  • 2,381
  • 11
  • 15
2

It seems you are affected by https://sourceforge.net/p/raspberry-gpio-python/tickets/187/, which has been fixed in 0.7.1a2, and is a GCC, not a Python issue. It can be circumvented by doing export CFLAGS=-fcommon first, before installing rpi.gpio. However, the latest stable release 0.7.0 does not fully support RPI4. So you might want to install version 0.7.1a4 anyway.

dleidert
  • 21
  • 1
  • Strictly speaking GCC is not to blame for rejecting everything that is non-standard. It is even helpful when it comes to platform independent development. So it is a problem with raspberry-gpio-python if they use non-standard behaviour or deprecated features. Even if these features have been implemented by intention. – Tobias Schlemmer Jan 09 '22 at 17:20