Python: “ImportError: DLL load failed: The specified module could not be found.” Problems when importing ffn (finance library for python)

半城伤御伤魂 提交于 2020-01-03 04:09:07

问题


Apologies if there does in fact exist a thread that has already figured this out (I've spent a few hours attentively searching multiple sites and the GitHubs for the dependencies that seem to cause the problems), however each solution seemed fairly specific to the particular library that so and so was attempting to use.

I've been messing around with quantitative finance/ algorithmic trading and have been trying to import a particular library ffn, however, per the question title, I've been receiving a somewhat lengthy error message detailing an ImportError, and how I'm supposedly missing certain, very specific dependencies that seem to be there. Honestly this may just be a dependency-ception (I'm missing dependencies of dependencies of ffn), but I've done my best to rule out this possibility.

Here's the full error:

ImportError                               Traceback (most recent call last)
    <ipython-input-2-01bc82d8cf41> in <module>()
      2 import numpy as np
      3 import pandas as pd
----> 4 import ffn
      5 import math

~\PycharmProjects\buff\venv\lib\site-packages\ffn\__init__.py in <module>()
----> 1 from . import core
      2 from . import data
      3 
      4 from .data import get
      5 #from .core import year_frac, PerformanceStats, GroupStats, merge

~\PycharmProjects\buff\venv\lib\site-packages\ffn\core.py in <module>()
      8 from pandas.core.base import PandasObject
      9 from tabulate import tabulate
---> 10 import sklearn.manifold
     11 import sklearn.cluster
     12 import sklearn.covariance

~\PycharmProjects\buff\venv\lib\site-packages\sklearn\__init__.py in <module>()
    132 else:
    133     from . import __check_build
--> 134     from .base import clone
    135     __check_build  # avoid flakes unused variable error
    136 

~\PycharmProjects\buff\venv\lib\site-packages\sklearn\base.py in <module>()
     11 from scipy import sparse
     12 from .externals import six
---> 13 from .utils.fixes import signature
     14 from . import __version__
     15 

~\PycharmProjects\buff\venv\lib\site-packages\sklearn\utils\__init__.py in <module>()
      9 
     10 from .murmurhash import murmurhash3_32
---> 11 from .validation import (as_float_array,
     12                          assert_all_finite,
     13                          check_random_state, column_or_1d, check_array,

~\PycharmProjects\buff\venv\lib\site-packages\sklearn\utils\validation.py in <module>()
     16 
     17 from ..externals import six
---> 18 from ..utils.fixes import signature
     19 from .. import get_config as _get_config
     20 from ..exceptions import NonBLASDotWarning

~\PycharmProjects\buff\venv\lib\site-packages\sklearn\utils\fixes.py in <module>()
    142     from ._scipy_sparse_lsqr_backport import lsqr as sparse_lsqr
    143 else:
--> 144     from scipy.sparse.linalg import lsqr as sparse_lsqr  # noqa
    145 
    146 

~\PycharmProjects\buff\venv\lib\site-packages\scipy\sparse\linalg\__init__.py in <module>()
    112 from __future__ import division, print_function, absolute_import
    113 
--> 114 from .isolve import *
    115 from .dsolve import *
    116 from .interface import *

~\PycharmProjects\buff\venv\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py in <module>()
      4 
      5 #from info import __doc__
----> 6 from .iterative import *
      7 from .minres import minres
      8 from .lgmres import lgmres

~\PycharmProjects\buff\venv\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py in <module>()
      8 import numpy as np
      9 
---> 10 from . import _iterative
     11 
     12 from scipy.sparse.linalg.interface import LinearOperator

ImportError: DLL load failed: The specified module could not be found.

This particular message was from a failed Jupyter notebook trial (IPython console), though I've tried running the same code through a "normal" Python 3 file, only to get the same message. As I inferred earlier, I already have downloaded/ properly installed all the dependencies mentioned in the message (sklearn and scipy are the only problem children outside of ffn itself that the error mentions). The thing confusing me the most is that all of the things that these import statements within the dependencies/ within ffn reference are where they should and (to my knowledge) are accessible.

Perhaps I should've researched this more thoroughly, but the only thing that really made sense to me was that I had the wrong version of these libraries (which are, for the most part, well maintained and somewhat frequently updated) and that certain features that ffn and its dependencies need were deprecated and no longer exist. However, this theory was disproven (at least in part) when I took 30 seconds to figure out if sklearn.manifold existed, and to my apparent surprise, it does. I also checked my IDE's library manager/ interpreter settings menu and everything is up to date (I'm using PyCharm CE).

In short: why I am receiving this message when I seem to have everything it's searching for/ what exactly does it mean, and how do I fix this so that I can use the libraries I wanted to use?

If this helps at all, here's a summary:

All libraries/ dependencies are up to date (PyCharm maintains what versions each one is currently on, although I have to go in manually to tell it to execute the update).

Again, I'm on PyCharm CE 2018 (most recent version).

Here's the entire cell from the Jupyter notebook which yields the error (which also happens to be everything that's in the notebook):

from pylab import * import numpy as np import pandas as pd import ffn import math

Here's all of the contents of the Python document that yields the same error (virtually the same code):

import ffn import math import pandas as pd, numpy as np import datetime data1 = ffn.get('agg, hyg, spy, eem, efa', start='2018-01-01', end='2018-02-02') print(data1.head())

I'm running Windows 10 64 bit


回答1:


Your code is not able to locate your modules. In a Jupyter Notebook, you can make it so that it can. 'PYTHONPATH' is the environment variable which locates the custom modules in python. Now your modules are in your project directory, so you need to make sure your interpreter can locate your files.

Basically, you need to set the path in your Jupyter Notebook to locate imported user define modules.

"To set an env variable in a jupyter notebook, just use a "%" magic commands, either %env or %set_env, e.g., %env MY_VAR=MY_VALUE or %env MY_VAR MY_VALUE. (Use %env by itself to print out current environmental variables.)"

See: How to set env variable in Jupyter notebook



来源:https://stackoverflow.com/questions/51257233/python-importerror-dll-load-failed-the-specified-module-could-not-be-found

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