导入 fiona 导致 ImportError: DLL load failed... 在 conda env 中,而 virtualenv 可以工作

问题描述 投票:0回答:1

我在网上查找信息,但找不到与此特定问题相关的任何内容。

在使用 conda 环境时导入 fiona 时,我得到以下堆栈跟踪:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Nick\anaconda3\envs\general\Lib\site-packages\fiona\__init__.py", line 41, in <module>
    from fiona._env import (
ImportError: DLL load failed while importing _env: The specified procedure could not be found.

同样,当我在终端中运行 fio 时,我收到以下消息:

Traceback (most recent call last):
  File "C:\Users\Nick\anaconda3\envs\general\Scripts\fio-script.py", line 6, in <module>
    from fiona.fio.main import main_group
  File "C:\Users\Nick\anaconda3\envs\general\Lib\site-packages\fiona\__init__.py", line 41, in <module>
    from fiona._env import (
ImportError: DLL load failed while importing _env: The specified procedure could not be found.

但是,如果我使用我用来测试的新 virtualenv venv,我可以成功导入 fiona。这目前适用于我正在处理的脚本,但它不是一个永久的解决方案,因为我无法通过 pip 安装让 gdal 工作,我只能通过使用

conda install -c conda-forge gdal
让它工作。我知道最终我需要在同一个脚本中使用 gdal 和 fiona,因此我正在寻找解决方案。


下面是用于创建新的 conda 环境并安装 python 和 fiona 的过程,然后尝试使用该环境导入 fiona。

Nick@w11-virt-nh MINGW64 ~/Desktop/scratch
$ conda create -n fionatest python fiona
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: C:\Users\Nick\anaconda3\envs\fionatest

  added / updated specs:
    - fiona
    - python


The following NEW packages will be INSTALLED:

  attrs              conda-forge/noarch::attrs-23.1.0-pyh71513ae_1
  blosc              conda-forge/win-64::blosc-1.21.5-hdccc3a2_0
  bzip2              conda-forge/win-64::bzip2-1.0.8-h8ffe710_4
  ca-certificates    conda-forge/win-64::ca-certificates-2023.7.22-h56e8100_0
  cairo              conda-forge/win-64::cairo-1.18.0-h1fef639_0
  cfitsio            conda-forge/win-64::cfitsio-4.3.0-h9b0cee5_0
  click              conda-forge/noarch::click-8.1.7-win_pyh7428d3b_0
  click-plugins      conda-forge/noarch::click-plugins-1.1.1-py_0
  cligj              conda-forge/noarch::cligj-0.7.2-pyhd8ed1ab_1
  colorama           conda-forge/noarch::colorama-0.4.6-pyhd8ed1ab_0
  expat              conda-forge/win-64::expat-2.5.0-h63175ca_1
  fiona              conda-forge/win-64::fiona-1.9.5-py312he9aeaab_0
  font-ttf-dejavu-s~ conda-forge/noarch::font-ttf-dejavu-sans-mono-2.37-hab24e00_0
  font-ttf-inconsol~ conda-forge/noarch::font-ttf-inconsolata-3.000-h77eed37_0
  font-ttf-source-c~ conda-forge/noarch::font-ttf-source-code-pro-2.038-h77eed37_0
  font-ttf-ubuntu    conda-forge/noarch::font-ttf-ubuntu-0.83-hab24e00_0
  fontconfig         conda-forge/win-64::fontconfig-2.14.2-hbde0cde_0
  fonts-conda-ecosy~ conda-forge/noarch::fonts-conda-ecosystem-1-0
  fonts-conda-forge  conda-forge/noarch::fonts-conda-forge-1-0
  freetype           conda-forge/win-64::freetype-2.12.1-hdaf720e_2
  freexl             conda-forge/win-64::freexl-2.0.0-h8276f4a_0
  gdal               conda-forge/win-64::gdal-3.7.2-py312hb5f3cee_7
  geos               conda-forge/win-64::geos-3.12.0-h1537add_0
  geotiff            conda-forge/win-64::geotiff-1.7.1-hcf4a93f_14
  gettext            conda-forge/win-64::gettext-0.21.1-h5728263_0
  hdf4               conda-forge/win-64::hdf4-4.2.15-h5557f11_7
  hdf5               conda-forge/win-64::hdf5-1.14.2-nompi_h73e8ff5_100
  icu                conda-forge/win-64::icu-73.2-h63175ca_0
  importlib-metadata conda-forge/noarch::importlib-metadata-6.8.0-pyha770c72_0
  intel-openmp       conda-forge/win-64::intel-openmp-2023.2.0-h57928b3_50496
  kealib             conda-forge/win-64::kealib-1.5.2-ha10e780_1
  krb5               conda-forge/win-64::krb5-1.21.2-heb0366b_0
  lcms2              conda-forge/win-64::lcms2-2.15-h67d730c_3
  lerc               conda-forge/win-64::lerc-4.0.0-h63175ca_0
  libaec             conda-forge/win-64::libaec-1.1.2-h63175ca_1
  libarchive         conda-forge/win-64::libarchive-3.7.2-h6f8411a_0
  libblas            conda-forge/win-64::libblas-3.9.0-18_win64_mkl
  libboost-headers   conda-forge/win-64::libboost-headers-1.82.0-h57928b3_6
  libcblas           conda-forge/win-64::libcblas-3.9.0-18_win64_mkl
  libcurl            conda-forge/win-64::libcurl-8.4.0-hd5e4a3a_0
  libdeflate         conda-forge/win-64::libdeflate-1.19-hcfcfb64_0
  libexpat           conda-forge/win-64::libexpat-2.5.0-h63175ca_1
  libffi             conda-forge/win-64::libffi-3.4.2-h8ffe710_5
  libgdal            conda-forge/win-64::libgdal-3.7.2-h3217549_7
  libglib            conda-forge/win-64::libglib-2.78.0-he8f3873_0
  libhwloc           conda-forge/win-64::libhwloc-2.9.3-default_haede6df_1009
  libiconv           conda-forge/win-64::libiconv-1.17-h8ffe710_0
  libjpeg-turbo      conda-forge/win-64::libjpeg-turbo-3.0.0-hcfcfb64_1
  libkml             conda-forge/win-64::libkml-1.3.0-haf3e7a6_1018
  liblapack          conda-forge/win-64::liblapack-3.9.0-18_win64_mkl
  libnetcdf          conda-forge/win-64::libnetcdf-4.9.2-nompi_h8284064_112
  libpng             conda-forge/win-64::libpng-1.6.39-h19919ed_0
  libpq              conda-forge/win-64::libpq-16.0-h43585b0_1
  librttopo          conda-forge/win-64::librttopo-1.1.0-h92c5fdb_14
  libspatialite      conda-forge/win-64::libspatialite-5.1.0-hbf340bc_0
  libsqlite          conda-forge/win-64::libsqlite-3.43.2-hcfcfb64_0
  libssh2            conda-forge/win-64::libssh2-1.11.0-h7dfc565_0
  libtiff            conda-forge/win-64::libtiff-4.6.0-h6e2ebb7_2
  libwebp-base       conda-forge/win-64::libwebp-base-1.3.2-hcfcfb64_0
  libxml2            conda-forge/win-64::libxml2-2.11.5-hc3477c8_1
  libzip             conda-forge/win-64::libzip-1.10.1-h1d365fa_3
  libzlib            conda-forge/win-64::libzlib-1.2.13-hcfcfb64_5
  lz4-c              conda-forge/win-64::lz4-c-1.9.4-hcfcfb64_0
  lzo                conda-forge/win-64::lzo-2.10-he774522_1000
  minizip            conda-forge/win-64::minizip-4.0.1-h5bed578_5
  mkl                conda-forge/win-64::mkl-2022.1.0-h6a75c08_874
  munch              conda-forge/noarch::munch-4.0.0-pyhd8ed1ab_0
  numpy              conda-forge/win-64::numpy-1.26.0-py312h8753938_0
  openjpeg           conda-forge/win-64::openjpeg-2.5.0-h3d672ee_3
  openssl            conda-forge/win-64::openssl-3.1.3-hcfcfb64_0
  pcre2              conda-forge/win-64::pcre2-10.40-h17e33f8_0
  pip                conda-forge/noarch::pip-23.2.1-pyhd8ed1ab_0
  pixman             conda-forge/win-64::pixman-0.42.2-h63175ca_0
  poppler            conda-forge/win-64::poppler-23.10.0-hc2f3c52_0
  poppler-data       conda-forge/noarch::poppler-data-0.4.12-hd8ed1ab_0
  postgresql         conda-forge/win-64::postgresql-16.0-hc80876b_1
  proj               conda-forge/win-64::proj-9.3.0-he13c7e8_1
  pthreads-win32     conda-forge/win-64::pthreads-win32-2.9.1-hfa6e2cd_3
  python             conda-forge/win-64::python-3.12.0-h2628c8c_0_cpython
  python_abi         conda-forge/win-64::python_abi-3.12-4_cp312
  setuptools         conda-forge/noarch::setuptools-68.2.2-pyhd8ed1ab_0
  shapely            conda-forge/win-64::shapely-2.0.2-py312h92c3dd1_0
  six                conda-forge/noarch::six-1.16.0-pyh6c4a22f_0
  snappy             conda-forge/win-64::snappy-1.1.10-hfb803bf_0
  sqlite             conda-forge/win-64::sqlite-3.43.2-hcfcfb64_0
  tbb                conda-forge/win-64::tbb-2021.10.0-h91493d7_1
  tiledb             conda-forge/win-64::tiledb-2.16.3-h1ffc264_3
  tk                 conda-forge/win-64::tk-8.6.13-hcfcfb64_0
  tzdata             conda-forge/noarch::tzdata-2023c-h71feb2d_0
  ucrt               conda-forge/win-64::ucrt-10.0.22621.0-h57928b3_0
  uriparser          conda-forge/win-64::uriparser-0.9.7-h1537add_1
  vc                 conda-forge/win-64::vc-14.3-h64f974e_17
  vc14_runtime       conda-forge/win-64::vc14_runtime-14.36.32532-hdcecf7f_17
  vs2015_runtime     conda-forge/win-64::vs2015_runtime-14.36.32532-h05e6639_17
  wheel              conda-forge/noarch::wheel-0.41.2-pyhd8ed1ab_0
  xerces-c           conda-forge/win-64::xerces-c-3.2.4-h63175ca_3
  xz                 conda-forge/win-64::xz-5.2.6-h8d14728_0
  zipp               conda-forge/noarch::zipp-3.17.0-pyhd8ed1ab_0
  zlib               conda-forge/win-64::zlib-1.2.13-hcfcfb64_5
  zstd               conda-forge/win-64::zstd-1.5.5-h12be248_0


Proceed ([y]/n)?


Downloading and Extracting Packages:

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate fionatest
#
# To deactivate an active environment, use
#
#     $ conda deactivate


(testing) 
Nick@w11-virt-nh MINGW64 ~/Desktop/scratch
$ conda activate fionatest

(fionatest) 
Nick@w11-virt-nh MINGW64 ~/Desktop/scratch
$ python
Python 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:26:13) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiona
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Nick\anaconda3\envs\fionatest\Lib\site-packages\fiona\__init__.py", line 41, in <module>
    from fiona._env import (
ImportError: DLL load failed while importing _env: The specified procedure could not be found.
>>>

下面尝试与我的 test_venv 进行相同的操作(使用 virtualenv 模块制作,fiona 使用 pip 安装)并显示版本:

Nick@w11-virt-nh MINGW64 ~/Desktop/scratch/
$ source test_venv/Scripts/activate
(test_venv) 
Nick@w11-virt-nh MINGW64 ~/Desktop/scratch/
$ python
Python 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:29:11) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiona
>>> fiona.__version__
'1.9.5'
>>>
python conda virtualenv fiona
1个回答
0
投票

虽然这确实解决了我的问题,但如果有人有更专业的答案或知道为什么会发生这种情况,我仍然很想听听!

写完我的问题后,我重读了它,注意到我说:“用 virtualenv 模块制作,fiona 用 pip 安装”...

这导致我尝试通过 conda 删除 fiona,通过 pip 安装它,然后再次使用 conda 重新安装 gdal。这似乎解决了我的问题,因为我无法同时导入

fiona
gdal
,也无法使用
fio.exe

conda uninstall fiona
pip install fiona
conda install -c conda-forge gdal
(fionatest) 
Nick@w11-virt-nh MINGW64 ~/Desktop/scratch
$ python
Python 3.12.0 | packaged by conda-forge | (main, Oct  3 2023, 08:26:13) [MSC v.1935 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fiona
>>> from osgeo import gdal
>>> fiona.__version__
'1.9.5'
>>> gdal.__version__
'3.7.2'
>>>
© www.soinside.com 2019 - 2024. All rights reserved.