How to troubleshoot python import error - DLL access denied

半城伤御伤魂 提交于 2021-01-31 07:22:07

问题


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?


回答1:


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...




回答2:


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!




回答3:


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



来源:https://stackoverflow.com/questions/49127425/how-to-troubleshoot-python-import-error-dll-access-denied

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!