Challenge installing psd-tools on fresh Mac - python

I've been using PSD-TOOLS to great effect on a 13" notebook for half a year now (Python 2.7.3). Just tried to do a fresh install on a Mac running 10.8.4.
I ran through the python setup at http://docs.python-guide.org/en/latest/starting/install/osx/ (Python version
Installed Pil using:
sudo pip install pil
All my Pil scripts work fine.
pip list
shows PIL (1.1.7) installed fine.
Then tried to install psd-tools using:
sudo pip install psd-tools
Appears to install fine but when I run my PSD scripts, get the following:
File "/Library/Python/2.7/site-packages/psd_tools/user_api/psd_image.py", line 91, in as_PIL
return self._psd._layer_as_PIL(self._index)
File "/Library/Python/2.7/site-packages/psd_tools/user_api/psd_image.py", line 243, in _layer_as_PIL
return pil_support.extract_layer_image(self.decoded_data, index)
File "/Library/Python/2.7/site-packages/psd_tools/user_api/pil_support.py", line 32, in extract_layer_image
decoded_data.header.depth, get_icc_profile(decoded_data))
File "/Library/Python/2.7/site-packages/psd_tools/user_api/pil_support.py", line 68, in _channels_data_to_PIL
raise Exception("This module requires PIL (or Pillow) installed.")
Exception: This module requires PIL (or Pillow) installed.
Anybody run into this issue?

I ran into this issue on OSX 10.9 with Python 2.7.5. (In a virtualenv)
I ended up going over https://pypi.python.org/pypi/Pillow/2.2.1 and installing some optional prerequisites for Pillow.
#I already had libjpeg but this is the line in their doc.
brew install libtiff libjpeg webp littlecms
#Then re-installed Pillow
pip install --force-reinstall --upgrade pillow
The result was the following features enabled
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- TIFF G3/G4 (experimental) support available
*** FREETYPE2 support not available
--- LITTLECMS support available
--- WEBP support available
--- WEBPMUX support available
And my small python test ran
from PIL import Image
from psd_tools import PSDImage
psd = PSDImage.load('test_data/1.psd')
merged_image = psd.as_PIL()
Not sure which of those requirements was responsible so if you are not interested in installing extra libraries you may have to do 1 at a time or dig into the source.

Related

Libtiff not listed in library path on Win 7

After successfully installing libtiff on win7 I try to run:
tif = TIFF.open("sometiff.tiff")
I get the following error:
File "C:\Python27\ArcGIS10.2\lib\site-packages\libtiff\libtiff_ctypes.py",
line 41, in <module> raise
ImportError: Failed to find TIFF library.
Make sure that libtiff is installed and its location is listed in PATH|LD_LIBRARY_PATH|..
I'm not sure what I need to add to the windows path to make this work successfully.
The directory that contains the dll for libtiff needs to be in your PATH environment variable.
If you did pip install libtiff, then you would have installed it using libtiff from pypi. This seems to be a "wrapper" around libtiff, so you will also need to install the actual libtiff Setup program.
Depending on what you are doing, you may want to look into a more complete distribution of python on windows such as Anaconda, which seems to be quite popular, or Enthought, which the subscription version is well supported. (I believe there is a subscription version of Anaconda, but I have not used it.)

How to install scipy misc package

I have installed (actually reinstalled) scipy:
10_x86_64.whl (19.8MB): 19.8MB downloaded
Installing collected packages: scipy
Successfully installed scipy
But the misc subpackage is apparently not included?
16:03:28/shared $ipython
In [1]: from scipy.misc import imread
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-f9d3d927b58f> in <module>()
----> 1 from scipy.misc import imread
ImportError: cannot import name imread
What is the way to install the scipy.misc package?
I think you need to install PIL as well. From the scipy.misc docs:
Note that the Python Imaging Library (PIL) is not a dependency of SciPy and therefore the pilutil module is not available on systems that don’t have PIL installed.
I had same problem, running Python 2.7.12 on an old Windows XP/SP3 box. I had some stuff running on Python on MacBook, and wanted to make it work on an old Windows box. It can be done. The winbox had pip ver. 8, and I upgraded it to pip ver. 9, from within Python, using the suggestion pip provides when you run it. I had installed numpy and Pillow (current ver of PIL), using "pip install numpy" and "pip install Pillow", but "pip install scipy" and "pip install scipy.misc" failed with "no matching distribution found". I had to uninstall numpy, and then install two files: 1) numpy+mkl and then 2) scipy, both files installed are binaries for Windows, in .whl (wheel) archive format, downloaded from: http://www.lfd.uci.edu/~gohlke/pythonlibs/
site maitained by Christoph Gohlke. Find the binary versions you need for your flavour of Windows, and downloaded them into C:\some\directory. Installation order is important. First the numpy+mkl is installed, using pip, with the scipy file second. I downloaded the files from Gohlke's site, and then used pip to install them. For my old winbox, this was:
C:\some\directory\> pip install numpy-1.12.1rc1+mkl-cp27-cp27m-win32.whl
(you should see)
Installing collected packages: numpy
Successfully installed numpy-1.12.1rc1+mkl
(then, you can run)
C:\some\directory\> pip install scipy-0.18.1-cp27-cp27m-win32.whl
and you should see the "Successfully installed..." message. I had already installed Pillow.
Confirm by starting Python, and trying:
>>> import numpy as np
>>> from PIL import Image, ImageDraw
>>> import scipy.misc
and all these should work. You should be able to render a .jpg with:
image = Image.open("Somefile.jpg")
image.show()
and your somefile.jpg will be displayed.

Python Can't Find Modules

I'm running a python script which resizes and converts images to JPG and an RGB. This script worked perfectly until I upgraded my computers HD and moved everything over from my Time Machine backup. Now when I try to run the script it can't find any modules. Specifically the Image module (I use Pillow).
Traceback (most recent call last):
File "processImgs.py", line 1, in <module>
import os, sys, argparse, shutil, imgFunctions
File "/web/script/python/img_processing/imgFunctions.py", line 1, in <module>
import os, sys, Image, shutil, re
ImportError: No module named Image
I am using Homebrew to manage my modules, and "brew list" outputs the following:
freetype graphicsmagick libpng libtool little-cms2 openssl pkg-config readline webp
gdbm jpeg libtiff little-cms openjpeg pillow python sqlite
If i run "pip list" I get:
Pillow (2.3.0)
pip (1.5.4)
setuptools (2.2)
wsgiref (0.1.2)
If i run "help(modules)" in python, the Image module isn't listed.
Could be your python path isn't set up correctly after the move.
see here for the homebrew/python docs page and it seems that a reinstall of homebrew may fix it.

PNG display in PIL broken on OS X Mavericks?

I've noticed that PNG images aren't displaying in Tkinter apps using ImageTk.PhotoImage in OS X Mavericks. But, GIFs and JPEGs display fine. There's no error printed or exception thrown and debugging the code shows the image is read and has the correct height & width. Here's a simplified example:
import Tkinter
from PIL import Image, ImageTk
logo_file = 'test.png'
#logo_file = 'test.gif'
class Application(Tkinter.Frame):
def __init__(self, master):
Tkinter.Frame.__init__(self, master)
self.master.minsize(width=512, height=256)
self.master.config()
self.pack()
self.main_frame = Tkinter.Frame()
self.some_image = ImageTk.PhotoImage(Image.open(logo_file))
some_label = Tkinter.Label(self.main_frame, image=self.some_image)
some_label.config()
some_label.pack(side='top')
self.main_frame.place(in_=self.master, anchor='c', relx=.5, rely=.5)
root = Tkinter.Tk()
app = Application(root)
app.mainloop()
If you use a GIF the image will be displayed, but using a PNG it will not. Again, this is only happening on OS X Mavericks, Mountain Lion works fine. I've tried re-installing (compiling PIL) with no luck, as well as trying a new virtualenv.
Is there perhaps some PNG attribute I need to set correctly when creating/saving the PNG? Or is this a bug in PIL or Tkinter or OS X?
Update to add some details
I'm using:
Python 2.7.5 (/usr/bin/python)
PIL 1.1.7 (compiled using pip)
This is on a machine that was just updated to Mavericks from Mountain Lion, and previously had PIL installed, and I haven't messed with the system Python shipped by Apple.
Update 2 Pillow setup summary
I installed Pillow 2.2.1 and it says it has PNG support:
--------------------------------------------------------------------
PIL SETUP SUMMARY
--------------------------------------------------------------------
version Pillow 2.2.1
platform darwin 2.7.5 (default, Aug 25 2013, 00:04:04)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- TIFF G3/G4 (experimental) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
*** WEBP support not available
*** WEBPMUX support not available
--------------------------------------------------------------------
I also uninstalled and re-installed libpng using brew (libpng 1.5.14). I then re-installed Pillow to make sure it built with it, though I think it uses zlib.
Update 3 trying to build Python 2.7.5
Perhaps the issue is with zlib, trying to compile Python 2.7.5 I get this:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _sqlite3 _ssl
bsddb185 dbm dl
gdbm imageop linuxaudiodev
nis ossaudiodev readline
spwd sunaudiodev zlib
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
Failed to build these modules:
_tkinter
I think your problem is that your PIL was built without PNG support, or with only partial PNG support, on your Mavericks machine.
If PIL can't find both libpng and libz where it wants to, you won't have complete PNG support. And after upgrading from Mountain Lion to Mavericks, this seems to sometimes be a problem.
This may not be the same problem you're having. For example, it could be down to Apple using a buggy version of Tcl/Tk again (as they infamously did in Snow Leopard). But it's definitely worth trying.
With Pillow, and some versions of old-school PIL (but really, if you're not using Pillow, you almost definitely should be), the end of the install process gives you a friendly "PIL SETUP SUMMARY" section that shows you all the important configuration stuff.
I had the exact same problem with Pillow 2.2.1 on a locally-built Python 3.3.2. I solved it by using Homebrew to install libpng, then rebuilding Pillow:
$ brew install libpng
$ pip-3.3 uninstall pillow
$ pip-3.3 install pillow
I was experiencing the same problem and I did the following. It seems to be fixed.
sudo unistall pillow
xcode-select --install
pip install pillow
It seems to be working great. I also installed all the items below, but it seems you have it already installed
brew install libtiff libjpeg libpng webp littlecms
Did you install Pillow dependencies?
pip uninstall Pillow
brew install libtiff libjpeg webp littlecms
pip install Pillow
You will need HomeBrew to execute the brew command.
I installed Pillow from homebrew (brew install Pillow), all necessary dependencies will be installed automatically. Problem solved.

PIL: selftest fails, but package shows status is fine?

I have PIL installed with the required libraries (so I think). During installation it shows
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
--- LITTLECMS support available
However, when I run selftest.py, I get this:
*** PIL CORE support not installed
*** TKINTER support not installed
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
*** FREETYPE2 support not installed
*** LITTLECMS support not installed
i.e. it's not detecting PIL CORE, FREETYPE2 and LITTLECMS.
I installed the following packages on CentOS 6.0 using python 2.6.5
libjpeg libjpeg-devel zlib zlib-devel freetype freetype-devel lcms lcms-devel
PIL was installed with pip install PIL. However, the selftest was run from a source code from the offical PIL website.
Any ideas?
Try building the C extensions in-place in the source directory with setup.py build_ext -i before running selftest.py or Tests\run.py.

Categories

Resources