Power & Source of Big Ideas

NanoPi M1 python RPi.GPIO - ImportError: No module

Moderators: chensy, FATechsupport

hello,

I have NanoPi M1 and I want to program GPIO pins with python. When I try to import module with "import RPi.GPIO" I get message "ImportError: No module named 'RPi'".

I have found, that RPi.GPIO should be installed by default on NanoPi NEO/NEO2/Air, but I can not find any article how to install it on NanoPi M1.

Can anyone help me, how to work with python RPi.GPIO on NanoPi M1 board?
I am using current armbian https://www.armbian.com/nanopi-m1/

Thank you. Jakub
I do not use friendlyelec images anymore, but yes, these images should contain RPi.GPIO_NP by default.

However, from a previous message at viewtopic.php?f=47&t=1151, a user was obliged to install RPI.GPIO by hand (with pip3). This procedure is invalid because RPI.GPIO is incompatible with NanoPI. You really need a RPI.GPIO_NP installation.

You must probably now build https://github.com/auto3000/RPi.GPIO_NP manually on friendlyelec images.

The INSTALL procedure is described at the end of https://github.com/auto3000/RPi.GPIO_NP ... NSTALL.txt.
hi,

I have tried described but with no success.

What I did:
- sudo apt-get install python-dev python3-dev
- git clone https://github.com/auto3000/RPi.GPIO_NP.git
- cd cd RPi.GPIO_NP
- sudo python setup.py install

I get few warnings but finally it was done successful.

But when I run python with "python" command and than try to "import RPi.GPIO_NP" i get error "ImportError: No module named GPIO_NP"

I have tried same with python3 but no success. Am I doing something wrong, or what is problem?
Please give a try with "import RPi.GPIO". For reference, you can find a working software based on this library at https://github.com/auto3000/pedalpii/bl ... II/main.py

For python3, I suspect you need to install with "python3 setup.py install".

To be honest, I never tried to install on friendlyelec images, but some users did it successfully.
I have found, that package is successfully installed, but there is no code. When I try import RPi.GPIO_NP there is no directory GPIO_NP in RPi folder: https://github.com/auto3000/RPi.GPIO_NP/tree/master/RPi
When I try import RPi.GPIO, there is GPIO directory but is empty, except __init__ where is "from RPi._GPIO import *" pointing to not existing directory _GPIO
About _GPIO, it could be fine. This symbol is implemented in a native library (.so), you can refer at line 976 of https://github.com/auto3000/RPi.GPIO_NP ... /py_gpio.c for any doubts.

I think you should be able to call RPI.GPIO procedures with your environment now.
I have pulled new changes and run setup again. But with no success:

command import RPi.GPIO cause:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "RPi/GPIO/__init__.py", line 23, in <module>
from RPi._GPIO import *
ImportError: No module named _GPIO

and cmd import RPi.GPIO_NP cause:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named GPIO_NP
I am attaching install log, maybe it will helps:

Code: Select all

udo python setup.py install
running install
running build
running build_py
running build_ext
building 'RPi._GPIO' extension
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/py_gpio.c -o build/temp.linux-armv7l-2.7/source/py_gpio.o
source/py_gpio.c: In function 'init_GPIO':
source/py_gpio.c:1034:16: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
    pin_to_gpio = &pin_to_gpio_nanopi;
                ^
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/c_gpio.c -o build/temp.linux-armv7l-2.7/source/c_gpio.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/cpuinfo.c -o build/temp.linux-armv7l-2.7/source/cpuinfo.o
source/cpuinfo.c: In function 'get_rpi_info':
source/cpuinfo.c:41:7: warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result]
       fgets(buffer, sizeof(buffer), fp);
       ^
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/event_gpio.c -o build/temp.linux-armv7l-2.7/source/event_gpio.o
source/event_gpio.c: In function 'gpio_export':
source/event_gpio.c:64:5: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
     write(fd, str_gpio, len);
     ^
source/event_gpio.c: In function 'gpio_unexport':
source/event_gpio.c:79:5: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
     write(fd, str_gpio, len);
     ^
