1

I have created a virtual enviroment on my RPI3 (Raspbian-Jessie), so that I may more easily work with a particular image-searching software (as outlined in this tutorial, step #4).

My script requires a module, "smbus", to use I2C while running a python 2.7 script in my virtual environment.
The issue is that I can't import the module when the environment is activated, and I can't install in within the environment.

Code:

import smbus

Shell:

(cv) pi@raspberrypi:~ $ python i2ctest1.py
Traceback (most recent call last):
File "i2ctest1.py", line 1, in <module>
import smbus
ImportError: No module named smbus

It will however import just fine outside that "cv" environment. I can see the module installed:

pi@raspberrypi:~ $ pip freeze
[...]
smbus==1.1
[...]

But inside the environment, smbus is not there:

(cv) pi@raspberrypi:~ $ pip freeze
imutils==0.3.6
numpy==1.11.1
picamera==1.12
Shapely==1.5.17
spidev==3.2

I tried installing smbus with the environment activated, but it just tells me it is already installed:

(cv) pi@raspberrypi:~ $ sudo apt-get install python-smbus
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-smbus is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 96 not upgraded.

I also tried :
(cv) pi@raspberrypi:~ $ sudo pip install smbus

resulting in:

Requirement already satisfied (use --upgrade to upgrade): smbus in /usr/lib/python2.7/dist-packages
(cv) pi@raspberrypi:~ $ sudo pip install smbus --upgrade
Requirement already up-to-date: smbus in /usr/lib/python2.7/dist-packages

I read this link on virtual environments, but I was not able to understand what I've done wrong.

Do I need to install the module differently, or do I just need to import it differently?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.