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

Python • Re: DS18B20 / w1thermsensor

$
0
0
"this environment is externally managed".means you are executing the command in a terminal with the venv not activated.
I actually was executing the pip with the venv activated. I had created the venv without copying over the main package distribution. So I recreated it doing that copy-over and then the install succeeded. It gave a warning that the package had been installed in /home/pi/.local/bin and I should add that to my $PATH., which I did.

Strange (at least to this Linux noob) is that now my Python programs that use the sensor work WITHOUT having the venv activated. (???) It's like the venv was only needed for the install. Does that make sense?

I look in /home/pi/.local/bin and the only file there is: w1thermsensor, of type plain text, and here is what it contains:

Code:

#!/home/pi/Documents/HVAC/env/bin/python# -*- coding: utf-8 -*-import reimport sysfrom w1thermsensor.cli import cliif __name__ == '__main__':    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])    sys.exit(cli())
I'm glad it works but sure don't understand it!

I don't know what this file is called (maybe you posted the name somewhere up there and I just did not look), but it is a python entry point script which wraps the actual execution of a python script with something akin to

Code:

sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
This has the effect of always using that virtual environment's python version, even if I have not "activated" the environment or messed with my path in any way.

If you edit that script from this:

Code:

#!/home/pi/Documents/HVAC/env/bin/python# -*- coding: utf-8 -*-import reimport sysfrom w1thermsensor.cli import cliif __name__ == '__main__':    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])    sys.exit(cli())
I'm glad it works but sure don't understand it!
[/quote]

to this:

Code:

#!/home/pi/Documents/HVAC/env/bin/python# -*- coding: utf-8 -*-import reimport sysfrom w1thermsensor.cli import cliif __name__ == '__main__':    print("before", sys.argv)    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])    print("after", sys.argv)    sys.exit(cli())
Then execute it from a terminal, it will show you what it is doing.

Here's a nice simple read on python entry points and you can code along if you don't want to just read it (I learn better with code alongs) https://amir.rachum.com/python-entry-points/

For a more technical short background on it https://packaging.python.org/en/latest/ ... ry-points/

Statistics: Posted by memjr — Sat Aug 03, 2024 4:59 pm



Viewing all articles
Browse latest Browse all 4906

Trending Articles