0

here is what i did before i messed up everything :

i tried to install a package using pip3 , after a long time the download finished and suddenly the error about permission came up because i forgot to use sudo at first and because I didn't want to download the packages again and didn't know where is the pip cache folder is , I did a very stupid thing i changed the permission of the entire python folder in the /usr/bin/ to install package without sudo , after this i tried this :

pip3 install tensorflow
File "/usr/bin/pip3", line 7, in <module>
    from pip import main
ImportError: No module named 'pip'

i got these damn error , can anybody help me fix this ?

Edit : here is my sequence of the command i used :

1 - pip3 install tensorflow -- the error came up

2 - sudo find /usr/lib/python3.5/ -type d -exec chmod 766 {} \;

3 - sudo find /usr/lib/python3.5/ -type f -exec chmod 766 {} \;

Javad Sameri
  • 1,218
  • 3
  • 17
  • 30
  • 1
    try with `pip` not `pip3` – dot.Py Mar 31 '17 at 18:01
  • i want to install the package in python3 version , pip install it in python2.7 by default i think because when i tried the pip install .. it start to download again – Javad Sameri Mar 31 '17 at 18:02
  • 1
    To clarify, can you list the sequence of commands to used (my guess from the start of this 3)? – Tom de Geus Mar 31 '17 at 18:04
  • So you installed `python3` and `python2` in the same machine? Maybe your `python2` executable comes first than `python3` in your `path variable`.. What you can do is start your `python3` terminal and type `pip install tensorflow`. Or fix your `path variable` to indicate that `python3` executable must come first. [Take a look here](http://stackoverflow.com/questions/18247333/python-pythonpath-in-linux) – dot.Py Mar 31 '17 at 18:06
  • 1
    Also I think that the problems with permissions you got earlier referred to the `/usr/local/lib/...` folder (where the packages are stored on most Linux distributions), while you are mentioning that you changed the path where (a link to the) executable is stored – Tom de Geus Mar 31 '17 at 18:10
  • @dot.py i will try to change path variable – Javad Sameri Mar 31 '17 at 18:12
  • @mjsameri So, can you tell us more if your problem was solved? In particular, were you able to run pip without root permissions? – Tom de Geus Apr 19 '17 at 07:23
  • @TomdeGeus it still on and not fixed , but every time I wanted to use pip , I manually go to python folder and use ./pip .... – Javad Sameri Apr 19 '17 at 07:33
  • @mjsameri I'm not sure that I understand. That has nothing to do with permission problems right? Where is the executable located? Did you check you `PATH` variable? – Tom de Geus Apr 19 '17 at 07:37

1 Answers1

3

First, and foremost, I consider your approach quite unwise. You have now changed the permissions of all files and directories for the owner, the group, and others.

In principle you just needed to ensure that pip3 (by extension, your user-account) would be able write files and directories in a directory owned by root (presumably /usr/lib/python3.5/site-packages). You could have accomplished this by:

sudo chmod o+w /usr/lib/python3.5/site-packages

Alternatively you could have changed the ownership of this folder. IMPORTANT: when doing this kind of thing, be sure to know what you are doing, and don't forget to change everything back as soon as possible. Things can be broken, and security issues can be created.

Now as to a solution to your problem. You have now given the directories the following permissions -rwxrw-rw- (6 = 4 (read) + 2 (write)). However for users, and programs executed on its behalf, to do anything to/from a directory they need the right to execute. For this you should have used 5 instead of 6 (5 = 4 (read) + 1 (execute)). To correct:

sudo find /usr/lib/python3.5/ -type d -exec chmod 755 {} \;

Then, I think that for Python to correctly load compiled libraries (shared-objects or .so files) they should also have these permissions. Judging from my own Python directory I would probably do:

sudo find /usr/lib/python3.5/ -type f -exec chmod 644 {} \;
sudo find /usr/lib/python3.5/ -type f -iname '*.so' -exec chmod 755 {} \;

to set everything back to it's original state.

P.S. I am no expert in pip, so I have no idea what the protocol is to avoid pip from re-downloading upon retrying a failed installation.

Tom de Geus
  • 5,625
  • 2
  • 33
  • 77