简体   繁体   English

无法在 jupyter 实验室中导入 pymc3

[英]cannot import pymc3 in jupyter lab

I'm new to Python and trying to run someone else's code in Jupyter Lab on my Mac.我是 Python 的新手,并试图在我的 Mac 上的 Jupyter Lab 中运行其他人的代码。 It requires a package pymc3 that I installed both in Terminal ( conda install pymc3 ) and from Jupyter Lab following these instructions :它需要一个 package pymc3 ,我在终端( conda install pymc3 )和 Jupyter Lab 按照以下说明安装:

import sys
!conda install --yes --prefix {sys.prefix} pymc3

I did the same with the package theano .我对 package theano做了同样的事情。 When I run import pymc3 I still get this error:当我运行import pymc3时,我仍然收到此错误:


You can find the C code in this temporary file: /var/folders/mv/512bfbj50lz_x1664zjjk3b80000gn/T/theano_compilation_error_jlqz137r

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
~/opt/anaconda3/lib/python3.7/site-packages/theano/gof/lazylinker_c.py in <module>
     80                     version,
---> 81                     actual_version, force_compile, _need_reload))
     82 except ImportError:

ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
~/opt/anaconda3/lib/python3.7/site-packages/theano/gof/lazylinker_c.py in <module>
    104                         version,
--> 105                         actual_version, force_compile, _need_reload))
    106         except ImportError:

ImportError: Version check of the existing lazylinker compiled file. Looking for version 0.211, but found None. Extra debug information: force_compile=False, _need_reload=True

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
~/opt/anaconda3/lib/python3.7/site-packages/theano/gof/vm.py in <module>
    673         raise theano.gof.cmodule.MissingGXX('lazylinker will not be imported if theano.config.cxx is not set.')
--> 674     from . import lazylinker_c
    675 

~/opt/anaconda3/lib/python3.7/site-packages/theano/gof/lazylinker_c.py in <module>
    139             cmodule.GCC_compiler.compile_str(dirname, code, location=loc,
--> 140                                              preargs=args)
    141             # Save version into the __init__.py file.

~/opt/anaconda3/lib/python3.7/site-packages/theano/gof/cmodule.py in compile_str(module_name, src_code, location, include_dirs, lib_dirs, libs, preargs, py_module, hide_symbols)
   2398             raise Exception('Compilation failed (return status=%s): %s' %
-> 2399                             (status, compile_stderr.replace('\n', '. ')))
   2400         elif config.cmodule.compilation_warning and compile_stderr:

Exception: Compilation failed (return status=1): In file included from /Users/afh/.theano/compiledir_Darwin-19.3.0-x86_64-i386-64bit-i386-3.7.6-64/lazylinker_ext/mod.cpp:1:. In file included from /Users/afh/opt/anaconda3/include/python3.7m/Python.h:25:. /Users/afh/opt/anaconda3/bin/../include/c++/v1/stdio.h:108:15: fatal error: 'stdio.h' file not found. #include_next <stdio.h>.               ^~~~~~~~~. 1 error generated.. 

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
<ipython-input-41-200e74b8195d> in <module>
----> 1 import pymc3

~/opt/anaconda3/lib/python3.7/site-packages/pymc3/__init__.py in <module>
      3 
      4 from .blocking import *
----> 5 from .distributions import *
      6 from .distributions import transforms
      7 from .glm import *

~/opt/anaconda3/lib/python3.7/site-packages/pymc3/distributions/__init__.py in <module>
----> 1 from . import timeseries
      2 from . import transforms
      3 from . import shape_utils
      4 
      5 from .continuous import Uniform

~/opt/anaconda3/lib/python3.7/site-packages/pymc3/distributions/timeseries.py in <module>
      1 from scipy import stats
----> 2 import theano.tensor as tt
      3 from theano import scan
      4 
      5 from pymc3.util import get_variable_name

~/opt/anaconda3/lib/python3.7/site-packages/theano/__init__.py in <module>
    108     object2, utils)
    109 
--> 110 from theano.compile import (
    111     SymbolicInput, In,
    112     SymbolicOutput, Out,

~/opt/anaconda3/lib/python3.7/site-packages/theano/compile/__init__.py in <module>
     10 from theano.compile.function_module import *
     11 
---> 12 from theano.compile.mode import *
     13 
     14 from theano.compile.io import *

~/opt/anaconda3/lib/python3.7/site-packages/theano/compile/mode.py in <module>
      9 import theano
     10 from theano import gof
---> 11 import theano.gof.vm
     12 from theano import config
     13 from six import string_types

~/opt/anaconda3/lib/python3.7/site-packages/theano/gof/vm.py in <module>
    681 except ImportError:
    682     pass
--> 683 except (OSError, theano.gof.cmodule.MissingGXX) as e:
    684     # OSError happens when g++ is not installed.  In that case, we
    685     # already changed the default linker to something else then CVM.

AttributeError: module 'theano' has no attribute 'gof'

I can tell this has something to do with file paths and environments, and someone with a similar problem fixed it by "setting up a separate conda env" , but I don't know how to do that.我可以说这与文件路径和环境有关, 有类似问题的人通过“设置单独的 conda env”修复了它,但我不知道该怎么做。 Any suggestions greatly appreciated.任何建议都非常感谢。

To create a new conda env for a specific version of Python, try the following:要为 Python 的特定版本创建新的 conda env,请尝试以下操作:

conda create -n myenv python=3.6

(see https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands ) (参见https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#creating-an-environment-with-commands

Alternatively, I've read that there was a problem on Mojave that can be addressed by installing theano from the pip repository:或者,我读到Mojave 存在一个问题,可以通过从 pip 存储库安装 theano 来解决:

pip install theano

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM