Welcome to DOFBOT-JetsonNANO repository
3.Python virtual environment
Python virtual environment
Python virtual environmentPython virtual environmentCreate a virtual environmentActivate virtual environmentInstall the third line packageExit the virtual environmentThonny EditorChange the virtual environment Python version
In previous versions of the operating system, the program could be installed using Python's pip tool:
$ pip install buildhat
But in newer versions of Raspberry Pi OS systems, this is not allowed; if you try to install a Python package system-wide, you will receive an error similar to the following:

xxxxxxxxxxWe used another method to eliminate this warning when building the jupyter lab environment, but here we only introduce how to build a python virtual environment.
Python virtual environment
To use a virtual environment, you need to create a container to store the environment.
Create a virtual environment
Create and enter the Demo_Project folder, then use Python's built-in module venv to create a virtual environment named env:
xxxxxxxxxxmkdir Demo_Projectcd Demo_Projectpython -m venv env

After the operation is successful, there will be an additional env folder under the folder.
Activate virtual environment
In this directory is a complete Python distribution; activate the virtual environment and make this Python version the currently used version:
xxxxxxxxxxsource env/bin/activate

At this point, we are no longer using the system Python, but the version of Python included in the virtual environment:
Any changes made here will not cause problems for your system Python;
Any new modules installed into the environment will also not affect system Python.
Install the third line package
xxxxxxxxxxpip install jupyterlab

View the modules installed by the current Python version:
xxxxxxxxxxpip list

Exit the virtual environment
xxxxxxxxxxdeactivate

Thonny Editor
When using Python on the Raspberry Pi, Thonny is the system default editor and the interpreter uses the system Python.
Change the virtual environment Python version

Click the interpreter menu in the lower right corner of the Thonny interface to switch to the Python virtual environment: Add according to the virtual environment path

Configuration successful:
