diff --git a/index.html b/index.html new file mode 100644 index 0000000..dc0bd5f --- /dev/null +++ b/index.html @@ -0,0 +1,113 @@ + + + + Python Virtual Environments on Raspberry Pi Bookworm + + + + +
+

Python Virtual Environments on Raspberry Pi Bookworm

+
+
+
+
+

What's a virtual environment?

+
+
+

+ While having to care about Python virtual environments + is a bit of a bump in the road to getting started with + Python they're not just a nuisance foisted upon you by + curmudgeonly Linux distribution maintainers. +

+

+ A virtual environment is a useful, logical way of + isolating your project dependencies from each other and + ensuring things don't break when there are conflicts.. +

+

+ What happens if you create a new project using Library + v2, but you have old projects that only work with Library + v1? Bad things, that's what. A virtual environments mean + you can just spin up a clean environment for your new + project and never have to worry about breaking or updating + your old ones. +

+ They are also a great way for a user to install and use + your project without affecting their other Python + environments. +

+
+
+
+
+

Why do I need one?

+
+
+

+ As of Raspberry Pi OS bookworm, you'll get a slap on the + wrist in the form of an error message if you attempt to + pip install any Python libraries on your + Raspberry Pi. +

+

+ It looks something like this: +

+ $ 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. +

+ The "TLDR" (too long, don't read) of this message is that + installing libraries from pypi (which is what pip does) + into your system can cause all sorts of here-be-dragons + weirdness and breakage. So it's recommended against. +

+

+ Instead, you use a virtual environment which is just + a bunch of monkeying with paths to ensure your Python + project dependencies are completely self-contained, and + isolated from the system and each other. +

+
+
+
+
+

Okay, that sounds tedious. Make it easy for me!

+
+
+
+
+ + +