Enviro+ issue: python and python 3

Hi

I am a relatively novice user and am currently trying to set up my Enviro+.

I have had problems with installing bme280. Following the “Getting started article” on Pimoroni for the enviro+ seemed to install everything but I encountered an error when running the all-in-one.py script
from bme280 import BME280
Traceback (most recent call last):
File “”, line 1, in
ImportError: cannot import name BME280

I have researched the error and uninstalled enviroplus from the pi. Then reinstalled it using the curl install mentioned on this forum. I also installed the libraries to Python3.

What I have come to realise is that the line of code “from bme280 import BME280” runs fine from the Python3 shell, but not from the Python shell. I cannot run the enviroplus python code from a Python3 shell as it is not formatted correctly.

Could anyone provide further guidance on getting the bme280 libraries running. The module is definitely installed on the Pi.

Thank you

Do you want to use Python2 or Python3?

I use Python3 for everything as Python2 went end of life in January. To install things for Python3 I use pip3 instead of pip.

I use the bme280 library from Python3 without problems. When you say the examples aren’t formatted correctly for Python3 can you be more specific. It should be an easy fix.

Thanks for the reply. Yep I agree Python 3 makes sense.

I am referring to the example python scripts that pimoroni supply for the enviro+ board. There are several very useful scripts that enable readings from the sensors to display on the LED screen.

I guess I may need to reformat them into python 3 scripts as they are currently python 2. Unless I can get the bme280 library working

IIRC I had to change a lot of divides from / to // to make the examples work in Python3. I think 2 always produces an integer when two integers are divided by 3 produces a fraction so // has to be used to force an integer result like 2.

Still wondering why the bme280 line of code
From bme20 import BME280

Won’t run in python 2. As this is what is suggested in the enviro+ tutorial.

If you type

pip2 list | grep bme

do you get something like

pimoroni-bme280 0.0.1

Yep, I get
bme 280 0.5
pimoroni-bme280 0.0.2

Looks like you have two bme280 libraries installed. Perhaps the non-pimoroni one doesn’t have the BME280 constructor. You could try

pip2 uninstall bme280

Also I noticed that the pimoroni github for the Enviro+ was updated for Python3 today.