Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1269

Python • Re: How to get Python to use a custom library path

$
0
0
You completely miss the point of what Python venvs are for.

[. . . .]

This has now gone WAY off topic. But hopefully it sheds some light on why some things are the way they are even if it's initially inconvenient at first.
This is the best and most lucid treatment of venv's that I've seen.

As for me. . . .

With the exception of VMware on a PC, I've never had to mess with containers, venv's, or even operating systems for the largest part of my career, as things like aircraft cockpit instruments or spacecraft guidance systems don't use one. (Or didn't, I don't know what they're doing now - they could be running Linux Mint with a GUI for all I know. :facepalm:)

With me it was 99% bare metal. A processor chip, memory, I/O, and whatever specialized hardware you needed and a dev environment, (such as it was - I still remember running ASM on a Kaypro II using CPM, transmitting Intel hex records, (in ASCII), to an EPROM burner via a RS232 serial cable). Later on there were dev systems that ran C, then C++, but much was still bare metal assembler which was my specialty.)

Later on, with personal computers taking over engineering environments, my main task was still "get this strange piece of hardware HERE to talk to the software/system way over THERE" - and it was all low-level code. A Borland C compiler was a godsend!

A lot of this is new to me, and being retired I don't have the 2+ hour train ride each way to catch up on my reading. (Now it's the endless "honey-do" list so I have even less time!)

Most of the stuff I see on YouTube appears to be just punters and wannabees babbling nonsense, so I don't normally use that as a resource. (The "funny cat" videos often make more sense.)

I got myself a robot to help me get involved with things again, and I feel like I'm swimming against the tide. . . (:banging head against wall:)

I don't know if it's possible, but this is a discussion I would love to take off-line with you.

Thanks!

P. S.
If you don't mind, I would really like to copy your entire post and paste it in the Dexter GoPiGo forums.
Sorry for the delay, I've been a bit under the weather. Got covid, then covid rebound (basically it came back 3 days after feeling great again), and I've been feeling really tired since. So I have not spent much time in front of the computer other than during work hours. But starting to feel better again, so...

It took me sometime to start appreciating what venvs and containers give you, but once you start working with either, you'll neve want to go back. Because the possible issues you'll run into while using them is totally isolated to that venv/container and cannot be caused by anything else running beside it.

The obvious exception is your container will break if you do something to the docker installation in the host, but that's to be expected. But one container will not break another.

Same for venvs. In Linux, the python interpreter and other binaries in venv/bin are soft links to the actual binaries, be them the default system interpreter or an additional one installed beside it. But again, the only way to break your venv at this point, is to muck around with the underlying python installation, and not one venv breaking another.

It's also worth noting that Python no longer supports pip install --user which was an alternative to installing things at the user level while leaving the system alone. This still had the same issue as breaking the system, except you'd break things at the user context. It was the same as having just one venv for all your projects, as a certain official Pi set of instructions suggests the user do, or at least used to suggest it. You just one one venv being stepped on by all of your python projects.

Going back to pip install --user, that was solved with, drum rolls please........ you guessed it venv!


As for posting my stuff on that other board, sure, I don't mind. Just keep in mind that it probably has lots of grammar and spelling mistakes. I wrote all of that on my phone and auto correct is not kind. Or you could just link it there to here. Your choice.

Here's one more experiment I think you'd appreciate when it comes to PYTHONPATH and how venvs work. Remember my previous screenshots showing PYTHONPATH with python 3.10 and 3.11? Compare it to using python 3.10 and a python 3.10 venv activated.
2024.07.10_16.33.06.jpg
Looks exactly the same. And if you create teh venv with flag to use system packages, then that path will be there too in addition to the venv's folder one, but it'll come after so it looks in your venv first.

All a venv does is make those path settings. You can see exactly how it modifies all the paths and variable by reading the activate script in your venv/bin directory.

Statistics: Posted by memjr — Wed Jul 10, 2024 8:36 pm



Viewing all articles
Browse latest Browse all 1269

Trending Articles