如何在Windows 10中安装gdal for python?

zzwlnbp8  于 2023-04-22  发布在  Windows
关注(0)|答案(3)|浏览(269)

我正在尝试安装gdal库。我已经尝试了这里推荐的东西Installing gdal python library on windows using conda (DLL load failed)
标签:https://github.com/felipunky/GISPython/blob/master/README.md
然后我试着:

C:\Users\User>pip install D:\Seba\Programas\GDAL-3.3.0-cp37-cp37m-win_amd64.whl
Requirement already satisfied: GDAL==3.3.0 from file:///D:/Seba/Programas/GDAL-3.3.0-cp37-cp37m-win_amd64.whl in c:\users\user\appdata\local\programs\python\python37\lib\site-packages (3.3.0)
WARNING: You are using pip version 20.1.1; however, version 21.1.2 is available.
You should consider upgrading via the 'c:\users\user\appdata\local\programs\python\python37\python.exe -m pip install --upgrade pip' command.

C:\Users\User>python
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import gdal
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'gdal'
>>> from osgeo import gdal
Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\osgeo\__init__.py", line 18, in swig_import_helper
    return importlib.import_module(mname)
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 583, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1043, in create_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: DLL load failed: No se puede encontrar el módulo especificado.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\osgeo\__init__.py", line 34, in <module>
    _gdal = swig_import_helper()
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\osgeo\__init__.py", line 31, in swig_import_helper
    return importlib.import_module('_gdal')
  File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named '_gdal'
>>>

有什么推荐吗?
谢谢

0s0u357o

0s0u357o1#

在windows中安装gdal的conda可以工作。
您还没有给出更多的信息,但我猜您还没有激活安装了gdal的conda环境。
通常,如果您激活了命令提示符,它看起来应该是这样的

(gdal_env_name) C:\Users\User>python

还有,快跑

conda list

检查所有预期的库是否都在那里。

mqkwyuun

mqkwyuun2#

您可以使用Anaconda包管理系统在Windows上安装GDAL

安装Anaconda

完整的 Anaconda 有超过500 Mb的预下载库库。很可能你只会使用其中的一小部分。另外,你想使用的一些库根本不是默认的anaconda channell的一部分(例如GDAL库)。
这就是为什么 conda 管理器的首选安装程序是 Miniconda。它只包含工作所需的库(conda 沿着一些必需的库)。
https://docs.conda.io/en/latest/miniconda.html

运行安装程序

运行Miniconda安装程序。默认设置足够公平。

将conda-forge设为默认通道(可选)

conda config --add channels conda-forge
conda config --set channel_priority strict

安装python包

启动Anaconda prompt并执行以下命令:

创建专用虚拟Python环境(可选)

conda create -n dev
conda activate dev
conda install -c conda-forge  python=3.10

安装GDAL库

conda install -c conda-forge gdal

安装其他Python库

conda install -c conda-forge xlsxwriter openpyxl pandas geopandas matplotlib psycopg requests keyring

检查GDAL环境

在命令提示符下输入:

python --version
gdalinfo --version

执行一些GDAL代码

from osgeo import gdal
print(gdal.VersionInfo("–version"))

#> GDAL 3.6.3, released 2023/03/07
atmip9wb

atmip9wb3#

试试这个:sudo easy_install GDAL

相关问题