question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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: https://github.com/ContinuumIO/anaconda-issues/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)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
veenstrajelmercommented, Sep 7, 2022

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!

0reactions
dalthvizcommented, 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>)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

import matplotlib fails with DLL load error but only in spyder
It appears that this issue requires an upgrade on the Spyder and Spyder-kernel side and/or an environmental variable be set on the Windows ......
Read more >
Python script runs in Spyder but not in Command Line
I created a .bat file with c: call C:\Users\RAdams\AppData\Local\Continuum\miniconda3\Scripts\activate base pythonw ...
Read more >
sitecustomize.py - emzed
coding: utf-8 -*- # Spyder's ExternalPythonShell sitecustomize import sys import ... __buffer+text).splitlines(True): if text.startswith(' File') \ and not ...
Read more >
Common Illnesses — Spyder 5 documentation
There are a number of problems that can cause this, but most can be fixed fairly quickly with a few easy steps. Spyder-Kernels...
Read more >
The ordinal 242 could not be located in the dynamic link ...
Another way which Works for me (I deleted all DLL files but the problem ... Then, launch the Spyder IDE, always using the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found