“OSError: [WinError 126] The specified module could not be found” using pvfactors library

社会主义新天地 提交于 2021-02-16 23:59:27

问题


I started using the pvfactors tool in Python (which calculates the irradiance incident on surfaces of a photovoltaic arrays) following the website tutorial 1.

import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import pandas as pd
import warnings
warnings.filterwarnings("ignore", category=RuntimeWarning)

# Settings
'exec(%matplotlib inline)'
np.set_printoptions(precision=3, linewidth=300)

#Get timeseries inputs
df_inputs = pd.DataFrame(
    {'solar_zenith': [20., 50.],
     'solar_azimuth': [110., 250.],
     'surface_tilt': [10., 20.],
     'surface_azimuth': [90., 270.],
     'dni': [1000., 900.],
     'dhi': [50., 100.],
     'albedo': [0.2, 0.2]},
    index=[datetime(2017, 8, 31, 11), datetime(2017, 8, 31, 15)]
)

#Prepare some PV array parameters
pvarray_parameters = {
    'n_pvrows': 3,            # number of pv rows
    'pvrow_height': 1,        # height of pvrows (measured at center / torque tube)
    'pvrow_width': 1,         # width of pvrows
    'axis_azimuth': 0.,       # azimuth angle of rotation axis
    'gcr': 0.4,               # ground coverage ratio
}



    from pvfactors.engine import PVEngine
    from pvfactors.geometry import OrderedPVArray
    
    pvarray = OrderedPVArray.init_from_dict(pvarray_parameters)
    
    engine = PVEngine(pvarray)
    
    engine.fit(df_inputs.index, df_inputs.dni, df_inputs.dhi,
               df_inputs.solar_zenith, df_inputs.solar_azimuth,
               df_inputs.surface_tilt, df_inputs.surface_azimuth,
               df_inputs.albedo)

However, when trying to import the classes, I got the following error:

OSError: [WinError 126] The specified module could not be found

The whole error message:

File "C:\Users\karen\OneDrive\Documentos\Doutorado\pvfactors\starting_pvfactors.py", line 51, in from pvfactors.engine import PVEngine

File "C:\Users\karen\anaconda3\lib\site-packages\pvfactors\engine.py", line 5, in from pvfactors.viewfactors import VFCalculator

File "C:\Users\karen\anaconda3\lib\site-packages\pvfactors\viewfactors_init_.py", line 3, in from pvfactors.viewfactors.calculator import VFCalculator

File "C:\Users\karen\anaconda3\lib\site-packages\pvfactors\viewfactors\calculator.py", line 4, in from pvfactors.viewfactors.vfmethods import VFTsMethods

File "C:\Users\karen\anaconda3\lib\site-packages\pvfactors\viewfactors\vfmethods.py", line 4, in from pvfactors.geometry.timeseries import TsLineCoords, TsPointCoords

File "C:\Users\karen\anaconda3\lib\site-packages\pvfactors\geometry_init_.py", line 3, in from pvfactors.geometry.pvarray import OrderedPVArray

File "C:\Users\karen\anaconda3\lib\site-packages\pvfactors\geometry\pvarray.py", line 6, in from pvfactors.geometry.base import \

File "C:\Users\karen\anaconda3\lib\site-packages\pvfactors\geometry\base.py", line 9, in from pvfactors.geometry.utils import \

File "C:\Users\karen\anaconda3\lib\site-packages\pvfactors\geometry\utils.py", line 6, in from shapely.geometry import \

File "C:\Users\karen\anaconda3\lib\site-packages\shapely\geometry_init_.py", line 4, in from .base import CAP_STYLE, JOIN_STYLE

File "C:\Users\karen\anaconda3\lib\site-packages\shapely\geometry\base.py", line 19, in from shapely.coords import CoordinateSequence

File "C:\Users\karen\anaconda3\lib\site-packages\shapely\coords.py", line 8, in from shapely.geos import lgeos

File "C:\Users\karen\anaconda3\lib\site-packages\shapely\geos.py", line 154, in _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))

File "C:\Users\karen\anaconda3\lib\ctypes_init_.py", line 364, in init self._handle = _dlopen(self._name, mode)

OSError: [WinError 126] The specified module could not be found

Can someone please help me solve this bug?


回答1:


the 2nd to last line:

anaconda3\lib\site-packages\shapely\geos.py", line 154, in _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))

shows that your python cannot find the GEOS library that Shapely uses. Shapely is a dependency in pvfactors. However it appears your anaconda environment does have Shapely installed, so there is something wrong either with anaconda or your conda environment. The solution for this is almost always to create a new environment and activate it. Part of the problem is that pvfactors is only distributed in PyPI, and doesn't have a conda forge or anaconda package, so you have to install the requirements from Anaconda manually. Luckily Shapely is on conda forge

Try this in an anaconda prompt (enter commands after C:\Users\karen\> ):

(base) C:\Users\karen\> conda create -n myenv
(base) C:\Users\karen\> activate myenv
(myenv) C:\Users\karen\> conda config --env --add channels conda-forge
(myenv) C:\Users\karen\> conda install python pvlib-python shapely matplotlib future six
(myenv) C:\Users\karen\> pip install --no-deps pvfactors
(myenv) C:\Users\karen\> conda install <other stuff like ipython Jupyter spyder etc>

Good luck. I would recommend creating an issue in pvfactors and ask them to add a conda forge package.

PS: see https://docs.conda.io/projects/conda/en/latest/commands/config.html PPS: see https://pip.pypa.io/en/stable/reference/pip_install/#install-no-deps



来源:https://stackoverflow.com/questions/64037211/oserror-winerror-126-the-specified-module-could-not-be-found-using-pvfactor

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