Can't install python packages using pip on the RaspberryPi

When trying to install using pip on the pi I got this error:

$ pip install buildhat
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
  python3-xyz, where xyz is the package you are trying to
  install.

  If you wish to install a non-Debian-packaged Python package,
  create a virtual environment using python3 -m venv path/to/venv.
  Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
  sure you have python3-full installed.

  For more information visit http://rptl.io/venv

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

This is a new feature by the Python community.
See additional data on the Raspberry Pi forum: About Python virtual environments

Tips:
Note that you can override this by using the –break-system-packages flag.
When building a new virtual environment add the –system-site-packages
If you want to still use the python packages installed on the Pi “system” python (you probably do… for accessing the picamera for example)
CLI example:

python -m venv /path/to/new/virtual/environment --system-site-packages

If I were you, I would you follow the advice that is in the text and do this within a virtual environment.

It’s worth googling python virtual environments and why they’re a good idea if you’re not familiar with them.

If you really know what you’re doing and have a compelling reason to install this for your system python then you possibly can do it with sudo but that’s generally not needed nor a good idea (despite the number of older pieces of advice suggesting sudo pip install xyz…)

Hi Neil, great to have you in our community!
You are right, the way to go is to setup a virtual environment as described in the end of my last post.
Be sure to add the --system-site-packages flag if you want to have Hailo and RPi’s Python bindings available for your project.

1 Like

Thanks for the welcome. Glad to be here.

I’m sorry, I originally read your post as a problem you were asking about for yourself, didn’t realise you were actually from Hailo and somehow didn’t see you’d included those details at the end as a solution, so I started answering :slightly_smiling_face:

1 Like