Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
470 views
in Technique[技术] by (71.8m points)

Package (Python PIL/Pillow) installed but I can't import it

I've been using python for simple data processing scripts, but now I want to do some image processing and I encountered a problem. Importing the pillow module doesn't seem to work. I found a simple script here to check what packages are installed and I found it, but importing it doesn't seem to work.

Here's the code I'm trying to run:

import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
     for i in installed_packages])
print(installed_packages_list)

import pillow

And here's the result:

runfile('C:/Users/Augustas/.spyder2/temp.py', wdir=r'C:/Users/Augustas/.spyder2')
['-curses==2.2', 'aafigure==0.5', 'alembic==0.7.1', 'apptools==4.2.1', 'argparse==1.2.2', 'astroid==1.3.2', 'astropy==0.4.2', 'atom==0.3.10', 'babel==1.3', 'backports.ssl-match-hostname==3.4.0.2', 'beaker==1.6.4', 'beautifulsoup4==4.3.2', 'beautifulsoup==3.2.1', 'blockcanvas==4.0.3', 'blosc==1.2.4', 'bottleneck==0.8.0', 'cchardet==0.3.5', 'cdecimal==2.3', 'certifi==14.05.14', 'cffi==0.8.6', 'chaco==4.5.0', 'chardet==2.3.0', 'codetools==4.2.0', 'colorama==0.3.2', 'configobj==5.0.6-xy.1', 'configparser==3.3.0r2', 'cov-core==1.15.0', 'coverage==3.7.1', 'cryptography==0.6.1', 'cssselect==0.9.1', 'cvxopt==1.1.7', 'cvxpy==0.2.15', 'cx-freeze==4.3.3', 'cython==0.21.1', 'datrie==0.7', 'decorator==3.4.0', 'dill==0.2.1', 'distlib==0.1.9', 'docutils-aafigure==0.3', 'docutils==0.12', 'ecdsa==0.12.dev1', 'ecos==1.0.5', 'ed25519ll==0.6', 'egenix-mx-base==3.2.8', 'enable==4.4.1', 'enaml==0.9.8', 'enamllexer==0.0.0', 'encore==0.6.0', 'enum34==1.0.4', 'envisage==4.4.0', 'ets==4.4.4', 'etsdevtools==4.0.2', 'etsproxy==0.1.2', 'execnet==1.2.0', 'fabric==1.10.0', 'faulthandler==2.4', 'ffnet==0.7.1', 'fonttools==2.4', 'formlayout==1.0.15', 'funcsigs==0.4', 'futures==2.2.0', 'gdal==1.11.1', 'gevent-websocket==0.9.3', 'gevent==1.0.1', 'graphcanvas==4.0.2', 'greenlet==0.4.5', 'grin==1.2.1-xy1', 'guidata==1.6.1', 'guiqwt==2.3.2', 'h5py==2.3.1', 'html5lib==0.999', 'imageio==0.5.1', 'imread==0.5.1-git.xy.1', 'ipdb==0.8', 'ipdbplugin==1.4.1', 'ipython==2.3.1', 'jaraco.timing==1.1', 'jaraco.util==10.6.2dev', 'jaraco.windows==3.1.2dev', 'jdcal==1.0', 'jinja2==2.7.3', 'keyring==4.0', 'kiwisolver==0.1.3', 'logilab-common==0.63.2', 'lxml==3.4.1', 'mahotas==1.2.3', 'mako==1.0.0', 'markupsafe==0.23', 'matplotlib==1.4.2', 'mayavi==4.3.1', 'mdp==3.3', 'mock==1.0.1', 'modernize==0.4', 'more-itertools==2.3.dev', 'ndg-httpsclient==0.3.3', 'netcdf4==1.1.1', 'netifaces==0.10.4', 'networkx==1.9.1', 'nose-cov==1.6', 'nose-fixes==1.3', 'nose==1.3.4', 'numexpr==2.4', 'numpy==1.8.2', 'objgraph==1.8.1', 'opencv-python==2.4.9', 'openpyxl==2.1.3', 'pandas==0.15.2', 'paramiko==1.15.1', 'pathlib==1.0.1', 'patsy==0.3.0', 'pdfrw==0.1', 'pep8==1.5.7', 'pillow==2.6.1', 'ply==3.4', 'polygon==2.0.5', 'pp==1.6.4', 'psutil==2.1.3', 'py2exe==0.6.9', 'py==1.4.26', 'pyamg==2.1.0', 'pyasn1-modules==0.0.5', 'pyasn1==0.1.8rc2', 'pyaudio==0.2.8', 'pycares==0.6.3', 'pycparser==2.11.dev1', 'pycrypto==2.6.1', 'pycurl==7.19.5', 'pydicom==0.9.9', 'pyemf==2.0.0', 'pyface==4.4.0', 'pyflakes==0.8.1', 'pygments==2.0.1', 'pygraphviz==1.3.dev', 'pyhdf==0.8.3', 'pyhyphen==2.0.5', 'pyicu==1.8-xy.1', 'pylint==1.4.0', 'pymc==2.3.4', 'pyminuit==1.2.1', 'pyodbc==3.0.7', 'pyopengl-accelerate==3.1.0', 'pyopengl==3.1.0', 'pyopenssl==0.14', 'pyparallel==0.2', 'pyparsing==2.0.3', 'pypdf2==1.23', 'pypdf==1.13', 'pyreadline==2.0.6-xy.1', 'pyserial==2.7', 'pytest-bench==0.3.0', 'pytest-cache==1.0', 'pytest-cov==1.8.1', 'pytest-flakes==0.2', 'pytest-pep8==1.0.6', 'pytest-runner==2.1.2', 'pytest-xdist==1.11', 'pytest==2.6.4', 'python-dateutil==2.3', 'pytz==2014.10', 'pyvisa==1.6.1', 'pywavelets==0.2.2', 'pywin32==219', 'pywin==0.3.1', 'pywinauto==0.4.2', 'pyyaml==3.11', 'pyzmq==14.4.1', 'reportlab==3.1.10', 'requests==2.5.0', 'rope==0.10.2', 'rst2pdf==0.93', 'sampy==1.2.1', 'scikit-image==0.10.1', 'scikit-learn==0.15.2', 'scimath==4.1.2', 'scipy==0.14.0', 'scs==1.0.6', 'seaborn==0.5.1', 'sendkeys==0.3', 'simplejson==3.6.5', 'singledispatch==3.4.0.3', 'six==1.8.0', 'smc.freeimage==0.3dev', 'sphinx==1.2.3', 'sphinxcontrib-aafig==1.0', 'sphinxcontrib-napoleon==0.2.8', 'spyder==2.3.2', 'sqlalchemy==0.9.8', 'statsmodels==0.6.1', 'svg2rlg==0.3', 'svglib==0.6.3', 'sympy==0.7.6', 'tables==3.1.1', 'tempita==0.5.2', 'termcolor==1.1.0', 'toolz==0.7.0', 'tornado==4.0.2', 'traits==4.5.0', 'traitsui==4.4.0', 'ttfquery==1.0.5', 'ujson==1.33', 'uncertainties==2.4.6.1', 'unittest2==0.8.0', 'veusz==1.22', 'virtualenv==1.11.6', 'virtualenvwrapper-win==1.1.5', 'vitables==2.1', 'vpython==5.74', 'vtk==5.10.1', 'wheel==0.24.0', 'whoosh==2.5.7', 'wincertstore==0.2', 'winpdb==1.4.8', 'wsaccel==0.6.2', 'wxpython-common==2.8.12.1', 'wxpython==2.8.12.1', 'xhtml2pdf==0.0.7.dev', 'xlrd==0.9.3', 'xlwt==0.7.5']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:Python27libsite-packagesspyderlibwidgetsexternalshellsitecustomize.py", line 601, in runfile
    execfile(filename, namespace)
  File "C:Python27libsite-packagesspyderlibwidgetsexternalshellsitecustomize.py", line 66, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "C:/Users/Augustas/.spyder2/temp.py", line 7, in <module>
    import pillow
ImportError: No module named pillow

I'm running this on Windows 8.1 using Spyder and Python 2.7.9

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are importing incorrectly. Try using:

import  PIL
from PIL import Image

PIL i.e Python Imaging Library is no longer maintained, Pillow is used instead. To maintain backwards compatibility, PIL module name is used in imports.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...