[gdal-dev] Python installation can't find gdal_array.py
Jorge Arévalo
jorge at cartodb.com
Wed Jan 28 10:08:18 PST 2015
> Even Rouault <mailto:even.rouault at spatialys.com>
> January 28, 2015 at 6:53 PM
> Le mercredi 28 janvier 2015 18:51:28, Jorge Arévalo a écrit :
>> Hi,
>>
>>> Even Rouault<mailto:even.rouault at spatialys.com>
>>> January 28, 2015 at 6:44 PM
>>> Jorge,
>>>
>>>> I've compiled GDAL from trunk, specifying --with-python at configure
>>>> time. I first checked numpy is correctly installed. The problem is I
>>>> couldn't import gdal_array.py by default (got ImportError: no module
>>>> named _gdal_array).
>>>>
>>>> Tried
>>>>
>>>> python gdal_sources/swig/python/setup.py install
>>>>
>>>> Didn't work.
>>> "didn't work", could you be more precise ?
>>> "python setup.py install" requires root rights since it installs in
>>> /usr/local/lib. There's a ticket&debate if the python bindings should
>>> honour the --prefix specified at configure time or not. Currently they
>>> don't, and it is an annoyance for folks. Perhaps we should revert to
>>> honour the prefix, but this was disabled at some point and nobody
>>> remembers why...
>> Yes, I felt the pain of python bindings don't honouring the --prefix
>> specified... Good to know there's a debate on this.
>>
>> Sorry about my vague description. I just did it using sudo, for a system
>> installation, and after that, system Python still didn't find the path.
>> So, after
>>
>> sudo python gdal_sources/swig/python/setup.py install
>>
>> I still get the same error:
>>
>> ImportError: no module named _gdal_array
>
> Are you sure you don't have a python-gdal package hanging somewhere ? (but
> that would be weird it wouldn't have numpy support). Or a custom python-gdal
> bindings installed in another location that is tried before the one where you
> install.
Yep. Looked for gdal packages:
dpkg-query --show --showformat='${Package;-50}\t${Installed-Size}\n' |
sort -k 2 -n | grep -v deinstall | awk '{printf "%.3f MB \t %s\n",
$2/(1024), $1}' | grep gdal
0 found. Just installed GDAL from sources, using this line
./configure --with-python --without-libtool --with-curl=/usr/bin/curl-config
Also looked for any existent gdal_array.py
sudo find / -name gdal_array.py
Just found the one in my sources tree, and the system one at
/usr/local/lib/python2.7/dist-packages/osgeo/gdal_array.py.
If I print sys.path from Python console, I get:
['', '/home/jorge', '/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',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PILcompat']
So, /usr/local/lib/python2.7/dist-packages is included, but
/usr/local/lib/python2.7/dist-packages/osgeo doesn't. I tried with
from osgeo import gdal_array
And then, I get ImportError: no module named _gdal
>>>> I finally had to define
>>>>
>>>> export
>>>> PYTHONPATH=$PYTHONPATH:$/usr/local/lib/python2.7/dist-packages/osgeo
>>>>
>>>> to make it work. And I don't think that's the default solution, right?
>>> That's what I use since I have many GDAL versions on my machine and must
>>> switch between them without reinstalling. For regular users not tweaking
>>> the installation prefix, "sudo make install" should do the right thing
>>> however.
>> Yep, that was what I thought. But still fails after sudo make install.
>> The only way I've found to make it work is by exporting PYTHONPATH
>>
>> Best regards,
>>
>> Jorge
>>
>>>> Am I doing something wrong?
>>>>
>>>> Environment: Ubuntu 14.10, GDAL from trunk, Python 2.7.8
>>> Even
>
> Even Rouault <mailto:even.rouault at spatialys.com>
> January 28, 2015 at 6:44 PM
> Jorge,
>
>> I've compiled GDAL from trunk, specifying --with-python at configure
>> time. I first checked numpy is correctly installed. The problem is I
>> couldn't import gdal_array.py by default (got ImportError: no module
>> named _gdal_array).
>>
>> Tried
>>
>> python gdal_sources/swig/python/setup.py install
>>
>> Didn't work.
>
> "didn't work", could you be more precise ?
> "python setup.py install" requires root rights since it installs in
> /usr/local/lib. There's a ticket&debate if the python bindings should honour
> the --prefix specified at configure time or not. Currently they don't, and it is
> an annoyance for folks. Perhaps we should revert to honour the prefix, but this
> was disabled at some point and nobody remembers why...
>
>> I finally had to define
>>
>> export PYTHONPATH=$PYTHONPATH:$/usr/local/lib/python2.7/dist-packages/osgeo
>>
>> to make it work. And I don't think that's the default solution, right?
>
> That's what I use since I have many GDAL versions on my machine and must
> switch between them without reinstalling. For regular users not tweaking the
> installation prefix, "sudo make install" should do the right thing however.
>
>> Am I doing something wrong?
>>
>> Environment: Ubuntu 14.10, GDAL from trunk, Python 2.7.8
>>
>
> Even
>
--
Sent with Postbox <http://www.getpostbox.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150128/493dc197/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: compose-unknown-contact.jpg
Type: image/jpeg
Size: 770 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20150128/493dc197/attachment-0001.jpg>
More information about the gdal-dev
mailing list