columbia-applied-data-science / rosetta

Tools, wrappers, etc... for data science with a concentration on text processing
Other
206 stars 47 forks source link

Image importing doesn't work #16

Open langmore opened 10 years ago

langmore commented 10 years ago

When docx is imported, docx imports Image (with a capital I). This doesn't work. It should (I believe) import image (with lower case). This works. I have image installed on my machine. I have done both pip install image and pip install Image, but only import image can work. For some reason, the version of docx being used says import Image, which is absolutely screwball since a Python module is never named with capital letters. I recommend finding a version of docx that works and then putting that in requirements.txt (also, there should be some way to enforce these requirements...not sure if that is set up.

Traceback below.

ImportError: Failed to import test module: test_text
Traceback (most recent call last):
  File "/Users/langmore/anaconda/lib/python2.7/unittest/loader.py", line 252, in _find_tests
    module = self._get_module_from_name(name)
  File "/Users/langmore/anaconda/lib/python2.7/unittest/loader.py", line 230, in _get_module_from_name
    __import__(name)
  File "/Users/langmore/lib/rosetta/rosetta/tests/test_text.py", line 13, in <module>
    from rosetta.text import text_processors, vw_helpers, nlp, converters
  File "rosetta/text/converters.py", line 7, in <module>
    from docx import opendocx, getdocumenttext
  File "/Users/langmore/anaconda/lib/python2.7/site-packages/docx.py", line 23, in <module>
    import Image
  File "/Users/langmore/anaconda/lib/python2.7/site-packages/PIL/Image.py", line 53, in <module>
    from PIL import _imaging as core
ImportError: dlopen(/Users/langmore/anaconda/lib/python2.7/site-packages/PIL/_imaging.so, 2): Library not loaded: libjpeg.8.dylib
  Referenced from: /Users/langmore/anaconda/lib/python2.7/site-packages/PIL/_imaging.so
  Reason: image not found
dkrasner commented 10 years ago

try installing Pillow - a better.more stable fork of PIL http://pillow.readthedocs.org/en/latest/

if that is good we can put Pillow in requirements

dkrasner commented 10 years ago

another option is to use this perl based unix util, but the requires another outside dependency which so far seems pretty easy to install (as long as you have perl)

langmore commented 10 years ago

pillow didn't work. It was actually already installed.

langmore commented 10 years ago

This might be already obvious, but this incompatibility is not rosetta related. It's really just an issue with docx compatability. I can't import docx. The installer for docx should specify the software it needs. Maybe just look at the code in docx and see what's going on.

dkrasner commented 10 years ago

docx specifies PIL and the latest version of PIL doesn't install properly

ApproximateIdentity commented 10 years ago

I'm not using anaconda, but 'import Image' shows up in PIL, Pillow, matplotlib, and scipy for me. Here are some threads about it:

http://stackoverflow.com/questions/8339991/why-in-python-sometimes-from-pil-import-image-fails-and-import-image-works

http://stackoverflow.com/questions/19126305/pil-image-importerror

The second link seems to say that replacing 'import Image' with 'from PIL import Image' should solve most problems (for example 'import Image' doesn't work for me, but 'from PIL import Image' does.

In my version of docx.py it has the following import statement at the top:

try: from PIL import Image except ImportError: import Image

Since the first try block works for me, I see no error. Does this mean that running 'from PIL import Image' does not work for you?

ApproximateIdentity commented 10 years ago

Here's a blog post about a bit of a hack that could solve this problem:

http://reinout.vanrees.org/weblog/2013/09/24/pil-pillow-image-import.html

It might work for you, but I can't really test it myself since everything seems to be importing correctly for me. Maybe anaconda has an old verion of docx or PIL or something that has this error?

gerrywastaken commented 9 years ago

For me all I needed to do was "sudo pip install --upgrade pillow". It uninstalled Pillow 2.3.2 and then reinstalled what seems to be the exact same version. Things then worked.