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 resolution in Python 3.8 on Windows has changed

See original GitHub issue

The resolution of DLLs has changed in Python 3.8 for Windows.

New in version 3.8: Previous versions of CPython would resolve DLLs using the default behavior for the current process. This led to inconsistencies, such as only sometimes searching PATH or the current working directory, and OS functions such as AddDllDirectory having no effect.

DLL dependencies for extension modules and DLLs loaded with ctypes on Windows are now resolved more securely. Only the system paths, the directory containing the DLL or PYD file, and directories added with add_dll_directory() are searched for load-time dependencies. Specifically, PATH and the current working directory are no longer used, and modifications to these will no longer have any effect on normal DLL resolution. If your application relies on these mechanisms, you should check for add_dll_directory() and if it exists, use it to add your DLLs directory while loading your library. Note that Windows 7 users will need to ensure that Windows Update KB2533623 has been installed (this is also verified by the installer). (Contributed by Steve Dower in bpo-36085.)

As a result the Appveyor job for 3.8 is failing:

https://ci.appveyor.com/project/sgillies/fiona/branch/master/job/5e9p53tga9ono4j3

python -c "import fiona"
python : Traceback (most recent call last):
At line:1 char:1
+ python -c "import fiona"
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
  File "<string>", line 1, in <module>
  File "C:\Python38-x64\Lib\site-packages\fiona\__init__.py", line 85, in <module>
    from fiona.collection import BytesCollection, Collection
  File "C:\Python38-x64\Lib\site-packages\fiona\collection.py", line 9, in <module>
    from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
ImportError: DLL load failed while importing ogrext: The specified module could not be found.
Command executed with exception:   File "<string>", line 1, in <module>
  File "C:\Python38-x64\Lib\site-packages\fiona\__init__.py", line 85, in <module>
    from fiona.collection import BytesCollection, Collection
  File "C:\Python38-x64\Lib\site-packages\fiona\collection.py", line 9, in <module>
    from fiona.ogrext import Iterator, ItemsIterator, KeysIterator
ImportError: DLL load failed while importing ogrext: The specified module could not be found.

I’m not sure what the correct thing to do here is. For wheels on Windows it’s easy to call add_dll_directory with the correct path. But I’m not sure what to do for users not using a wheel - how could we know which path to add? I’d be interested to see how other libraries have handled this.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gtmaskallcommented, Nov 2, 2020

@achapkowski - were you seeing this (with Python 3.6.8) in either ipython or a jupyter notebook? I’ve just had a very similar issue with python 3.6.11 that is resolved by upgrading to python 3.6.12. The weird thing is that it only happened when using either ipython or jupyter notebooks, and not the straight python repl. I documented my research in this SO post.

@rbuffat , @snorfalorpagus - do the tests cover imports from ipython?

0reactions
GuYithcommented, Mar 9, 2022

I found the same problem when I tried to “import fiona” in Jupyter Notebook.

As a matter of fact, I had no problem importing in Jupyter Notebook when I had configured the environment at the beginning. However, when I tried to use it again a few days later, the same error occurred. And I found, the import outside of Jupyter Notebook is correct.

1

I support the problem is not related to fiona itself.

I tried removing the kernel which include fiona, and installed it in Jupyter Notebook again. The error disappeared. Although I don’t know why.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue 36085: Enable better DLL resolution - Python tracker
msg336349 ‑ (view) Author: Steve Dower (steve.dower) * Date: 2019‑02‑23 00:28 msg336350 ‑ (view) Author: Steve Dower (steve.dower) * Date: 2019‑02‑23 00:33 msg336353 ‑ (view)...
Read more >
Issue 43173: Python Windows DLL search paths - Issue Tracker
Hi, What's the correct way to set the DLL search path when running a python script? It seems that it doesn't search the...
Read more >
What's New In Python 3.8 — Python 3.11.1 documentation
This article explains the new features in Python 3.8, compared to 3.7. Python 3.8 was released on October 14, 2019. For full details,...
Read more >
Unable to import module due to python unable to resolve ...
The error I get is: Python 3.8.0 (tags/v3.8.0:fa919fd, ... Hello Steve, You have added changes to load windows dependent DLLs for python C ......
Read more >
Issue 39393: Misleading error message upon dependent DLL ...
Under Windows with Python 3.8+, trying to load a DLL whose dependencies cannot be resolved may produce a misleading error message.
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