Reputation: 7173
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:
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.
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).
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?
Upvotes: 1
Views: 10511
Reputation: 306
I struggled with this - I kept getting an error saying package couldn't be found.
Running below in command prompt worked for me.
conda install -c asmeurer pattern=2.5
Upvotes: 1
Reputation: 11
Sometimes this happens when you have multiple versions of Python/Anaconda installed on your machine. As the Pattern package does not run on Python 3.4, you need to launch IPython Notebook from the Anaconda server that runs Python 2.7.
So the first step is to make sure that you install the Pattern package using pip in the version of Anaconda that runs Python 2.7.
For example, C:\Users\MyName\Anaconda\Scripts\pip install pattern
The second step is to make sure that you run ipython notebook from the correct path.
For example, C:\Users\MyName\Anaconda\Scripts\ipython notebook
That should do it.
Upvotes: 0
Reputation: 587
On windows, open cmd.exe and type:
conda install pattern
This should do it ;)
Upvotes: 0