Skip to content

Commit

Permalink
Add import check for shapely/geos (#110)
Browse files Browse the repository at this point in the history
Closes #109

* add import check to __init__.py

* add commentary to installation docs

* spelling error
  • Loading branch information
kandersolar authored Feb 5, 2021
1 parent 56eac34 commit 9f883a0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/sphinx/installation/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ The easiest way to install ``pvfactors`` is using pip_:
$ pip install pvfactors
However, installing ``shapely`` from PyPI may not install all the necessary binary dependencies.
If you run into an error like ``OSError: [WinError 126] The specified module could not be found``,
try installing conda from conda-forge with:

.. code-block:: shell
$ conda install -c conda-forge shapely
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


pvlib implementation
Expand Down
16 changes: 16 additions & 0 deletions pvfactors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
import logging
logging.basicConfig()

try:
from shapely.geos import lgeos
except OSError as err:
# https://github.com/SunPower/pvfactors/issues/109
msg = (
"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 "
"Christoph Gohlke's website if you're on Windows: "
"https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely"
)
err.strerror += "; " + msg
raise err


class PVFactorsError(Exception):
pass

0 comments on commit 9f883a0

Please sign in to comment.