python-sense-hat: Sense Hat can't find RTIMU after upgrade to Python 3.5.2

I recently upgraded the GNU R packages from 3.1.1 to 3.3.1. To do this, I had to add the stretch distribution to my /etc/apt/sources.list file. In the process of successfully upgrading GNU R, apt also chose to install an upgraded version of Python3. Now when I try to use the Sense Hat module with Python3, I get the following error message:

`Python 3.5.2+ (default, Sep 22 2016, 12:18:14) [GCC 6.1.1 20160802] on linux Type “copyright”, “credits” or “license()” for more information.

from sense_hat import SenseHat Traceback (most recent call last): File “<pyshell#0>”, line 1, in <module> from sense_hat import SenseHat File “/usr/lib/python3/dist-packages/sense_hat/init.py”, line 2, in <module> from .sense_hat import SenseHat, SenseHat as AstroPi File “/usr/lib/python3/dist-packages/sense_hat/sense_hat.py”, line 10, in <module> import RTIMU # custom version ImportError: No module named ‘RTIMU’ `

pip3 reports that sense-hat 2.2.0 and RTIMUlib 7.2.1 are installed. I do NOT get this error when I use Python 2.7.9.

Any ideas on what got broken during the apt-get install of r-base? It was working fine before the GNU R upgrade.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (4 by maintainers)

Commits related to this issue

Most upvoted comments

As it’s not very clear in that thread, I’d like to share what I did. Basically following bennuttall recommendation did the trick:

  • Create a virtualenv:
    • virtualenv -p /usr/bin/python3 ~/.ve/sensorhat
    • source ~/.ve/sensorhat/bin/activate
  • Clone RTIMULib:
    • git clone https://github.com/RPi-Distro/RTIMULib/ RTIMU
    • cd RTIMU/Linux/python
  • Follow instruction in RTIMULib/Linux/python:
    • sudo apt install python3-dev
    • python setup.py build
    • python setup.py install
  • Install libopenjp2-7:
    • sudo apt install libopenjp2-7
  • Install sense-hat:
    • sudo apt install sense-hat

That should do the trick. Some code like this should work:

from sense_hat import SenseHat

sense = SenseHat()
print('temperature', float(sense.get_temperature()))
print('humidity', float(sense.get_humidity()))
print('pressure', float(sense.get_pressure()))

That’s very nice of you! I just tested successfully with:

sudo apt install libopenjp2-7 sense-hat
pip install sense-hat rtimulib

That seem to be sufficient, libtiff-tools is installed as a sense-hat dependency and I didn’t need libatlas-base-dev at all. Hope this helps!

I’m getting “PyRTIMU.h: No such file or directory” with the above suggestions.

same problem, with python3.8 on a PRi-2 in a virtual environment the pip install RTIMULib return with an error

Running setup.py install for RTIMULib ... error
    ERROR: Command errored out with exit status 1:
     command: /var/www/lab_app/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-jd0jlh8r/RTIMULib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-jd0jlh8r/RTIMULib/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-3l18gjw7/install-record.txt --single-version-externally-managed --compile --install-headers /var/www/lab_app/include/site/python3.8/RTIMULib
         cwd: /tmp/pip-install-jd0jlh8r/RTIMULib/
    Complete output (12 lines):
    running install
    running build
    running build_ext
    building 'RTIMU' extension
    creating build
    creating build/temp.linux-armv6l-3.8
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -DHAL_QUIET -I../../RTIMULib -I/var/www/lab_app/include -I/usr/local/opt/python-3.8.2/include/python3.8 -c PyRTIMU.cpp -o build/temp.linux-armv6l-3.8/PyRTIMU.o -std=c++0x
    PyRTIMU.cpp:28:10: fatal error: PyRTIMU.h: Bestand of map bestaat niet
     #include "PyRTIMU.h"
              ^~~~~~~~~~~
    compilation terminated.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /var/www/lab_app/bin/python3.8 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-jd0jlh8r/RTIMULib/setup.py'"'"'; __file__='"'"'/tmp/pip-install-jd0jlh8r/RTIMULib/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-3l18gjw7/install-record.txt --single-version-externally-managed --compile --install-headers /var/www/lab_app/include/site/python3.8/RTIMULib Check the logs for full command output.

Has anyone gotten this to work? I’m hitting this same issue when trying to dockerize sense-hat

As it’s not very clear in that thread, I’d like to share what I did. Basically following bennuttall recommendation did the trick:

  • Create a virtualenv:

    • virtualenv -p /usr/bin/python3 ~/.ve/sensorhat
    • source ~/.ve/sensorhat/bin/activate
  • Clone RTIMULib:

    • git clone https://github.com/RPi-Distro/RTIMULib/ RTIMU
    • cd RTIMU/Linux/python
  • Follow instruction in RTIMULib/Linux/python:

    • sudo apt install python3-dev
    • python setup.py build
    • python setup.py install
  • Install libopenjp2-7:

    • sudo apt install libopenjp2-7
  • Install sense-hat:

    • sudo apt install sense-hat

That should do the trick. Some code like this should work:

from sense_hat import SenseHat

sense = SenseHat()
print('temperature', float(sense.get_temperature()))
print('humidity', float(sense.get_humidity()))
print('pressure', float(sense.get_pressure()))

This helped a lot, thank you so much 👍

I have uploaded a test copy of RTIMULib to PyPI in order to make this process simpler.

You can now pip install rtimulib in a virtualenv, and as long as you have the other requirements you stated, it works. However, I seemed to need libatlas-base-dev, libopenjp2-7, libtiff-tools and sense-hat.

Once this is confirmed and tested properly I’ll push out a new sense hat version to pypi including the dependency on rtimulib, and document the process required for using in a virtualenv.