如何修复ImportError:DLL加载失败

时间:2020-07-07 19:03:32

标签: python-3.x pymc3

我正在Windows 10 Pro上运行Python 3.8。我正在尝试将多项式固定效果模型拟合到某些数据。所有软件包看上去都可以很好地加载,数据可以加载并且可以被操纵和查看。但是,当我调用协作者编写的适合模型的模块(称为contactai)时出现错误。 这是contactai的代码:

注意:tt代表theano.tensor,pm代表pymc3

def fixed_effects_model(X, y):

参数

X:数组包含协变量 设计矩阵n x p

y:数组或共享theano变量 多项式响应变量n x 3

返回

包含拟合模型的pymc3模型对象

  yarray = y.eval() 
else:
  yarray = y

if type(X) == tt.sharedvar.TensorSharedVariable:
  Xmat = X.eval()
else:
  Xmat = X

model = pm.Model() 

with model:

  # Transformed coefficients
  betaD = pm.Normal('betad', mu=0, sd=5, shape=(Xmat.shape[1], 1))
  betaI = pm.Normal('betai', mu=0, sd=5, shape=(Xmat.shape[1], 1))
  
  # Softmax transformation with no contact as baseline
  etad = tt.exp(tt.dot(X, betaD)) 
  etai = tt.exp(tt.dot(X, betaI))

  p_d = etad / (1 + etad + etai)
  p_i = etai / (1 + etad + etai)
  p_n = 1 - p_d - p_i 
  ps = tt.stack([p_n, p_d, p_i], axis=1).reshape((len(yarray), 3)) # Stack column-wise
   
  Y_obs = pm.Multinomial("Y_obs", n=1, p=ps, observed=y)

return(model) 

当我使用Jupyter笔记本电脑调用contaciai.py时

test_mod = contactai.fixed_effects_model(Xmat1, Yres.values) 

我收到此错误消息:

ImportError                               Traceback (most recent call last)
<ipython-input-6-275ca67d4b63> in <module>
      1 # Run Fixed Effects model
----> 2 test_mod = contactai.fixed_effects_model(Xmat1, Yres.values)
      3 niter = 1000
      4 
      5 with test_mod:

~\dropbox\Brooke\ai_multinomial_model\contactai.py in fixed_effects_model(X, y)
     50     # Transformed coefficients, what are D and I? In other examples this is where priors are
     51     #specified.
---> 52     betaD = pm.Normal('betad', mu=0, sd=5, shape=(Xmat.shape[1], 1))
     53     betaI = pm.Normal('betai', mu=0, sd=5, shape=(Xmat.shape[1], 1))
     54     # First argument is the name of the random variable

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\pymc3\distributions\distribution.py in __new__(cls, name, *args, **kwargs)
     44                 raise TypeError("observed needs to be data but got: {}".format(type(data)))
     45             total_size = kwargs.pop('total_size', None)
---> 46             dist = cls.dist(*args, **kwargs)
     47             return model.Var(name, dist, data, total_size)
     48         else:

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\pymc3\distributions\distribution.py in dist(cls, *args, **kwargs)
     55     def dist(cls, *args, **kwargs):
     56         dist = object.__new__(cls)
---> 57         dist.__init__(*args, **kwargs)
     58         return dist
     59 

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\pymc3\distributions\continuous.py in __init__(self, mu, sigma, tau, sd, **kwargs)
    468 
    469         self.mean = self.median = self.mode = self.mu = mu = tt.as_tensor_variable(floatX(mu))
--> 470         self.variance = 1. / self.tau
    471 
    472         assert_negative_support(sigma, 'sigma', 'Normal')

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\tensor\var.py in __rtruediv__(self, other)
    204 
    205     def __rtruediv__(self, other):
--> 206         return theano.tensor.basic.true_div(other, self)
    207 
    208     def __rfloordiv__(self, other):

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\op.py in __call__(self, *inputs, **kwargs)
    667 
    668                 # compute output value once with test inputs to validate graph
--> 669                 thunk = node.op.make_thunk(node, storage_map, compute_map,
    670                                            no_recycling=[])
    671                 thunk.inputs = [storage_map[v] for v in node.inputs]

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\op.py in make_thunk(self, node, storage_map, compute_map, no_recycling, impl)
    952                               compute_map=compute_map, impl='c')
    953             try:
--> 954                 return self.make_c_thunk(node, storage_map, compute_map,
    955                                          no_recycling)
    956             except (NotImplementedError, utils.MethodNotDefined):

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\op.py in make_c_thunk(self, node, storage_map, compute_map, no_recycling)
    855                 raise NotImplementedError("float16")
    856         _logger.debug('Trying CLinker.make_thunk')
--> 857         outputs = cl.make_thunk(input_storage=node_input_storage,
    858                                 output_storage=node_output_storage)
    859         thunk, node_input_filters, node_output_filters = outputs

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cc.py in make_thunk(self, input_storage, output_storage, storage_map, keep_lock)
   1213         """
   1214         init_tasks, tasks = self.get_init_tasks()
-> 1215         cthunk, module, in_storage, out_storage, error_storage = self.__compile__(
   1216             input_storage, output_storage, storage_map,
   1217             keep_lock=keep_lock)

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cc.py in __compile__(self, input_storage, output_storage, storage_map, keep_lock)
   1151         input_storage = tuple(input_storage)
   1152         output_storage = tuple(output_storage)
-> 1153         thunk, module = self.cthunk_factory(error_storage,
   1154                                             input_storage,
   1155                                             output_storage,

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cc.py in cthunk_factory(self, error_storage, in_storage, out_storage, storage_map, keep_lock)
   1621             for node in self.node_order:
   1622                 node.op.prepare_node(node, storage_map, None, 'c')
-> 1623             module = get_module_cache().module_from_key(
   1624                 key=key, lnk=self, keep_lock=keep_lock)
   1625 

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cmodule.py in module_from_key(self, key, lnk, keep_lock)
   1187             try:
   1188                 location = dlimport_workdir(self.dirname)
-> 1189                 module = lnk.compile_cmodule(location)
   1190                 name = module.__file__
   1191                 assert name.startswith(location)

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cc.py in compile_cmodule(self, location)
   1518         try:
   1519             _logger.debug("LOCATION %s", str(location))
-> 1520             module = c_compiler.compile_str(
   1521                 module_name=mod.code_hash,
   1522                 src_code=src_code,

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2418             open(os.path.join(location, "__init__.py"), 'w').close()
   2419             assert os.path.isfile(lib_filename)
-> 2420             return dlimport(lib_filename)
   2421 
   2422 

c:\users\webblab\appdata\local\programs\python\python38-32\lib\site-packages\theano\gof\cmodule.py in dlimport(fullpath, suffix)
    315             warnings.filterwarnings("ignore",
    316                                     message="numpy.ndarray size changed")
--> 317             rval = __import__(module_name, {}, {}, [module_name])
    318         t1 = time.time()
    319         import_time += t1 - t0

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

我的协作者在其Macbook上运行相同的代码时未收到此错误,因此问题与代码无关。我用pip安装了所有软件包。任何帮助将不胜感激,这使我在该项目上处于停顿状态。

0 个答案:

没有答案