Skip to content
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

Add import check for shapely/geos #110

Merged
merged 3 commits into from
Feb 5, 2021

Conversation

kandersolar
Copy link
Contributor

Closes #109

One consequence of doing this check in __init__.py is that it makes it impossible to use pvfactors at all if shapely.geos.lgeos can't be imported. I've not actually used pvfactors before so maybe this is a silly question, but is there any pvfactors functionality that doesn't require shapely? If so, maybe this warrants a more targeted change.

I ran into difficulties testing py2.7, but here's the output I get with py3.7:

(pvfactors-dev) C:\Users\KANDERSO\projects\pvfactors>python -c "import pvfactors"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\KANDERSO\projects\pvfactors\pvfactors\__init__.py", line 21, in <module>
    raise err
  File "C:\Users\KANDERSO\projects\pvfactors\pvfactors\__init__.py", line 8, in <module>
    from shapely.geos import lgeos
  File "C:\Users\KANDERSO\Software\Anaconda3\envs\pvfactors-dev\lib\site-packages\shapely\geos.py", line 154, in <module>
    _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
  File "C:\Users\KANDERSO\Software\Anaconda3\envs\pvfactors-dev\lib\ctypes\__init__.py", line 364, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found; pvfactors encountered an error when importing the shapely package. This often happens when a binary dependency is missing because shapely was installed from PyPI using pip. Try reinstalling shapely from another source like conda-forge with `conda install -c conda-forge shapely`, or alternatively from Cristoph Gohlke's website if you're on Windows: https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely

I'm happy to push updates if this needs anything else like a changelog entry or something, let me know.

Copy link
Contributor

@anomam anomam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @kanderso-nrel, this is the right approach in my opinion. shapely is currently marked as a requirement for the whole package so we shouldn't allow partial usage of pvfactors and do a module-level warning, it would be quite messy I think.


Windows users may also be able to resolve the issue by installing wheels from `Christoph Gohlke`_.

.. _Christoph Gohlke: https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

"from another source like conda-forge with "
"`conda install -c conda-forge shapely`, or alternatively from "
"Christoph Gohlke's website if you're on Windows: "
"https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@anomam anomam added this to the v1.4.2 milestone Feb 5, 2021
@anomam anomam merged commit 9f883a0 into SunPower:master Feb 5, 2021
@anomam anomam mentioned this pull request Feb 5, 2021
@kandersolar kandersolar deleted the shapely_warning branch February 5, 2021 16:07
@anomam anomam mentioned this pull request Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: raise a more informative message when geos_c.dll isn't found
2 participants