How to troubleshoot python import error - DLL access denied
Asked Answered
C

3

7

I have installed a certain python package (netCDF4), which contains compiled code (extension module). I am running Anaconda and python 3.6 under Windows 10 (x64). When importing the module from console, I get the following error:

In [1]: import netCDF4
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-9588a3d4fb24> in <module>()
----> 1 import netCDF4

C:\Program Files\Anaconda3\lib\site-packages\netCDF4\__init__.py in <module>()
      1 # init for netCDF4. package
      2 # Docstring comes from extension module _netCDF4.
----> 3 from ._netCDF4 import *
      4 # Need explicit imports for names beginning with underscores
      5 from ._netCDF4 import __doc__, __pdoc__

ImportError: DLL load failed: Access is denied.

But the module is loaded flawlessly from an administrator account.

I suspect that some crucial DLL file is blocked by company-wide security policy, which is quite restrictive. For instance, binary files are blocked by default unless in the "program files" folder. But my python distribution and the netCDF4 package are already within this folder, so I'm at loss how to explain this. The AppLocker log in Windows Event Viewer does not show any blocking activity. The dependencies listed by the depencency walker tool are either system libraries or contained in the "program files" folder.

How do I start troubleshooting? How can I find out what is going on?

Cargill answered 6/3, 2018 at 9:28 Comment(0)
C
3

After a long struggle, I now have the solution.

I started python in admin mode, and used the tool Process Explorer to log which DLL files were loaded. The import netCDF4 statement loaded around 10 extra DLL files. I then started python in user mode, and used ctypes.WinDLL to load each of these libraries manually. I was then able to pinpoint the exact library (hdf5.dll) that caused the problems. It turned out that hdf5.dll had incomplete permissions, so that it could only be loaded with administrator privilegies.

Although my problem was very specific, I hope that my solution can help others in related situations...

Cargill answered 6/3, 2018 at 11:35 Comment(1)
I think you mean Process Monitor (not Process Explorer--I don't know where it has file handle logging). I had a similar situation where certain modules wouldn't import with "access denied" errors, and Qt apps (e.g. spyder) wouldn't open. It turned out QtCore5.dll and certain modules' __config__.py didn't have the read/read+execute permissions for regular users.Serin
F
3

This worked for me:

https://vxlabs.com/2017/12/06/how-to-debug-pyinstaller-dll-pyd-load-failed-issues-on-windows/

When debugging DLL load errors on Windows, use lucasg’s open source and more modern rewrite of the old Dependency Walker software. Very importantly, keep on drilling down through indirect dependencies until you find the missing DLLs.

Download here: https://github.com/lucasg/Dependencies

Could be used also without admin rights!

Fleeman answered 26/11, 2018 at 15:38 Comment(0)
C
0

This worked for me: turn off your firewall. I was using 360 Firewall. After I turned it off, everything was fine and dandy. hope this help

Chevy answered 6/6, 2020 at 17:46 Comment(2)
I'm sorry to downvote, but the question is about how to debug, and you do not provide an answer for that. Besides, a company-wide security policy (as per the question) cannot be turned off. Also, turning off the firewall is a last-resort temporary resolution.Cargill
1. I understand where you are coming from, sorry if my answer did not help you.Chevy

© 2022 - 2024 — McMap. All rights reserved.