我正在 conda python 环境中加载
osgeo
。最初,我根据 this帖子再次安装了
gdal
和 libgdal
,似乎有效。我使用的Python位于:C:\\Users\\Admin\\AppData\\Local\\r-miniconda\\envs\\ENVNAME\\python.exe
Python 3.9.19 | packaged by conda-forge | (main, Mar 20 2024, 12:38:46) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
当我运行
import osgeo
时,我在 Anaconda PowerShell Prompt (miniconda3) 上的 python 上运行它,该提示位于 %windir%\System32\cmd.exe "/K" C:\Users\Admin\miniconda3\Scripts\activate.bat C:\Users\Admin\miniconda3
但是在 Windows Power shell 和 Anaconda 提示符(miniconda 3)上启动的同一个 python 上运行时出现错误。我在这三种情况下都位于同一个文件夹中
Anaconda Powershell 提示符(miniconda3):
%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -NoExit -Command "& 'C:\Users\Admin\miniconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\Users\Admin\miniconda3'
Windows PowerShell:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
如何在同一个 Python 上但从不同的控制台导入
osgeo
?
这是我得到的错误:
(base) C:\Users\Admin>C:\\Users\\Admin\\AppData\\Local\\r-miniconda\\envs\\ENVNAME/python.exe
Python 3.9.19 | packaged by conda-forge | (main, Mar 20 2024, 12:38:46) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import osgeo
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\r-miniconda\envs\ENVNAME\lib\site-packages\osgeo\__init__.py", line 30, in swig_import_helper
return importlib.import_module(mname)
File "C:\Users\Admin\AppData\Local\r-miniconda\envs\ENVNAME\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 666, in _load_unlocked
File "<frozen importlib._bootstrap>", line 565, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1173, in create_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
ImportError: DLL load failed while importing _gdal: Not found specific proccess
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Admin\AppData\Local\r-miniconda\envs\ENVNAME\lib\site-packages\osgeo\__init__.py", line 35, in <module>
_gdal = swig_import_helper()
File "C:\Users\Admin\AppData\Local\r-miniconda\envs\ENVNAME\lib\site-packages\osgeo\__init__.py", line 32, in swig_import_helper
return importlib.import_module('_gdal')
File "C:\Users\Admin\AppData\Local\r-miniconda\envs\ENVNAME\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing _gdal: Not found specific process
>>>
另外,当获取 import sys 时; sys.path,我在三个控制台中得到了相同的响应:
['', 'C:\\Users\\Admin\\AppData\\Local\\r-miniconda\\envs\\cola\\python39.zip',
'C:\\Users\\Admin\\AppData\\Local\\r-miniconda\\envs\\cola\\DLLs',
'C:\\Users\\Admin\\AppData\\Local\\r-miniconda\\envs\\cola\\lib',
'C:\\Users\\Admin\\AppData\\Local\\r-miniconda\\envs\\cola',
'C:\\Users\\Admin\\AppData\\Local\\r-miniconda\\envs\\cola\\lib\\site-packages']
乍一看,您似乎没有激活首先安装 gdal 的环境。您应该先致电
conda activate ENVNAME
。