Raspberry Pi is a Single Board Computer (SBC) developed by Raspberry Pi Foundation. It has Broadcom SOC at its heart. IT primarily runs on Linux.
Its Linux Distribution is based on the Debian customised for Rasoberry-Pi and hence called as Raspbian.
The native python envronment of Raspbian OS is protected and we cant install new packages/ modules using pip in the native environment.
We need to create virtual environment of python so as to install python modules using pip
To create Virual Environment of python in Raspberry Pi
-
Open the terminal by Pressing
Ctrl+Alt+T -
Type the following command to create new virtual environment
python3 -m venv --system-site-packages .venv -
set the Thonny to use newly created virtual environment
- Open Thonny, and click on Switch to regular mode on right top corner, then restart the thonny
- Go to Tools->Options-> Interpreter and click on three dots (...) button Brows to .venv/bin/python3.xx [XX will be replaced by python versionistalled on your system] file and click on OK
- Again Click on OK to close the tools window
- Restart the Thonny again
Before installing the python packages make sure that you hace seup the python virtual environment on the system.
Open the Terminal by pressing CTRL+ALT+T
The terminal will get open on your screen but it will refereing to the default local python environment, which is protected in nature and will not allow you to install any third party package by using pip.
So we need to activate the virtual environment we have created earlier. To do so, type the following command in the terminal
source .venv/bin/activate
After you type the command, hit Enter button and you will see (.venv) before the command prompt of the terminal.
This will indicate that, virtual environment is activated and your terminal is now refering to the virtual environment.
In simple words, whatever commands you will enter in the terminal are executed in the virtual environment and will not affect the local python environment.
Now you are all set to install the third-party packages. Use the following commands to install respective module in virtual environment.
pip install adafruit-circuitpython-ads1x15
pip install pyfingerprint
pip install pynput
pip install paho-mqtt
