<html><head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head><body text="#000000" bgcolor="#FFFFFF"><br>
<br>
<blockquote style="border: 0px none;"
cite="mid:201501281925.02973.even.rouault@spatialys.com" type="cite">
<div style="margin:30px 25px 10px 25px;" class="__pbConvHr"><div
style="display:table;width:100%;border-top:1px solid
#EDEEF0;padding-top:5px"> <div
style="display:table-cell;vertical-align:middle;padding-right:6px;"><img
photoaddress="even.rouault@spatialys.com" photoname="Even Rouault"
src="cid:part1.09010804.03040802@cartodb.com"
name="compose-unknown-contact.jpg" width="25px" height="25px"></div> <div
style="display:table-cell;white-space:nowrap;vertical-align:middle;width:100%">
<a moz-do-not-send="true" href="mailto:even.rouault@spatialys.com"
style="color:#737F92
!important;padding-right:6px;font-weight:bold;text-decoration:none
!important;">Even Rouault</a></div> <div
style="display:table-cell;white-space:nowrap;vertical-align:middle;">
<font color="#9FA2A5"><span style="padding-left:6px">January 28, 2015
at 7:25 PM</span></font></div></div></div>
<div style="color: rgb(136, 136, 136); margin-left: 24px;
margin-right: 24px;" __pbrmquotes="true" class="__pbConvBody"><pre wrap="">Le mercredi 28 janvier 2015 19:08:18, Jorge Arévalo a écrit :
</pre><blockquote type="cite"><blockquote type="cite"><pre wrap="">Even Rouault <a class="moz-txt-link-rfc2396E" href="mailto:even.rouault@spatialys.com"><mailto:even.rouault@spatialys.com></a>
January 28, 2015 at 6:53 PM
Le mercredi 28 janvier 2015 18:51:28, Jorge Arévalo a écrit :
</pre><blockquote type="cite"><pre wrap="">Hi,
</pre><blockquote type="cite"><pre wrap="">Even Rouault<a class="moz-txt-link-rfc2396E" href="mailto:even.rouault@spatialys.com"><mailto:even.rouault@spatialys.com></a>
January 28, 2015 at 6:44 PM
Jorge,
</pre><blockquote type="cite"><pre wrap="">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.
</pre></blockquote><pre wrap="">"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...
</pre></blockquote><pre wrap="">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
</pre></blockquote><pre wrap="">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.
</pre></blockquote><pre wrap="">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']
</pre></blockquote><pre wrap=""><!---->
Trying the same with python2.6, I have the following in sys.path :
'/usr/local/lib/python2.6/dist-packages/GDAL-2.0.0-py2.6-linux-x86_64.egg'
And
'from osgeo import gdal_array' works without PYTHONPATH defined
What is the output of "python setup.py install" ? Mine for reference :
$ sudo python setup.py install
running install
running bdist_egg
running egg_info
creating GDAL.egg-info
writing GDAL.egg-info/PKG-INFO
writing top-level names to GDAL.egg-info/top_level.txt
writing dependency_links to GDAL.egg-info/dependency_links.txt
writing manifest file 'GDAL.egg-info/SOURCES.txt'
writing manifest file 'GDAL.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
creating build/bdist.linux-x86_64
creating build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.6/gdal.py -> build/bdist.linux-x86_64/egg
creating build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/gdal.py -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/_gdalconst.so -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/__init__.py -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/__init__.pyc -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/gdalconst.pyc -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/_gdal.so -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/ogr.pyc -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/gdalnumeric.py -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/_gdal_array.so -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/gdalconst.py -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/ogr.py -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/osr.pyc -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/gdal_array.py -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/gdal.pyc -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/osr.py -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/_ogr.so -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/osgeo/_osr.so -> build/bdist.linux-x86_64/egg/osgeo
copying build/lib.linux-x86_64-2.6/gdalnumeric.py -> build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.6/gdalconst.py -> build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.6/ogr.py -> build/bdist.linux-x86_64/egg
copying build/lib.linux-x86_64-2.6/osr.py -> build/bdist.linux-x86_64/egg
byte-compiling build/bdist.linux-x86_64/egg/gdal.py to gdal.pyc
byte-compiling build/bdist.linux-x86_64/egg/osgeo/gdalnumeric.py to gdalnumeric.pyc
byte-compiling build/bdist.linux-x86_64/egg/osgeo/gdal_array.py to gdal_array.pyc
byte-compiling build/bdist.linux-x86_64/egg/gdalnumeric.py to gdalnumeric.pyc
byte-compiling build/bdist.linux-x86_64/egg/gdalconst.py to gdalconst.pyc
byte-compiling build/bdist.linux-x86_64/egg/ogr.py to ogr.pyc
byte-compiling build/bdist.linux-x86_64/egg/osr.py to osr.pyc
creating stub loader for osgeo/_gdal.so
creating stub loader for osgeo/_gdalconst.so
creating stub loader for osgeo/_osr.so
creating stub loader for osgeo/_ogr.so
creating stub loader for osgeo/_gdal_array.so
byte-compiling build/bdist.linux-x86_64/egg/osgeo/_gdal.py to _gdal.pyc
byte-compiling build/bdist.linux-x86_64/egg/osgeo/_gdalconst.py to _gdalconst.pyc
byte-compiling build/bdist.linux-x86_64/egg/osgeo/_osr.py to _osr.pyc
byte-compiling build/bdist.linux-x86_64/egg/osgeo/_ogr.py to _ogr.pyc
byte-compiling build/bdist.linux-x86_64/egg/osgeo/_gdal_array.py to _gdal_array.pyc
creating build/bdist.linux-x86_64/egg/EGG-INFO
copying GDAL.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
copying GDAL.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying GDAL.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
copying GDAL.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
copying GDAL.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
writing build/bdist.linux-x86_64/egg/EGG-INFO/native_libs.txt
creating dist
creating 'dist/GDAL-2.0.0-py2.6-linux-x86_64.egg' and adding 'build/bdist.linux-x86_64/egg' to it
removing 'build/bdist.linux-x86_64/egg' (and everything under it)
Processing GDAL-2.0.0-py2.6-linux-x86_64.egg
creating /usr/local/lib/python2.6/dist-packages/GDAL-2.0.0-py2.6-linux-x86_64.egg
Extracting GDAL-2.0.0-py2.6-linux-x86_64.egg to /usr/local/lib/python2.6/dist-packages
Adding GDAL 2.0.0 to easy-install.pth file
Installed /usr/local/lib/python2.6/dist-packages/GDAL-2.0.0-py2.6-linux-x86_64.egg
Processing dependencies for GDAL==2.0.0
Finished processing dependencies for GDAL==2.0.0
</pre></div>
</blockquote>
Mine is much shorter<br>
<br>
running install<br>
running build<br>
running build_py<br>
running build_ext<br>
running install_lib<br>
running install_egg_info<br>
Removing /usr/local/lib/python2.7/dist-packages/GDAL-2.0.0.egg-info<br>
Writing /usr/local/lib/python2.7/dist-packages/GDAL-2.0.0.egg-info<br>
<br>
<br>
<br>
<blockquote style="border: 0px none;"
cite="mid:201501281925.02973.even.rouault@spatialys.com" type="cite">
<div style="color: rgb(136, 136, 136); margin-left: 24px;
margin-right: 24px;" __pbrmquotes="true" class="__pbConvBody">
<pre wrap="">
</pre>
<blockquote type="cite"><pre wrap="">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
</pre><blockquote type="cite"><blockquote type="cite"><blockquote
type="cite"><blockquote type="cite"><pre wrap="">I finally had to define
export
PYTHONPATH=$PYTHONPATH:$/usr/local/lib/python2.7/dist-packages/osgeo
</pre></blockquote></blockquote></blockquote></blockquote></blockquote><pre wrap=""><!---->
Should rather be PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages (without the final osgeo) actually</pre></div>
</blockquote>
<br>
Actually, that path is already included<br>
<br>
['', '/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']<br>
<br>
So, if I try something like <br>
<br>
from osgeo import gdal<br>
<br>
it works. But running gdal_merge.py, for example, I get the mentioned
error<br>
<br>
File "/usr/local/bin/gdal_merge.py", line 513, in <module><br>
sys.exit(main())<br>
File "/usr/local/bin/gdal_merge.py", line 499, in main<br>
fi.copy_into( t_fh, band, band, nodata )<br>
File "/usr/local/bin/gdal_merge.py", line 243, in copy_into<br>
nodata_arg )<br>
File "/usr/local/bin/gdal_merge.py", line 63, in raster_copy<br>
nodata )<br>
File "/usr/local/bin/gdal_merge.py", line 99, in
raster_copy_with_nodata<br>
t_xsize, t_ysize )<br>
File "/usr/local/lib/python2.7/dist-packages/osgeo/gdal.py", line
1331, in ReadAsArray<br>
import gdalnumeric<br>
File "/usr/local/lib/python2.7/dist-packages/osgeo/gdalnumeric.py",
line 1, in <module><br>
from gdal_array import *<br>
File "/usr/local/lib/python2.7/dist-packages/osgeo/gdal_array.py",
line 25, in <module><br>
_gdal_array = swig_import_helper()<br>
File "/usr/local/lib/python2.7/dist-packages/osgeo/gdal_array.py",
line 17, in swig_import_helper<br>
import _gdal_array<br>
ImportError: No module named _gdal_array<br>
<br>
Opening gdal_merge.py, I see the imports are doing in the right way:<br>
<br>
try:<br>
from osgeo import gdal<br>
except ImportError:<br>
import gdal<br>
<br>
I'd understand if an old version of the script still does<br>
<br>
import gdal<br>
<br>
which is deprecated way to import gdal bindings (right?). But the script
is also from trunk. The last version.<br>
<br>
<br>
<br>
<blockquote style="border: 0px none;"
cite="mid:201501281925.02973.even.rouault@spatialys.com" type="cite">
<div style="color:#888888;margin-left:24px;margin-right:24px;"
__pbrmquotes="true" class="__pbConvBody">
<pre wrap="">
</pre>
<blockquote type="cite"><blockquote type="cite"><blockquote type="cite"><blockquote
type="cite"><blockquote type="cite"><pre wrap="">to make it work. And I don't think that's the default solution, right?
</pre></blockquote><pre wrap="">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.
</pre></blockquote><pre wrap="">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
</pre><blockquote type="cite"><blockquote type="cite"><pre wrap="">Am I doing something wrong?
Environment: Ubuntu 14.10, GDAL from trunk, Python 2.7.8
</pre></blockquote><pre wrap="">Even
</pre></blockquote></blockquote><pre wrap="">Even Rouault <a class="moz-txt-link-rfc2396E" href="mailto:even.rouault@spatialys.com"><mailto:even.rouault@spatialys.com></a>
January 28, 2015 at 6:44 PM
Jorge,
</pre><blockquote type="cite"><pre wrap="">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.
</pre></blockquote><pre wrap="">"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...
</pre><blockquote type="cite"><pre wrap="">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?
</pre></blockquote><pre wrap="">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.
</pre><blockquote type="cite"><pre wrap="">Am I doing something wrong?
Environment: Ubuntu 14.10, GDAL from trunk, Python 2.7.8
</pre></blockquote><pre wrap="">Even
</pre></blockquote></blockquote><pre wrap=""><!---->
</pre></div>
<div style="margin:30px 25px 10px 25px;" class="__pbConvHr"><div
style="display:table;width:100%;border-top:1px solid
#EDEEF0;padding-top:5px"> <div
style="display:table-cell;vertical-align:middle;padding-right:6px;"><img
photoaddress="even.rouault@spatialys.com" photoname="Even Rouault"
src="cid:part1.09010804.03040802@cartodb.com"
name="compose-unknown-contact.jpg" width="25px" height="25px"></div> <div
style="display:table-cell;white-space:nowrap;vertical-align:middle;width:100%">
<a moz-do-not-send="true" href="mailto:even.rouault@spatialys.com"
style="color:#737F92
!important;padding-right:6px;font-weight:bold;text-decoration:none
!important;">Even Rouault</a></div> <div
style="display:table-cell;white-space:nowrap;vertical-align:middle;">
<font color="#9FA2A5"><span style="padding-left:6px">January 28, 2015
at 6:53 PM</span></font></div></div></div>
<div style="color:#888888;margin-left:24px;margin-right:24px;"
__pbrmquotes="true" class="__pbConvBody"><pre wrap="">Le mercredi 28 janvier 2015 18:51:28, Jorge Arévalo a écrit :
</pre><blockquote type="cite"><pre wrap="">Hi,
</pre><blockquote type="cite"><pre wrap="">Even Rouault <a class="moz-txt-link-rfc2396E" href="mailto:even.rouault@spatialys.com"><mailto:even.rouault@spatialys.com></a>
January 28, 2015 at 6:44 PM
Jorge,
</pre><blockquote type="cite"><pre wrap="">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.
</pre></blockquote><pre wrap="">"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...
</pre></blockquote><pre wrap="">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
</pre></blockquote><pre wrap=""><!---->
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.
</pre><blockquote type="cite"><blockquote type="cite"><blockquote
type="cite"><pre wrap="">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?
</pre></blockquote><pre wrap="">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.
</pre></blockquote><pre wrap="">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
</pre><blockquote type="cite"><blockquote type="cite"><pre wrap="">Am I doing something wrong?
Environment: Ubuntu 14.10, GDAL from trunk, Python 2.7.8
</pre></blockquote><pre wrap="">Even
</pre></blockquote></blockquote><pre wrap=""><!---->
</pre></div>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<div>Sent with <a href="http://www.getpostbox.com"><span style="color:
rgb(51, 102, 153);">Postbox</span></a></div></div>
</body></html>