无法将模块导入 ipython

Trouble importing modules into ipython

在新安装的 Windows 10 机器上,我安装了最新的 64 位版本的 anaconda。现在,当我尝试将模块导入 ipython 时,出现错误。下面重现了一些示例错误。

我是 Python 和编程的新手,希望能提供一些帮助。这是一台全新的 Lenovo 笔记本电脑,因此不存在任何 Python 版本冲突等问题(因为之前没有安装任何东西)。

In [1]: import sklearn
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-b7c74cbf5af0> in <module>
----> 1 import sklearn

C:\Software\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
     74 else:
     75     from . import __check_build
---> 76     from .base import clone
     77     from .utils._show_versions import show_versions
     78

C:\Software\anaconda3\lib\site-packages\sklearn\base.py in <module>
     11 import re
     12
---> 13 import numpy as np
     14
     15 from . import __version__

C:\Software\anaconda3\lib\site-packages\numpy\__init__.py in <module>
    138
    139     # Allow distributors to run custom init code
--> 140     from . import _distributor_init
    141
    142     from . import core

C:\Software\anaconda3\lib\site-packages\numpy\_distributor_init.py in <module>
     32
     33 with RTLD_for_MKL():
---> 34     from . import _mklinit
     35
     36 del RTLD_for_MKL

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

In [2]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-a0d2faabd9e9> in <module>
----> 1 import matplotlib.pyplot as plt

C:\Software\anaconda3\lib\site-packages\matplotlib\__init__.py in <module>
    136 # cbook must import matplotlib only within function
    137 # definitions, so it is safe to import from it here.
--> 138 from . import cbook, rcsetup
    139 from matplotlib.cbook import (
    140     MatplotlibDeprecationWarning, dedent, get_label, sanitize_sequence)

C:\Software\anaconda3\lib\site-packages\matplotlib\cbook\__init__.py in <module>
     29 from weakref import WeakMethod
     30
---> 31 import numpy as np
     32
     33 import matplotlib

C:\Software\anaconda3\lib\site-packages\numpy\__init__.py in <module>
    138
    139     # Allow distributors to run custom init code
--> 140     from . import _distributor_init
    141
    142     from . import core

C:\Software\anaconda3\lib\site-packages\numpy\_distributor_init.py in <module>
     32
     33 with RTLD_for_MKL():
---> 34     from . import _mklinit
     35
     36 del RTLD_for_MKL

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

In [3]: import pystan
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-3-ca8618bb8e4a> in <module>
----> 1 import pystan

ModuleNotFoundError: No module named 'pystan'

In [4]:

经过大量 google 搜索,我发现了一些涉及一些密切相关问题的网站(例如 https://github.com/stan-dev/pystan/issues/520)。碰巧需要在 Windows 路径中添加一些 anaconda directroties。我在路径中添加了 anaconda/Library/binanaconda/Scripts。现在一切都按预期工作。