DLL load issue in Spyder but not in cmd with python/ipython commands
See original GitHub issueProblem 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?
- 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
- Importing it with Python/IPython from the console works fine:
conda activate test_env
python -c "import netCDF4"
ipython -c "import netCDF4"
- 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:
- Created a year ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
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!
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>
)?