本文介绍了Python:"ImportError:DLL加载失败:找不到指定的模块."导入ffn时出现问题(用于python的财务库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果确实存在一个已经解决了这个问题的线程(我花了几个小时专心搜索了多个站点和GitHub,以查找似乎引起问题的依赖项),但是每种解决方案似乎都非常具体到某某某人尝试使用的特定库.

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.

我一直在研究量化金融/算法交易,并一直试图导入特定的库ffn,但是,根据问题标题,我一直在收到一条冗长的错误消息,详细说明ImportError ,以及我应该如何丢失似乎存在的某些非常具体的依赖关系.坦白地说,这可能只是一个依赖关系接收(我缺少ffn依赖关系的依赖关系),但是我已尽力排除了这种可能性.

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.

这是完整的错误:

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.

这条特殊消息来自Jupyter笔记本试用失败(IPython控制台),尽管我尝试通过正常" Python 3文件运行相同的代码,但只是得到了相同的消息.如前所述,我已经下载/正确安装了消息中提到的所有依赖项(sklearnscipy是错误所提及的ffn自身之外的唯一问题子级).最让我感到困惑的是,这些导入语句在ffn引用的dependencies/中的所有内容都应该在(据我所知)可以访问的地方.

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.

也许我应该对此进行更彻底的研究,但是对我而言真正有意义的唯一事情是我使用了这些库的错误版本(大部分情况下维护得很好并且经常进行了一些更新),并且ffn及其依赖项所需的某些功能已被弃用,并且不再存在.但是,当我花30秒钟来弄清sklearn.manifold是否存在时,这一理论(至少部分地)没有得到证实,令我惊讶的是,它确实存在.我还检查了我的IDE的库管理器/解释器设置菜单,所有内容都是最新的(我正在使用PyCharm CE).

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:

所有库/依赖项都是最新的(PyCharm会维护每个库当前的版本,尽管我必须手动输入以告诉它执行更新).

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).

再次,我正在使用PyCharm CE 2018(最新版本).

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

这是Jupyter笔记本中的整个单元格,会产生错误(这也恰好是笔记本中的所有内容):

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

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

以下是产生相同错误(几乎相同的代码)的Python文档的所有内容:

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())

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())

我正在运行Windows 10 64位版

I'm running Windows 10 64 bit

推荐答案

您的代码无法找到您的模块.在Jupyter笔记本中,您可以这样做. 'PYTHONPATH'是用于在python中定位自定义模块的环境变量.现在,您的模块位于项目目录中,因此您需要确保解释器可以找到您的文件.

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.

基本上,您需要在Jupyter Notebook中设置路径以找到导入的用户定义模块.

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

要在jupyter笔记本中设置env变量,只需使用"%魔术命令,即%env%set_env,例如%env MY_VAR=MY_VALUE%env MY_VAR MY_VALUE.(使用%env本身以打印出当前的环境变量.)"

"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.)"

请参阅:如何在Jupyter笔记本中设置环境变量

这篇关于Python:"ImportError:DLL加载失败:找不到指定的模块."导入ffn时出现问题(用于python的财务库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 04:50