Python Virtual Environment on Raspberry Pi Explained (surprisingly well!)

Adafruit (famous for clearly written tutorials) has, today, just dropped this rather good (IMO) explanation of Python Virtual Environment on Raspberry Pi. It is actually a simple-ish trick to temporarily (via “activate”) change the Python path from the usual “/usr/bin” to whatever you tell venv, e.g. “/home/pi/my_virtual_env/bin” and then back to the usual with “deactivate”.

Very clever and relatively easy to understand once you know the trick (like a lot of things). Also a timely appearance of this tutorial, considering the recent discussions on this topic! Check it out! :sunglasses:

3 Likes

It really is a great introduction to Python Virtual Environments, for sure.

Ah, but when Python Virtual Environment meets “GoPiGo3 the robot reality”, the problems begin. When you add ROS to the picture, nothing is standard, nothing works, and no one has boldly gone before.

To use code running in a Python virtual environment with ROS or ROS2 requires both a Python super-guru AND a ROS/ROS2 super-guru.

Sadly, we are nearly alone in the GoPiGo3 robot reality.

3 Likes

Can someone tell me why in the name of all that is holy and sacred, why these idiots decided to mandate containers for Python?  This makes about as much sense as mandating double-breasted pinstripe zoot-suits for Python.

This is something that they KNOW, (or should have known), is going to break half the known universe!

99.99999…999…999% of the GoPiGo is implemented as Python scripts.  So, what do we do?  Cap the allowable version at a pre-container version?

This is BULL :poop: !!!

One would hope that they allow non-containerized applications.  Otherwise just about everything I have done so far is IN THE DUMPER.

:face_with_symbols_over_mouth: :face_with_symbols_over_mouth: :face_with_symbols_over_mouth: :face_with_symbols_over_mouth: !!!

Maybe I should go on the Python forums and make a nuisance of myself?

2 Likes

Well, I hate it too (but less so, now that I better understand how it is implemented) but it seems due to the fact that Python, for a long time, has been both [1] the language of choice for the proper functioning of Linux distros and [2] the language of choice for all manner of developers.

This is inherently a conflict where a developer can use pip to change Python inside of the historically only location, /etc/bin, and thereby damage the Linux distro itself on that machine. Personally, I think it is crazy that this is even possible. It would be like me upgrading Visual Studio to a more recent version of C# and damaging the Windows operating system. Yikes!

See the following PEP (cited in the above Adafruit tutorial as well) which gives more details (I have only skimmed it so no quizzes please).

Interestingly, in the more recent “PEP 704 – Require virtual environments by default for package installers” a harder line was taken. That PEP was later withdrawn.

2 Likes