source/event_gpio.c: In function 'gpio_set_direction':
source/event_gpio.c:106:9: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
         write(fd, "in", 3);
         ^
source/event_gpio.c:108:9: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
         write(fd, "out", 4);
         ^
source/event_gpio.c: In function 'gpio_set_edge':
source/event_gpio.c:124:5: warning: ignoring return value of 'write', declared with attribute warn_unused_result [-Wunused-result]
     write(fd, stredge[edge], strlen(stredge[edge]) + 1);
     ^
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/soft_pwm.c -o build/temp.linux-armv7l-2.7/source/soft_pwm.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/py_pwm.c -o build/temp.linux-armv7l-2.7/source/py_pwm.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/common.c -o build/temp.linux-armv7l-2.7/source/common.o
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/constants.c -o build/temp.linux-armv7l-2.7/source/constants.o
arm-linux-gnueabihf-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -Wdate-time -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-armv7l-2.7/source/py_gpio.o build/temp.linux-armv7l-2.7/source/c_gpio.o build/temp.linux-armv7l-2.7/source/cpuinfo.o build/temp.linux-armv7l-2.7/source/event_gpio.o build/temp.linux-armv7l-2.7/source/soft_pwm.o build/temp.linux-armv7l-2.7/source/py_pwm.o build/temp.linux-armv7l-2.7/source/common.o build/temp.linux-armv7l-2.7/source/constants.o -o build/lib.linux-armv7l-2.7/RPi/_GPIO.so
running install_lib
creating /usr/local/lib/python2.7/dist-packages/RPi
copying build/lib.linux-armv7l-2.7/RPi/_GPIO.so -> /usr/local/lib/python2.7/dist-packages/RPi
copying build/lib.linux-armv7l-2.7/RPi/__init__.py -> /usr/local/lib/python2.7/dist-packages/RPi
creating /usr/local/lib/python2.7/dist-packages/RPi/GPIO
copying build/lib.linux-armv7l-2.7/RPi/GPIO/__init__.py -> /usr/local/lib/python2.7/dist-packages/RPi/GPIO
byte-compiling /usr/local/lib/python2.7/dist-packages/RPi/__init__.py to __init__.pyc
byte-compiling /usr/local/lib/python2.7/dist-packages/RPi/GPIO/__init__.py to __init__.pyc
running install_egg_info
Writing /usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.6.3.egg-info
Thanks for the detailed logs, really.

I don't know if that matters, probably it doesn't, but I can see there is a copy in /usr/"local"/lib during installation. Maybe python3 would give same results (sudo python3 setup.py install....)

Code: Select all

copying build/lib.linux-armv7l-2.7/RPi/_GPIO.so -> /usr/local/lib/python2.7/dist-packages/RPi
...


I will give a try on next weekend.
Sorry japlavaren, I did play with a different stuff this weekend, I have to postpone my investigation about python installation for later.
The software documentation has been updated. Please check INSTALL.txt and README.md in latest release.
hi,

I have tried new install, but after running "python setup.py install" getting error:

Code: Select all

source/py_gpio.c:23:20: fatal error: Python.h: No such file or directory
 #include "Python.h"
                    ^
compilation terminated.


any idea what to do?
thank you
I have found, that "sudo apt-get install python-dev" helps with #include "Python.h" problem

Than i runned "python setup.py install" but still getting error in python:

Code: Select all

import RPi.GPIO as GPIO
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "RPi/GPIO/__init__.py", line 23, in <module>
    from RPi._GPIO import *
ImportError: No module named _GPIO


with import RPi._GPIO getting same error
I do not know why, but if you run python from the directory that contains the RPi.GPIO code gives that error. You must change directory before running python. The sequence would look like this:

Code: Select all

git clone https://github.com/auto3000/RPi.GPIO_NP
cd RPi.GPIO_NP
python3 setup.py install
cd ..
python3


Code: Select all

 >>> import RPi.GPIO as GPIO

Who is online

In total there are 6 users online :: 0 registered, 0 hidden and 6 guests (based on users active over the past 5 minutes)
Most users ever online was 5185 on Wed Jan 22, 2020 1:44 pm

Users browsing this forum: No registered users and 6 guests