Your notebook has an active venv when you install the packages so when you run it it works.I used the following command in a .ipynd file: %pip install RPi.GPIO.
When I ran import RPi.GPIO in the notebook it runs perfectly. However, when I ran the same command in a .py file I get:
ModuleNotFoundError: No module named 'RPi'
in the terminal.
The weird thing is that when I ran import mfrc522 it runs on both the python file and the notebook.
I am very confused. Do you know why this is happening?
For the python file to work it also needs to be in an active venv with the packages installed. You can use the same one used by the notebook, or you can create a new one and use that. Regardless, you need to activate the correct venv where things are already installed before you can run any python script that tries to use things in the venv.
This is one of those things that you need to understand how it works. It's all well and good to follow some guides in the internet and get something working, but if you do not understand how it works, the minute you try to change it or make use of it somewhere else it'll stop working and you'll be all confused.
You need to read about what a python virtual env is, what they are used for and all of that. Start here: https://realpython.com/python-virtual-e ... -a-primer/
Statistics: Posted by memjr — Thu Dec 14, 2023 4:54 pm