ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm quite the novice in regards to python and especially in regards to using its modules but am now dabbling in it for a casual weekend project. I generally stay with whatever is in the official Raspberry Pi OS repositories exclusively and have avoided adding anything via pip3 until now.
However now that I have used pip3, I am getting all kinds of problems with scripts old and new. The first problem is that the modules are not usable from normal accounts.
Code:
$ ./bmp280-demo-01.py
Traceback (most recent call last):
File "./bmp280-demo-01.py", line 6, in <module>
import board
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 724, in exec_module
File "<frozen importlib._bootstrap_external>", line 859, in get_code
File "<frozen importlib._bootstrap_external>", line 916, in get_data
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.7/dist-packages/board.py'
$ ls -lh /usr/local/lib/python3.7/dist-packages/board.py
-rw-r----- 1 root staff 9.4K Aug 29 11:01 /usr/local/lib/python3.7/dist-packages/board.py
$ sudo bash -c umask
0027
How or why do the packages which were installed via pip3 end up not usable by general accounts? I presume the umask is what's wrong. What is the most efficient way to fix that? I hope not by manually applying chmod to all the files and directories.
I guess you can try to reinstall that module (pip3 install --reinstall <module> - or something similar) (as root), but first you need to set umask properly.
The other way could be to install it as your user, for your user.
That looks like the right direction. I'm still working through all the dependencies and such but the first step was to re-install everything. Apparently pip3 is not for scripting and gives a warning about the 'right' way to do it which is to invoke the interpreter with the -m option instead:
Code:
# umask 0022
# time { for m in $(pip3 list | awk 'NR>2{print $1}')
do python3 -m pip install -U ${m} --force-reinstall
done }
It takes while.
Last edited by Turbocapitalist; 08-29-2021 at 06:40 AM.
Reason: Edit: use the right pip formula
The re-installation seems to have been the main obstacle. Once that was out of the way, it was possible to track down various dependencies. The dependencies could usually be found by running the interpreter and going through various steps and then, once a missing file was noted, look up which package the file should belong to.
The re-installation seems to have been the main obstacle. Once that was out of the way, it was possible to track down various dependencies. The dependencies could usually be found by running the interpreter and going through various steps and then, once a missing file was noted, look up which package the file should belong to.
You might already know this, but in case not... modules often come as a WHL file, which is a structured zip file, and contains a "modulename.dist-info/METADATA" which is where dependencies are listed (as Requires-Dist lines), for which you can then download the relevant WHLs from pypi.org and repeat.
(If it's .tar.gz, there might be a "modulename.egg-info/requires.txt" instead.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.