1

I'm a newbie to IPython/Anaconda (for Windows 7), and for some reason, I'm getting an import error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-6-484073d472a5> in <module>()
      6 import matplotlib.pyplot as plt
      7 import requests
----> 8 import pattern

ImportError: No module named pattern

Here's what I did to set up Anaconda/IPython:

  1. Installed Anaconda. I already have a version of python on this computer. The Anaconda distribution was installed to C:\Users\MyName, while the regular python distribution (2.7) was installed to C:\Python27.

  2. When I tried to import some packages (sklearn, pandas, requests, pattern), for some reason those packages just wouldn't import so I installed them manually (downloading them to a local folder on my desktop and running $ python setup.py install, and after that it all seemed to work).

  3. I can run IPython notebooks fine. However, when I try to import pattern specifically, I get that error (which I don't get for sklearn or any of the other packages I installed manually). Printing my sys path from the terminal (import sys print sys.path) and IPython notebook gives:

Terminal:

    ['C:\\Users\\MyName\\Desktop\\Data Science\\cs109\\Labs', 'C:\\python27\\lib\\site- 
    packages\\mrjob-0.4.2_dev-py2.7.egg', 'C:\\python27\\lib\\site- 
    packages\\simplejson-3.3.1- 
    py2.7.egg', 'C:\\python27\\lib\\site-packages\\pyyaml-3.10-py2.7-win32.egg',  
    'C:\\python27\\lib\\site-packages\\boto-2.18.0-py2.7.egg',  
    'C:\\python27\\lib\\site-packages\\requests-2.0.1-py2.7.egg',  
    'C:\\Windows\\system32\\python27.zip',  
    'C:\\Python27\\lib\\site-packages\\Orange\\orng', 'C:\\python27\\DLLs',  
    'C:\\python27\\lib', 'C:\\python27\\lib\\plat-win', 'C:\\python27\\lib\\lib-tk',  
    'C:\\python27', 'C:\\python27\\lib\\site-packages', 'C:\\python27\\lib\\site- 
    packages\\PIL', 'C:\\python27\\lib\\site-packages\\win32',  
    'C:\\python27\\lib\\site- 
    packages\\win32\\lib', 'C:\\python27\\lib\\site-packages\\Pythonwin']

IPython notebook:

    ['', 'C:\\Users\\MyName\\Anaconda\\python27.zip', 'C:\\Python27\\lib\\site-                 
    packages\\Orange\\orng', 'C:\\Users\\MyName\\Anaconda\\DLLs',  
    'C:\\Users\\MyName\\Anaconda\\lib', 'C:\\Users\\MyName\\Anaconda\\lib\\plat-win',  
    'C:\\Users\\MyName\\Anaconda\\lib\\lib-tk', 'C:\\Users\\MyName\\Anaconda',  
    'C:\\Users\\MyName\\Anaconda\\lib\\site-packages',  
    'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\PIL',  
    'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\win32',  
    'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\win32\\lib',  
    'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\Pythonwin',  
    'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg- 
    info', 'C:\\Users\\MyName\\Anaconda\\lib\\site-packages\\IPython\\extensions']

If I do

    import pattern
    print pattern

It shows that pattern is located at:

    C:\python27\lib\site-packages\pattern\__init.pyc

Any thoughts as to why IPython can't import pattern?

4

3 回答 3

1

我为此苦苦挣扎 - 我一直收到一个错误消息,说找不到包。

在命令提示符下运行对我有用。

conda install -c asmeurer pattern=2.5
于 2017-02-02T12:53:30.340 回答
0

在 Windows 上,打开 cmd.exe 并键入:

conda install pattern

这应该这样做;)

于 2013-12-03T23:02:56.350 回答
0

当你的机器上安装了多个版本的 Python/Anaconda 时,有时会发生这种情况。由于 Pattern 包不在 Python 3.4 上运行,您需要从运行 Python 2.7 的 Anaconda 服务器启动 IPython Notebook。

所以第一步是确保在运行 Python 2.7 的 Anaconda 版本中使用 pip 安装 Pattern 包。

例如,C:\Users\MyName\Anaconda\Scripts\pip 安装模式

第二步是确保从正确的路径运行 ipython notebook。

例如,C:\Users\MyName\Anaconda\Scripts\ipython 笔记本

那应该这样做。

于 2015-05-08T04:21:11.913 回答