python – 没有名为osgeo.ogr的模块

我需要将osgeo.ogr模块导入virtualenv
python程序.

Global python有这个模块:

user@ubuntu:~/$python
Python 2.7.8 (default, Oct 20 2014, 15:05:19)
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import osgeo
>>>

但是进入virtualenv(没有–no-site-packages):

user@ubuntu:~$temp/bin/python
Python 2.7.8 (default, Oct 20 2014, 15:05:19) 
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import osgeo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named osgeo

这种行为的原因是什么?

最佳答案 问题以这种方式解决:

(VIRTUAL_ENV)user@ubuntu:~$pip install --no-install GDAL==1.11.2

1.11.2因为我的版本GDAL是1.11.2:

(VIRTUAL_ENV)user@ubuntu:~$gdal-config --version
1.11.2

下一个:

(VIRTUAL_ENV)user@ubuntu:~$cd ~/.virtualenvs/VIRTUAL_ENV/build/GDAL/
(VIRTUAL_ENV)user@ubuntu:~/.virtualenvs/VIRTUAL_ENV/build/GDAL$python setup.py build_ext --include-dirs=/usr/include/gdal/
(VIRTUAL_ENV)user@ubuntu:~/.virtualenvs/bamap/build/GDAL$pip install --no-download GDAL

–include-dirs = /usr/include / gdal /对我来说是正确的. GDAL在我的系统中安装了Quantum GIS.如果您将手动构建GDAL,则路径可能是其他路径.完整版本:

python setup.py build_ext --gdal-config=/YOUR_PATH/bin/gdal-config --library-dirs=/YOUR_PATH/gdal/VERSION_GDAL/lib --libraries=gdal --include-dirs=/YOUR_PATH/gdal/VERSION_GDAL/include

详细信息可能会找到here.

点赞