Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DLL load issue in Spyder but not in cmd with python/ipython commands #19220

Closed
veenstrajelmer opened this issue Aug 29, 2022 · 5 comments
Closed

Comments

@veenstrajelmer
Copy link

veenstrajelmer commented Aug 29, 2022

Problem Description

I have Anaconda freshly installed quite recently (2022.05) and with the 'append to PATH option' enabled. I can import netCDF4 in cmd when my conda env is activated. However, I cannot import the netCDF4 module in Spyder (running the same conda env), since I get a DLL load error.

What steps reproduce the problem?

  1. This is a minimal example, using conda-forge since I need it for some other modules (but it also happens when I exclude that):
conda create --name test_env -c conda-forge python=3.8 spyder netcdf4 -y
  1. Importing it with Python/IPython from the console works fine:
conda activate test_env
python -c "import netCDF4"
ipython -c "import netCDF4"
  1. However, when executing import netCDF4 in Spyder (in test_env environment, I checked this), I get the error:
ImportError: DLL load failed while importing _netCDF4: The specified procedure could not be found.

What is the expected output? What do you see instead?

Importing the module without an error

Paste Traceback/Error Below (if applicable)

Traceback (most recent call last):

  File "C:\Users\veenstra\AppData\Local\Temp\ipykernel_5068\2807976529.py", line 1, in <cell line: 1>
    import netCDF4

  File "C:\Users\veenstra\Anaconda3\envs\test_env\lib\site-packages\netCDF4\__init__.py", line 3, in <module>
    from ._netCDF4 import *

ImportError: DLL load failed while importing _netCDF4: The specified procedure could not be found.

Additional info: this is not because there are paths missing from os.sys.path, they are equal in ipython (cmd) and spyder

Versions

  • Spyder version: 5.3.2
  • Python version: 3.8.13
  • Qt version: 5.15.4
  • PyQt version: 5.15.7
  • Operating System name/version: Windows 10 64-bit

Workaround

I know from experience that if I install netCDF4 via pip, it does work properly. This is also mentioned by this issue: ContinuumIO/anaconda-issues#1671
However, in my case this would mean creating a conda env, pip installing my package (with netCDF4 as a dependency), conda installing the conda-forge specific packages like geopandas/contextily. This is not recommended when using conda/pip mixed (recommended is to first install all that is possible with conda, then install the last bits with pip)

@ccordoba12
Copy link
Member

Hey @veenstrajelmer, thanks for reporting. I don't know what happens in your case, but it's very strange that importing netCDF4 is not working properly.

@dalthviz, are you able to reproduce this problem on Windows?

@dalthviz
Copy link
Member

Hi @veenstrajelmer I was unable to reproduce this :/ Just in case, the env details where I tested this:


