LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-29-2021, 04:58 AM   #1
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,787
Blog Entries: 3

Rep: Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007
Python module via pip3 not readable


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.
 
Old 08-29-2021, 05:07 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,854

Rep: Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692
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.
 
Old 08-29-2021, 05:57 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,787

Original Poster
Blog Entries: 3

Rep: Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007
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
 
Old 08-29-2021, 06:03 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,854

Rep: Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692Reputation: 5692
yes, there was a bug (or whatever), so
Code:
# instead of
pip3 install ...
# you can write
python3 -m pip install ...
 
1 members found this post helpful.
Old 08-29-2021, 09:33 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,205
Blog Entries: 1

Rep: Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565Reputation: 1565
Something like this:
Code:
find /usr/local/lib/python3.7 -type d | xargs chmod go+rx
find /usr/local/lib/python3.7 -type f | xargs chmod go+r
 
Old 08-29-2021, 10:38 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,787

Original Poster
Blog Entries: 3

Rep: Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007Reputation: 3007
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.
 
Old 08-29-2021, 04:01 PM   #7
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 1,618

Rep: Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315Reputation: 1315
Quote:
Originally Posted by Turbocapitalist View Post
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.)

 
1 members found this post helpful.
  


Reply

Tags
pip3


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python pip3 download extremely slow, can it be speeded up? Pedroski Linux - Software 1 09-14-2020 02:25 AM
python pip/pip3 app installation error kermitdafrog8 Slackware - ARM 7 07-22-2020 07:35 AM
[SOLVED] How to install Python "pip"/"pip3" in slackware-arm? njathan Slackware - ARM 5 08-09-2017 12:35 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration