No such file smbus(1) when tryin to run the envirophat example on raspberry pi 2

hi

Im trying to run this code:

from envirophat import light

from the pimoroni site here:

but i get this error:

**mars@raspberrypi**:**~/Desktop $** python

Python 3.9.2 (default, Mar 12 2021, 04:06:34)

[GCC 10.2.1 20210110] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> from envirophat import light

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

File "/usr/local/lib/python3.9/dist-packages/envirophat/__init__.py", line 1, in <module>

from .i2c_bus import bus

File "/usr/local/lib/python3.9/dist-packages/envirophat/i2c_bus.py", line 20, in <module>

bus = smbus.SMBus(1)

FileNotFoundError: [Errno 2] No such file or directory

>>>

I already ran:

curl https://get.pimoroni.com/envirophat | bash

and got the All done. Enjoy your Enviro pHAT! message after install.

Is that a retired item? I’m not seeing it on the shop page?
Anyway, one option is to try the Manual install from here,
pimoroni/enviro-phat: Python libraries and examples for the Pimoroni Enviro pHAT (github.com)

Yeah, that install command | bash, ive run before. I just ran it again and I even see this:

Checking environment...
Updating apt indexes...
.....................

Checking hardware requirements...

Checking for packages required for GPIO control...
raspi-gpio is already installed
RPi.GPIO installed and up-to-date

I2C already enabled

Checking packages required by I2C interface...
Python 2 smbus installed and up-to-date
Python 3 smbus installed and up-to-date

Enviro pHAT comes with examples and documentation that you may wish to install.
Performing a full install will ensure those resources are installed,
along with all required dependencies. It may however take a while!

Do you wish to perform a full install? [y/N] 

which is telling me that the. smbus for python3 are up to date.

I tried the manual install, same problem…

I had this code on an rpi0 and I noticed one of the files on the desktop called shenviro.sh:

#!/bin/bash

/usr/bin/python3 /home/mars/envirophat2.py >> /home/mars/envirolog.log

i think i had some other code running the actual script (which is envirophat2.py) but I just cant remember. Maybe it had something to do with creating an environment for it to run in?

There are other commands you can run, other than the curl command. Go down the page a little and it lists them. It does the equivalent of the curl command, but with much more manual steps.

Thanks, yeah so I tried all of them:

sudo apt-get install pimoroni

**mars@raspberrypi**:**~ $** sudo apt-get install pimoroni
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package pimoroni
sudo apt-get install python3-envirophat

**mars@raspberrypi**:**~ $** sudo apt-get install python3-envirophat
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
python3-envirophat is already the newest version (1.0.0).
0 upgraded, 0 newly installed, 0 to remove and 42 not upgraded.
sudo pip3 install envirophat

**mars@raspberrypi**:**~ $** sudo pip3 install envirophat
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: envirophat in /usr/local/lib/python3.9/dist-packages (1.0.1)
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (from envirophat) (0.7.0)
Requirement already satisfied: setuptools>=30.4.0 in /usr/lib/python3/dist-packages (from envirophat) (52.0.0)

but no cigar! :-(

I’d say its time to Contact Us for Raspberry Pi Technical Support - Pimoroni

sudo’ing all those installs won’t install them into your python virtenv; try the pip3 flavour without the sudo, while running in your virtenv - that should then get installed in the right place.

How do I run those commands in virtual environment?

My bad; I’d blurred two different threads - ENOENT on SMBus would normally indicate that you haven’t got your i2c enabled, but the script output further up implies that that’s already done.

What does i2cdetect -y 1 show?

hi, thanks. I get the following:

**mars@raspberrypi**:**~ $** i2cdetect -y 1

Error: Could not open file `/dev/i2c-1' or `/dev/i2c/1': No such file or directory

That error looks to me a lot like you don’t have I2C enabled - try running

sudo raspi-config nonint do_i2c 0

in a terminal (or you can enable I2C in the graphical Raspberry Pi Configuration utility)?

YES! Thank you so much! I got it to work and i was able to run my python file and log data to my thingspeak account. Unfortunately, the water damage that killed by rpi0, seems to have damaged the envirophat board as well and most readings came back with value 0.

the temperature value was one of only ones that came back with non-zero values. So i guess I have to get a new hat.

In the meantime, could I bother to ask how i can view my rpi0 crontab or the other files that are normally used to start up jobs in rpi automatically? The way i had it running on my rpi0 is that it would log data every 5 minutes i believe. And even with power outs, which are frequent, it would resume logging as soon as power was restored and it rebooted. Im leaning towards crontab but it could be rc.local. I have my old rpi0 sd card in a usb port on my new rpi so i just need to know where to look…

I looked in rc.local and .bashrc and init.d directory and /etc/crontab/ but. didnt find anything.

I did notice i had a file on the desktop along with the actual python script called shenviro.sh which contains. this:

/usr/bin/python3 /home/mars/envirophat2.py >> /home/mars/envirolog.log

But i think that just logs errors, doesnt it?

FOUND IT. Its tricky navigating another drive on linux if you dont use absolute paths. I was checking my rpi directories instead of the usb-sd card one.

thanks in advance

1 Like