# Name                    Version                   Build  Channel
alabaster                 0.7.12                     py_0    conda-forge
arrow                     1.2.2              pyhd8ed1ab_0    conda-forge
astroid                   2.12.5           py38haa244fe_0    conda-forge
atomicwrites              1.4.1              pyhd8ed1ab_0    conda-forge
attrs                     22.1.0             pyh71513ae_1    conda-forge
autopep8                  1.6.0              pyhd8ed1ab_1    conda-forge
babel                     2.10.3             pyhd8ed1ab_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
bcrypt                    3.2.2            py38h294d835_0    conda-forge
beautifulsoup4            4.11.1             pyha770c72_0    conda-forge
binaryornot               0.4.4                      py_1    conda-forge
black                     22.6.0           py38haa244fe_2    conda-forge
bleach                    5.0.1              pyhd8ed1ab_0    conda-forge
brotlipy                  0.7.0           py38h294d835_1004    conda-forge
bzip2                     1.0.8                h8ffe710_4    conda-forge
ca-certificates           2022.6.15            h5b45459_0    conda-forge
certifi                   2022.6.15          pyhd8ed1ab_1    conda-forge
cffi                      1.15.1           py38hd8c33c5_0    conda-forge
cftime                    1.6.1            py38hbdcd294_0    conda-forge
chardet                   5.0.0            py38haa244fe_0    conda-forge
charset-normalizer        2.1.1              pyhd8ed1ab_0    conda-forge
click                     8.1.3            py38haa244fe_0    conda-forge
cloudpickle               2.1.0              pyhd8ed1ab_0    conda-forge
colorama                  0.4.5              pyhd8ed1ab_0    conda-forge
cookiecutter              2.1.1              pyh6c4a22f_0    conda-forge
cryptography              37.0.4           py38hb7941b4_0    conda-forge
curl                      7.83.1               h789b8ee_0    conda-forge
debugpy                   1.6.3            py38h885f38d_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
defusedxml                0.7.1              pyhd8ed1ab_0    conda-forge
diff-match-patch          20200713           pyh9f0ad1d_0    conda-forge
dill                      0.3.5.1            pyhd8ed1ab_0    conda-forge
docutils                  0.19             py38haa244fe_0    conda-forge
entrypoints               0.4                pyhd8ed1ab_0    conda-forge
flake8                    4.0.1              pyhd8ed1ab_2    conda-forge
gettext                   0.19.8.1          ha2e2712_1008    conda-forge
glib                      2.72.1               h7755175_0    conda-forge
glib-tools                2.72.1               h7755175_0    conda-forge
gst-plugins-base          1.20.3               he07aa86_0    conda-forge
gstreamer                 1.20.3               hdff456e_0    conda-forge
hdf4                      4.2.15               h0e5069d_4    conda-forge
hdf5                      1.12.2          nompi_h2a0e4a3_100    conda-forge
icu                       70.1                 h0e60522_0    conda-forge
idna                      3.3                pyhd8ed1ab_0    conda-forge
imagesize                 1.4.1              pyhd8ed1ab_0    conda-forge
importlib-metadata        4.11.4           py38haa244fe_0    conda-forge
importlib_metadata        4.11.4               hd8ed1ab_0    conda-forge
importlib_resources       5.9.0              pyhd8ed1ab_0    conda-forge
inflection                0.5.1              pyh9f0ad1d_0    conda-forge
intel-openmp              2022.1.0          h57928b3_3787    conda-forge
intervaltree              3.0.2                      py_0    conda-forge
ipykernel                 6.15.2             pyh025b116_0    conda-forge
ipython                   7.33.0           py38haa244fe_0    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
isort                     5.10.1             pyhd8ed1ab_0    conda-forge
jedi                      0.18.1             pyhd8ed1ab_2    conda-forge
jellyfish                 0.9.0            py38h294d835_1    conda-forge
jinja2                    3.1.2              pyhd8ed1ab_1    conda-forge
jinja2-time               0.2.0              pyhd8ed1ab_3    conda-forge
jpeg                      9e                   h8ffe710_2    conda-forge
jsonschema                4.14.0             pyhd8ed1ab_0    conda-forge
jupyter_client            7.3.5              pyhd8ed1ab_0    conda-forge
jupyter_core              4.11.1           py38haa244fe_0    conda-forge
jupyterlab_pygments       0.2.2              pyhd8ed1ab_0    conda-forge
keyring                   23.8.2           py38haa244fe_0    conda-forge
krb5                      1.19.3               h1176d77_0    conda-forge
lazy-object-proxy         1.7.1            py38h294d835_1    conda-forge
libblas                   3.9.0              16_win64_mkl    conda-forge
libcblas                  3.9.0              16_win64_mkl    conda-forge
libclang                  14.0.6          default_h77d9078_0    conda-forge
libclang13                14.0.6          default_h77d9078_0    conda-forge
libcurl                   7.83.1               h789b8ee_0    conda-forge
libffi                    3.4.2                h8ffe710_5    conda-forge
libglib                   2.72.1               h3be07f2_0    conda-forge
libiconv                  1.16                 he774522_0    conda-forge
liblapack                 3.9.0              16_win64_mkl    conda-forge
libnetcdf                 4.8.1           nompi_h85765be_104    conda-forge
libogg                    1.3.4                h8ffe710_1    conda-forge
libpng                    1.6.37               h1d00b33_4    conda-forge
libsodium                 1.0.18               h8d14728_1    conda-forge
libspatialindex           1.9.3                h39d44d4_4    conda-forge
libsqlite                 3.39.2               h8ffe710_1    conda-forge
libssh2                   1.10.0               h680486a_3    conda-forge
libvorbis                 1.3.7                h0e60522_0    conda-forge
libwebp                   1.2.4                h8ffe710_0    conda-forge
libwebp-base              1.2.4                h8ffe710_0    conda-forge
libxml2                   2.9.14               hf5bbc77_4    conda-forge
libxslt                   1.1.35               h34f844d_0    conda-forge
libzip                    1.9.2                hfed4ece_1    conda-forge
libzlib                   1.2.12               h8ffe710_2    conda-forge
lxml                      4.9.1            py38h294d835_0    conda-forge
markupsafe                2.1.1            py38h294d835_1    conda-forge
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
mccabe                    0.6.1                      py_1    conda-forge
mistune                   2.0.4              pyhd8ed1ab_0    conda-forge
mkl                       2022.1.0           h6a75c08_874    conda-forge
mypy_extensions           0.4.3            py38haa244fe_5    conda-forge
nbclient                  0.6.7              pyhd8ed1ab_0    conda-forge
nbconvert                 7.0.0              pyhd8ed1ab_0    conda-forge
nbconvert-core            7.0.0              pyhd8ed1ab_0    conda-forge
nbconvert-pandoc          7.0.0              pyhd8ed1ab_0    conda-forge
nbformat                  5.4.0              pyhd8ed1ab_0    conda-forge
nest-asyncio              1.5.5              pyhd8ed1ab_0    conda-forge
netcdf4                   1.6.0           nompi_py38h106dbc7_101    conda-forge
numpy                     1.23.2           py38h223ccf5_0    conda-forge
numpydoc                  1.4.0              pyhd8ed1ab_1    conda-forge
openssl                   1.1.1q               h8ffe710_0    conda-forge
packaging                 21.3               pyhd8ed1ab_0    conda-forge
pandoc                    2.19.2               h57928b3_0    conda-forge
pandocfilters             1.5.0              pyhd8ed1ab_0    conda-forge
paramiko                  2.11.0             pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pathspec                  0.9.0              pyhd8ed1ab_0    conda-forge
pcre                      8.45                 h0e60522_0    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pip                       22.2.2             pyhd8ed1ab_0    conda-forge
pkgutil-resolve-name      1.3.10             pyhd8ed1ab_0    conda-forge
platformdirs              2.5.2              pyhd8ed1ab_1    conda-forge
pluggy                    1.0.0            py38haa244fe_3    conda-forge
ply                       3.11                       py_1    conda-forge
prompt-toolkit            3.0.30             pyha770c72_0    conda-forge
psutil                    5.9.1            py38h294d835_0    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pycodestyle               2.8.0              pyhd8ed1ab_0    conda-forge
pycparser                 2.21               pyhd8ed1ab_0    conda-forge
pydocstyle                6.1.1              pyhd8ed1ab_0    conda-forge
pyflakes                  2.4.0              pyhd8ed1ab_0    conda-forge
pygments                  2.13.0             pyhd8ed1ab_0    conda-forge
pylint                    2.15.0             pyhd8ed1ab_0    conda-forge
pyls-spyder               0.4.0              pyhd8ed1ab_0    conda-forge
pynacl                    1.5.0            py38h31c79cd_1    conda-forge
pyopenssl                 22.0.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.0.9              pyhd8ed1ab_0    conda-forge
pyqt                      5.15.7           py38h75e37d8_0    conda-forge
pyqt5-sip                 12.11.0          py38h885f38d_0    conda-forge
pyqtwebengine             5.15.7           py38h75e37d8_0    conda-forge
pyrsistent                0.18.1           py38h294d835_1    conda-forge
pysocks                   1.7.1              pyh0701188_6    conda-forge
python                    3.8.13          h9a09f29_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python-fastjsonschema     2.16.1             pyhd8ed1ab_0    conda-forge
python-lsp-black          1.2.1              pyhd8ed1ab_0    conda-forge
python-lsp-jsonrpc        1.0.0              pyhd8ed1ab_0    conda-forge
python-lsp-server         1.5.0              pyhd8ed1ab_0    conda-forge
python-slugify            6.1.2              pyhd8ed1ab_0    conda-forge
python_abi                3.8                      2_cp38    conda-forge
pytoolconfig              1.2.2              pyhd8ed1ab_0    conda-forge
pytz                      2022.2.1           pyhd8ed1ab_0    conda-forge
pywin32                   303              py38h294d835_0    conda-forge
pywin32-ctypes            0.2.0           py38haa244fe_1005    conda-forge
pyyaml                    6.0              py38h294d835_4    conda-forge
pyzmq                     23.2.1           py38h09162b1_0    conda-forge
qdarkstyle                3.0.3              pyhd8ed1ab_0    conda-forge
qstylizer                 0.2.1              pyhd8ed1ab_0    conda-forge
qt-main                   5.15.4               h467ea89_2    conda-forge
qt-webengine              5.15.4               h7325c83_3    conda-forge
qtawesome                 1.1.1              pyhd8ed1ab_0    conda-forge
qtconsole                 5.3.2              pyhd8ed1ab_0    conda-forge
qtconsole-base            5.3.2              pyha770c72_0    conda-forge
qtpy                      2.2.0              pyhd8ed1ab_0    conda-forge
requests                  2.28.1             pyhd8ed1ab_1    conda-forge
rope                      1.3.0              pyhd8ed1ab_0    conda-forge
rtree                     1.0.0            py38h8b54edf_1    conda-forge
setuptools                65.3.0             pyhd8ed1ab_1    conda-forge
sip                       6.6.2            py38h885f38d_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
snowballstemmer           2.2.0              pyhd8ed1ab_0    conda-forge
sortedcontainers          2.4.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.3.2.post1        pyhd8ed1ab_0    conda-forge
sphinx                    5.1.1              pyhd8ed1ab_1    conda-forge
sphinxcontrib-applehelp   1.0.2                      py_0    conda-forge
sphinxcontrib-devhelp     1.0.2                      py_0    conda-forge
sphinxcontrib-htmlhelp    2.0.0              pyhd8ed1ab_0    conda-forge
sphinxcontrib-jsmath      1.0.1                      py_0    conda-forge
sphinxcontrib-qthelp      1.0.3                      py_0    conda-forge
sphinxcontrib-serializinghtml 1.1.5              pyhd8ed1ab_2    conda-forge
spyder                    5.3.2            py38haa244fe_0    conda-forge
spyder-kernels            2.3.3            py38haa244fe_0    conda-forge
sqlite                    3.39.2               h8ffe710_1    conda-forge
tbb                       2021.5.0             h2d74725_1    conda-forge
text-unidecode            1.3                        py_0    conda-forge
textdistance              4.4.0              pyhd8ed1ab_0    conda-forge
three-merge               0.1.1              pyh9f0ad1d_0    conda-forge
tinycss2                  1.1.1              pyhd8ed1ab_0    conda-forge
tk                        8.6.12               h8ffe710_0    conda-forge
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
tomli                     2.0.1              pyhd8ed1ab_0    conda-forge
tomlkit                   0.11.4             pyha770c72_0    conda-forge
tornado                   6.2              py38h294d835_0    conda-forge
traitlets                 5.3.0              pyhd8ed1ab_0    conda-forge
typing                    3.10.0.0           pyhd8ed1ab_0    conda-forge
typing-extensions         4.3.0                hd8ed1ab_0    conda-forge
typing_extensions         4.3.0              pyha770c72_0    conda-forge
ucrt                      10.0.20348.0         h57928b3_0    conda-forge
ujson                     5.4.0            py38h885f38d_0    conda-forge
unidecode                 1.3.4              pyhd8ed1ab_0    conda-forge
urllib3                   1.26.11            pyhd8ed1ab_0    conda-forge
vc                        14.2                 hb210afc_6    conda-forge
vs2015_runtime            14.29.30037          h902a5da_6    conda-forge
watchdog                  2.1.9            py38haa244fe_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
webencodings              0.5.1                      py_1    conda-forge
whatthepatch              1.0.2              pyhd8ed1ab_0    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
win_inet_pton             1.1.0            py38haa244fe_4    conda-forge
wrapt                     1.14.1           py38h294d835_0    conda-forge
xz                        5.2.6                h8d14728_0    conda-forge
yaml                      0.2.5                h8ffe710_2    conda-forge
yapf                      0.32.0             pyhd8ed1ab_0    conda-forge
zeromq                    4.3.4                h0e60522_1    conda-forge
zipp                      3.8.1              pyhd8ed1ab_0    conda-forge
zstd                      1.5.2                h7755175_4    conda-forge

@veenstrajelmer
Copy link
Author

veenstrajelmer commented Sep 6, 2022

I also tested it on a different computer. Unfortunately this resulted in the same issue. I did a file compare between our envs and only showed the lines with differences (yours is left, mine is right).

env_differences

Do you have any clue where I can start with looking for the source of this issue?

@dalthviz
Copy link
Member

dalthviz commented Sep 6, 2022

Hi again @veenstrajelmer , I was checking again all the info here and maybe the problem is due to the usage of the append to PATH in your installation and that option interacting somehow with the way Spyder handles if the conda environment should be activated. Just in case, what happens if you use the option custom interpreter instead of the default option in the preferences (Preferences > Python Interpreter > Use the following Python interpreter > <path to your interpreter>)?

@veenstrajelmer
Copy link
Author

I @dalthviz, thanks for this suggestion. It did not work right away, but because of it I removed the Anaconda related paths from the Path environment variable and this solved the issue. Very helpful, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants