I can not import library from .py but from terminal

1

I have installed a couple of libraries ( Piexif , pyexiv2 ) from terminal with the following commands:

sudo pip install piexif

sudo apt-get install python-pyexiv2

Therefore, your imports are like this

import piexif
import pyexiv2

But he throws me an error, he did not find the module. I decided to try importing it from terminal with

sudo python
import piexif
import pyexiv2

And it did not throw errors.

I have read and in some cases it is a problem of PATH , so I executed this code:

#!/usr/bin/env python
import sys
for path in sys.path:
    print path

Which throws me this:

  

/ home / yehad / Desktop / HardDrones / Project identification of   vegetation / Tests / Inspire   /usr/local/lib/python2.7/dist-packages/thinning-1.2.3-py2.7-linux-x86_64.egg   /usr/lib/python2.7 /usr/lib/python2.7/plat-x86_64-linux-gnu   /usr/lib/python2.7/lib-tk /usr/lib/python2.7/lib-old   /usr/lib/python2.7/lib-dynload   /home/yehad/.local/lib/python2.7/site-packages   /usr/local/lib/python2.7/dist-packages   /usr/lib/python2.7/dist-packages   /usr/lib/python2.7/dist-packages/PILcompat   /usr/lib/python2.7/dist-packages/gtk-2.0

And the libraries are just in /home/yehad/.local/lib/python2.7/site-packages , so that would not be the problem.

    
asked by Yehadska 03.03.2017 в 17:24
source

1 answer

1

From what I read, you have installed one of the libraries (piexif) with root permissions, therefore, any user with fewer privileges (all) may not have access to it.

sudo -H pip install piexif  # Updated from @toledano tip, sudo -H will not change owner permisions

Solution, install it for the active user with the param "--user":

pip install piexif --user

Another option would be to enable and re-establish the permissions in the folder where the libraries are located, which may have lost the ownership of Yehad and therefore can not access it.

sudo chown yehad -R /home/yehad/.local/lib/python2.7/site-packages
sudo chmod 0664 -R /home/yehad/.local/lib/python2.7/site-packages
    
answered by 03.03.2017 / 17:54
source