-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python38/Windows dll load directory #852
Conversation
fiona/__init__.py
Outdated
gdal_home = os.getenv('GDAL_HOME', None) | ||
|
||
if gdal_home is not None and os.path.exists(gdal_home): | ||
os.add_dll_directory(os.path.join(gdal_home, "bin")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If GDAL_HOME is set, but the directory does not exist, we should emit a warning
@cgohlke I tested this issue with Fiona‑1.8.13‑cp38‑cp38‑win32.whl from https://www.lfd.uci.edu/~gohlke/pythonlibs/#fiona. Changing fiona/init.py from
to
fixed the issue for me. However, I think this is not a "standard" gdal location to look for directly in Fiona. I removed numpy, because the code silently fails to import osgeo if it is not present. |
Those binaries are compiled against GDAL from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal. They are not meant to work with any other GDAL distribution. |
@cgohlke yes, you are right. Sorry for that. My problem was, that I had numpy not installed. I installed a fresh python 3.8, with gdal and fiona from your website. With this installation I got the following message:
I wrongly assumed it is the same reason as in #851 due to the changes in Python 3.8 on Windows and the similar ImportError message. However, as I did not have numpy installed, the import of osgeo never happened. |
fiona/__init__.py
Outdated
@@ -77,6 +77,17 @@ | |||
class Path: | |||
pass | |||
|
|||
|
|||
# Add gdal dll directory on Windows and Python >= 3.8, see https://github.com/Toblerity/Fiona/issues/851 | |||
if platform.system() == 'Windows' and (3, 8) <= sys.version_info: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is add_dll_directory harmful when gdal dlls are already loaded? E.g. when multiple gdal binaries are present.
The issue is that the GDAL Python package does not list numpy as an install requirement when the |
…ort of ogrext failed with ImportError
…rnal builds for gdal 3.0.x
fiona/__init__.py
Outdated
|
||
# Use GDAL_HOME if present | ||
if dll_directory is not None: | ||
gdal_home = os.getenv('GDAL_HOME', None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will need to be added to the documentation. I don't think it's a standard runtime environment variable for GDAL, although it does seem to be used in the build guide for Windows.
Should this be targetted at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes requested inline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some more changes requested inline.
fiona/__init__.py
Outdated
|
||
add_dll_directory_win() | ||
|
||
import fiona.ogrext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should only be one space here
fiona/__init__.py
Outdated
|
||
import fiona.ogrext | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the line breaks around this are necessary.
Currently hitting this. The GDAL installers put the executables and libraries in the GDAL directory, not under bin. So the
Took awhile to hunt down this issue to solve the specified module problem. I could use some direction in how to hunt down the procedure aspect. |
@s7726 I'm not sure what caused this error message. Maybe it helps to recompile Fiona and check that it compiles against the same gdal dlls. @sgillies @snorfalorpagus @cgohlke Numpy has a separate init file for distributions: https://github.com/numpy/numpy/blob/master/numpy/_distributor_init.py |
@rbuffat thanks for taking the lead on this. I would prefer a more explicit approach. Effectively, what we need to do on Windows/Python 3.8 is
in every Python module that imports Fiona extension modules (_env, _geometry, etc). We could write a generic context manager that used the Windows function when required and did nothing in other cases.
What would you think about doing this for a 1.8 bug fix release? |
@sgillies is that the direction you had in mind?
could be simplified to
However, my concern here is that providers of wheels could implement other ways to load the required dlls independent on environment variables. Adding additional directories could lead to side effects. As far as I currently see the only way to know if the dlls are not available is when the import fails. |
closed in favor of #875 |
A start towards fixing #851
This PR loads the GDAL_HOME/bin directory with add_dll_directory when fiona is imported.
We should probably think about adding other directories. Maybe somebody with experience providing wheels for Windows has some advice here @cgohlke @jorisvandenbossche