Python Forum
Venv - Python Virtual Environment on Raspberry Pi
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Venv - Python Virtual Environment on Raspberry Pi
#1
I try to follow a book and also Pythons document page to get a venv to work.
The install works but when I want to get a library through pip and I think it
works so far but when I wont to use the library it do not work. I get an answer
that the module do not exist.

Output:
(robot-venv) danne@RPi-robot:~ $ which python /home/danne/robot-venv/bin/python (robot-venv) danne@RPi-robot:~ $ python Python 3.11.2 (main, Apr 28 2025, 14:11:48) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from adafruit_crickit import crickit Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/danne/robot-venv/lib/python3.11/site-packages/adafruit_crickit.py", line 29, in <module> import board File "/home/danne/robot-venv/lib/python3.11/site-packages/board.py", line 48, in <module> from adafruit_blinka.board.raspberrypi.raspi_4b import * File "/home/danne/robot-venv/lib/python3.11/site-packages/adafruit_blinka/board/raspberrypi/raspi_4b.py", line 6, in <module> from adafruit_blinka.microcontroller.bcm2711 import pin File "/home/danne/robot-venv/lib/python3.11/site-packages/adafruit_blinka/microcontroller/bcm2711/pin.py", line 7, in <module> from adafruit_blinka.microcontroller.generic_linux.rpi_gpio_pin import Pin File "/home/danne/robot-venv/lib/python3.11/site-packages/adafruit_blinka/microcontroller/generic_linux/rpi_gpio_pin.py", line 6, in <module> from RPi import GPIO ModuleNotFoundError: No module named 'RPi'
I have been reading and doing uninstall and install many times in different ways but
get the same "ModuleNotFoundError:". I have lookup in adafuit for the Crickit and it
all show how to install and go on but it is not working.
When I follow the install in Python's document it gets the same. Is it more that is wrong,
when the output writes this "line x, in <module>" on the rows? Is that wrong also?

What is wrong???
Reply
#2
while your virtualenv is active, type from command line: pip list
do you see the rpi package in the list?
if not reinstall, making sure virtual environment is activated
Reply
#3
I’m jumping in here. I ran into the same error before. The problem seems to be with the RPi.GPIO module isn’t installed inside the virtual environment.

While the venv is active, try running:

bash
Copy
Edit
pip install RPi.GPIO
If that doesn’t fix it, the library might only be available system-wide. You could try:

bash
Copy
Edit
sudo apt install python3-rpi.gpio
But that installs it outside the venv. Not perfect, but it might help for testing. Let me know if that works for you.
Reply
#4
I may be wrong, but when I look around, the import should be:

import RPi.GPIO 
(Note the small i in RPi) or

import RPi.GPIO as GPIO
or as any alias you like.

The OP has:

from RPi import GPIO
No raspberries here!
Reply
#5
Pedroski55 Wrote:I may be wrong, but when I look around, the import should be:
Pedroski55, You are correct, didn't catch that one.
The import should definitely be
import RPi.GPIO
or
import RPi.GPIO as GPIO
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Start Idle in a virtual environment Pedroski55 8 3,296 Jun-02-2025, 05:53 AM
Last Post: Pedroski55
  Python automation: Sending clicks/keys to VMware virtual machine from host olips784 0 1,207 May-18-2025, 06:28 PM
Last Post: olips784
  How does venv update $PATH without activating on Windows? bottomfeeder 3 2,103 Mar-13-2025, 01:46 PM
Last Post: DeaD_EyE
  Python use of virtual environments bre67e49 4 1,742 Feb-19-2025, 04:01 AM
Last Post: Sece1967
  Building specific Python version on Raspberry PI 5 (Raspbian) andrewk 2 1,918 Feb-03-2025, 11:41 AM
Last Post: iterate
  I cannot create a virtual environment on visual studio code using python Willem_Aucamp316 2 12,166 Nov-27-2024, 02:20 PM
Last Post: menator01
  How to enable Matplotlib within virtual environment? tetris_theMovie 1 1,942 Oct-11-2024, 09:56 AM
Last Post: christie2
  JenkinsFile to create a Python venv NikitaMathur 2 3,194 Sep-23-2024, 11:33 AM
Last Post: NikitaMathur
  raspberry pi in a python script Raysz 5 2,334 Jun-08-2024, 07:04 PM
Last Post: jefsummers
  Troubleshooting Jupyter Notebook installation with Python using pip and a venv Drone4four 1 5,362 Jun-04-2024, 10:55 PM
Last Post: Drone4four

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.