Skip to content

Python - virtual environments - optional use of "--system-site-packages" #3220

@DeeJay

Description

@DeeJay

Ref: https://www.raspberrypi.com/documentation/computers/os.html#python-on-raspberry-pi

Perhaps add a mention of the potential need for "--system-site-packages" when invoking venv?

For example, the recommended python api for wrangling gpio pins is gpiozero. This is installed system-wide via apt by default. It is then not available from within a venv environment by default.

This might be confusing/frustrating to a beginner?

Example -

david@rp5bw101064fssk:~/Projects $ python -m venv NoSite
david@rp5bw101064fssk:~/Projects $ source NoSite/bin/activate
(NoSite) david@rp5bw101064fssk:~/Projects $ python
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gpiozero
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gpiozero'
>>>
(NoSite) david@rp5bw101064fssk:~/Projects $ deactivate
david@rp5bw101064fssk:~/Projects $ python -m venv --system-site-packages PlusSite
david@rp5bw101064fssk:~/Projects $ source PlusSite/bin/activate
(PlusSite) david@rp5bw101064fssk:~/Projects $ python
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gpiozero
>>>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions