I'm relatively new to development and I've been attempting to setup an application I'm building in Django (on Windows 7, 64 bit) to accept image uploads via ImageField. I initially installed PIL, but found that I needed JPEG and PNG libraries first. So I uninstalled PIL using "pip uninstall pil" and setup the libraries at C:\zlib-1.2.7\zlib.lib and C:\jpeg-8d\libjpeg.lib. Afterwards, I went into the setup.py in PIL and changed the following:
JPEG_ROOT = "C:/jpeg-8d"
ZLIB_ROOT = "C:/zlib-1.2.7"
I then install via:
pip install C:\Imaging-1.1.7\
I got the following at the end of the install, which suggests there's JPEG and PNG support:
Installing collected packages: PIL
Running setup.py install for PIL
WARNING: '' not a valid package name; please use only.-separated package nam
es in setup.py
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform win32 2.6.6 (r266:84297, Aug 24 2010, 18:46:32)
[MSC v.1500 32 bit (Intel)]
--------------------------------------------------------------------
*** TKINTER support not available (Tcl/Tk 8.5 libraries needed)
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.
To check the build, run the selftest.py script.
Successfully installed PIL
Cleaning up...
However, I got following when testing with selftest.py, which suggests no support:
C:\Windows\system32>python C:\Imaging-1.1.7\selftest.py
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY
--------------------------------------------------------------------
Python modules loaded from C:\Users\ayan\Desktop\Imaging-1.1.7\PIL
Binary modules loaded from C:\Python26_x86\lib\site-packages\PIL
--------------------------------------------------------------------
*** PIL CORE support not installed
*** TKINTER support not installed
*** JPEG support not installed
*** ZLIB (PNG/ZIP) support not installed
*** FREETYPE2 support not installed
*** LITTLECMS support not installed
--------------------------------------------------------------------
I also tried to work with a JPEG and got following IOError:
C:\Users\Public\Pictures\Sample Pictures>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>> import os, sys
>>> import Image
>>> img = Image.open(Desert.jpg)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Desert' is not defined
>>> img = Image.open("Desert.jpg")
>>> img.save("Desert_test.jpg")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26_x86\lib\site-packages\PIL\Image.py", line 1406, in save
self.load()
File "C:\Python26_x86\lib\site-packages\PIL\ImageFile.py", line 189, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "C:\Python26_x86\lib\site-packages\PIL\Image.py", line 385, in _getdecode
r
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available
This is somewhat similar to what was reported at https://stackoverflow.com/questions/10543581/pil-installation-run-issue; however, it appears that in this case, JPEGs actually aren't working. A similar problem is observed with PNGs.
It's not clear to me where in the process I've made a mistake, so any comments would be greatly appreciated. Please let me know if additional information is required, I'll endeavor to do by best to provide it.
Many thanks.
I have solved something similar but just for png support. I believe you can do the same for jpeg support as well.
First I would recommend using Pillow, a fork of PIL.
The solution I used is to manually compile on my machine (win7 64 bit) the zlib library.
And then manualy compiling the Pillow Package. I edited the Setup.py like you did to point at a directory where I put the zlib I just compiled.
I would suggest you manually compile the jpeg lib as well, and the zlib and then compile Pillow again. Make sure to uninstall previous versions of PIL/Pillow before doing it.
The link for my detailed answer of how to do it with zlib is:
https://stackoverflow.com/a/17190972/2501083
Hope this helps
Related
In python code, I need to process webp images. But when I try to open it with python PIL module, I have an error:
OSError: cannot identify image file 'my_image.webp
My Deep Learning image is created from GCP Marketplace VM (tensorflow image), but it seems that webp format is not "activated" at the pillow level.
Is the webp format supported in python by default?
What do I need to do/install/import on the VM to be able to open webp images with python PIL?
My python code steps:
>>>import PIL
>>>print(PIL.__version__)
6.0.0.post0
>>>from PIL import features
>>>print (features.check_module('webp'))
False
>>> PIL.Image.open('my_image.webp')
/usr/local/lib/python3.5/dist-packages/PIL/Image.py:2703: UserWarning: image file could not be identified because WEBP support not installed
warnings.warn(message)
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-4-99a62d35da67> in <module>
----> 1 PIL.Image.open('BATIMENT0000000045936174_flatRoof.webp')
/usr/local/lib/python3.5/dist-packages/PIL/Image.py in open(fp, mode)
2703 warnings.warn(message)
2704 raise IOError("cannot identify image file %r"
-> 2705 % (filename if filename else fp))
2706
2707 #
OSError: cannot identify image file 'my_image.webp'
Open JupyterLab UI of your GCP VM and run a Terminal session. In the terminal run these commands to install webp library:
pip uninstall Pillow
pip uninstall Pillow-SIMD
sudo apt install libwebp-dev
pip install Pillow-SIMD
Restart your Jupyter kernel. Now PIL is able te read webp images.
Ran into a similar issue on one of my servers.
Used the commands mentioned above, but was still getting False when running features.check_module('webp')
Turns out when reinstalling Pillow-SIMD, you need to make sure you're not using the cached version of the build, otherwise you won't get the WEBP support. So changing the last step to: pip install Pillow-SIMD --no-cache-dir solved it for me.
I would've added this as a comment but I don't have enough rep!
I have seen many more or less related questions on this topic, but none helped me finding a way to solve my problem.
I'm not very familiar with Windows environment, deep apologies if my question sounds obvious to some extent.
Setup:
Windows 10
Python 3.7.0 (installed through latest Anaconda release)
Spyder 3.3.1
Im running a Python, that involves several modules import. I came across some module issues. For example:
from PIL import Image as PIL_Image
Works smooth in Spyder, but gives (error message in french but I guess you got the point):
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\my_user_name\Anaconda3\lib\site-packages\PIL\Image.py", line 64, in <module>
from . import _imaging as core
ImportError: DLL load failed: Le module spécifié est introuvable.
If executed in Powershell or cmd.
What I tried:
Appending Anaconda's install path to my path variable before I open Powershell:
$Env:path += ";C:\Users\my_user_name\Anaconda3;C:\Users\my_user_name\Anaconda3\Scripts"
Checking that sys.path is the same in Powershell and Spyder. For both, it looks like:
['',
'C:\\Users\\my_user_name',
'C:\\Users\\my_user_name\\Anaconda3\\python37.zip',
'C:\\Users\\my_user_name\\Anaconda3\\DLLs',
'C:\\Users\\my_user_name\\Anaconda3\\lib',
'C:\\Users\\my_user_name\\Anaconda3',
'C:\\Users\\my_user_name\\AppData\\Roaming\\Python\\Python37\\site-packages',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\win32',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\win32\\lib',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\Pythonwin',
'C:\\Users\\my_user_name\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
'C:\\Users\\my_user_name\\.ipython']
What else could explain that my import fails outside of Spyder ?
Ok I could not find a clean way out, so let me just share my experience in case someone finds it helpful ...
The DLL failure with PIL related libs seems to be a known issue. See further explanations:
https://github.com/python-pillow/Pillow/issues/2945
PIL: DLL load failed: specified procedure could not be found
How I solved my issue:
Cleanly uninstalled anything related to Python on my laptop. Both Anaconda, isolated Python installs, Spyder ...
Re-installed the latest Anaconda. It happens to come with Python 3.7.1 instead of 3.7.0
Re-did my PIP installs of everything. Note I had to append Anaconda\Library\bin to my Windows path for PIP to work completely, which I don't recall having done with my previous installation.
I have tried pip install psycopg2 and following errors i got:
Error:
(ScrapeProj) C:\Users\e2sn7cy\Documents\GitHub\scraper>pip install psycopg2==2.5.4
Collecting psycopg2==2.5.4
Using cached psycopg2-2.5.4.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info\psycopg2.egg-info
writing pip-egg-info\psycopg2.egg-info\PKG-INFO
writing top-level names to pip-egg-info\psycopg2.egg-info\top_level.txt
writing dependency_links to pip-egg-info\psycopg2.egg-info\dependency_links.txt
writing manifest file 'pip-egg-info\psycopg2.egg-info\SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
Error: pg_config executable not found.
Please add the directory containing pg_config to the PATH
or specify the full executable path with the option:
python setup.py build_ext --pg-config /path/to/pg_config build ...
or with the pg_config option in 'setup.cfg'.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\e2sn7cy\appdata\local\temp\pi
p-build-joij3x\psycopg2
Then I tried using easy_install by downloading the .exe file from Stickpole and I got following errors :
(ScrapeProj) C:\Users\e2sn7cy\Envs\ScrapeProj\Scripts>easy_install psycopg2-2.6.1.win-amd64-py2.7-pg9
.4.4-release.exe
Processing psycopg2-2.6.1.win-amd64-py2.7-pg9.4.4-release.exe
psycopg2.tests.test_module: module references __file__
psycopg2.tests.test_types_basic: module references __file__
creating 'c:\users\e2sn7cy\appdata\local\temp\easy_install-sa7asq\psycopg2-2.6.1-py2.7-win32.egg' and
adding 'c:\users\e2sn7cy\appdata\local\temp\easy_install-sa7asq\psycopg2-2.6.1-py2.7-win32.egg.tmp'
to it
creating c:\users\e2sn7cy\envs\scrapeproj\lib\site-packages\psycopg2-2.6.1-py2.7-win32.egg
Extracting psycopg2-2.6.1-py2.7-win32.egg to c:\users\e2sn7cy\envs\scrapeproj\lib\site-packages
Adding psycopg2 2.6.1 to easy-install.pth file
Installed c:\users\e2sn7cy\envs\scrapeproj\lib\site-packages\psycopg2-2.6.1-py2.7-win32.egg
Processing dependencies for psycopg2==2.6.1
Finished processing dependencies for psycopg2==2.6.1
But when I again tried to install through pip I am getting a new message that its already there :
(ScrapeProj) C:\Users\e2sn7cy\Envs\ScrapeProj>pip install psycopg2
Requirement already satisfied (use --upgrade to upgrade): psycopg2 in c:\users\e2sn7cy\envs\scrapepro
j\lib\site-packages\psycopg2-2.6.1-py2.7-win32.egg
Then I thought ok I should try to import and then I got this error:
(ScrapeProj) C:\Users\e2sn7cy\Envs\ScrapeProj>python
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\e2sn7cy\Envs\ScrapeProj\lib\site-packages\psycopg2-2.6.1-py2.7-win32.egg\psycopg2\__
init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: DLL load failed: %1 is not a valid Win32 application.
Now I am not able to understand what to do. Thanks
Edit 1:
I have also added my PostgreSQL path to system path variables
path:C:\Program Files\PostgreSQL\9.4
path:C:\Program Files\PostgreSQL\9.4\bin
The correct answer was given by Craig Ringer, I am just adding this because I came to know that we should first check which version of 64 bit or 32bit Python installed on our system. If you have 32 bit version of Python and if you will try to install 64bit, then you will get the above error on importing.
For checking the version:
import platform
platform.architecture()
and you will get an output like this:
('32bit','WindowsPE')
Download the pre-packaged binary release of psycopg2 for Windows rather than compiling it yourself. It's a pain to compile on Windows. This is explained in the install documentation for psycopg2.
You might need to remove your half-installed attempts.
Choose the appropriate version from this page:
http://www.stickpeople.com/projects/python/win-psycopg/
Right click and select copy link address
Back at home, use easy_install <<Paste URL Here>>
Freeze your new requirements: pip freeze > requirements.txt
Now that psycopg is in PyPI (as of March 2017 it appears), just fire up a command prompt with administrator privileges and install like so:
python -m pip install -U pip
python -m pip install psycopg2
If you don't have pip installed, follow the instructions here to do that first:
https://stackoverflow.com/a/12476379/2540707
pip install psycopg2-binary
This worked for me
Step 1: Compilers Installation and configuration
https://wiki.python.org/moin/WindowsCompilers
Before do anything, install or upgrade the Setuptools Python package. It contain compatibility improvements and add automatic use of compilers:
pip install --upgrade setuptools
Step 2: Download and install PostgreSQL
Before you continue to install python packages inside you virtualenvs download postgres itself. It contains files that are needed when compiling the psycopg2 python package. Just use the PostgreSQL installer(version 10 for example).
Important: add the postgres C:\Program Files\PostgreSQL\10\bin folder to your path. It contains the .dll needed for psycopg2.
Step 3: Install psycopg2
pip install psycopg2
Tested on Windows 7 + python 3.7
The best/easiest way of installing packages (including this problematic psycopg2 ) for python on windows platform is to:
1) install anaconda and ...
2) use Anaconda Navigator GUI to install/update packages.
By this one avoids many inconsistencies and conflicts that occurs among different packages versions and installations.
I am having difficulty on my server trying to get the selftest.py to run successfully.
I am trying to get PIL 1.1.7 working with Python 2.4.4 (Are the versions compatible?)
When the install is preformed like so:
# python2.4 setup.py install
running install
running build
running build_py
running build_ext
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform linux2 2.4.6 (#1, Dec 21 2012, 14:54:30)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]
--------------------------------------------------------------------
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.
To check the build, run the selftest.py script.
running build_scripts
running install_lib
running install_scripts
changing mode of /usr/local/bin/pilconvert.py to 755
changing mode of /usr/local/bin/pilprint.py to 755
changing mode of /usr/local/bin/pilfile.py to 755
changing mode of /usr/local/bin/pilfont.py to 755
changing mode of /usr/local/bin/pildriver.py to 755
creating /usr/local/lib/python2.4/site-packages/PIL.pth
Everything seems handy dandy. Jpeg support is available and all is happy. But the selftest.py however is a different story:
# python2.4 /usr/local/src/Imaging-1.1.7/selftest.py
--------------------------------------------------------------------
PIL 1.1.7 TEST SUMMARY rc/Imaging-1.1.7]# yum install libjpeg62-devel zlib1g-devel libfreetype6-devel liblcms1-develp
--------------------------------------------------------------------
Python modules loaded from ./PIL
Binary modules loaded from ./PIL
--------------------------------------------------------------------
--- PIL CORE support ok
*** TKINTER support not installed
*** JPEG support not installed
*** ZLIB (PNG/ZIP) support not installed
--- FREETYPE2 support ok
*** LITTLECMS support not installed
--------------------------------------------------------------------
Running selftest:
*****************************************************************
Failure in example:
try:
_info(Image.open(os.path.join(ROOT, "Images/lena.jpg")))
except IOError, v:
print v
from line #24 of selftest.testimage
Expected: ('JPEG', 'RGB', (128, 128))
Got: decoder jpeg not available
1 items had failures:
1 of 57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.
I get the dreaded Jpeg decoder not available.
I've tried a variety of things. I changed the setup to point to usr/lib64 that didn't work. I made some symbolic links in the usr/lib to point to the libjpeg.so file, that also didn't work. I went back and forth with the tech guys at our server hosting place and they aren't understanding the issue and it's like talking to a wall. I am really stuck. The only thing I haven't tried is the PiP but I didn't try that because I don't know how that works exactly. So I want to avoid that.
Is there a compatibility issue or a setting I just don't have quite right?
Thank you for the assistance.
--UPDATE--
Working on this problem again these days
I've tested Centos 5 & 6 32-bit And everything installs like a charm, but 64-bit I'm still having issues.
It seems like the selftest works with the stock python2.6 but not with python2.4. Pil 1.1.7 is compatable with 2.4.4 but I think there is a problem with the libraries in 64-bit. Still searching for a solution.
After extensive testing it's just not possible.
I'm sure it can be done but the steps it would require to get it down would be so intensive that it would make it difficult to gaurentee the stability of the server/system.
The problem really lies in the 64-bit system. The Python-Imagining would work with python 2.4 if python 2.4 was compiled as 32-bit. However even if you get Python-2.4 compiled into 32-bit it has a hard time with the libraries since everything in Centos is build for the 64 arch. And getting those additional libraries is cumbersome since the repos won't include the structures you need to get it working. It's just, annoying. It's not feasible to go hunting around in circles and the time spent trying to support such a limping system is wasted. And possibly puts the system at risk.
No, it's not possible to install PIL for Python 2.4 on a 64-bit machine.
In my case we had no support of all the libraries in PIL (CentOS 6, x64)
*** TKINTER support not available
*** JPEG support not available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
So we used following:
yum install freetype freetype-devel libpng libpng-devel libjpeg libjpeg-devel
And now we have
*** TKINTER support not available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
--- FREETYPE2 support available
*** LITTLECMS support not available
3 years later, I know, but this can work just fine! The standard build process will not look for libraries in /usr/lib64, but you can't specify a library path when running setup.py build, so you need to rebuild the binaries afterwards in a separate step:
yum install freetype-devel libpng-devel libjpeg-turbo-devel libzip-devel lcms-devel
pip download PIL
unzip pil-1.1.7.zip
cd pil-1.1.7
./setup.py build
./setup.py build_ext -L /usr/lib64/:/usr/local/lib64 --force
./setup.py install --prefix /usr/local/python27 --force --skip-build
This is on Scientific Linux 6.7 64-bit, using Python 2.7 compiled from source.
I built and installed PIL on my CentOS 6.2 with Python 2.7 by executing build, build_ext -i and install. I had to change the library paths so that all supports are given.
When I run the selftest.py it says that everything is ok and all supports are given (especially JPEG).
When running my program which opens a jpeg, adds something, and saves it I get the error:
File "/opt/python2.7.2/lib/python2.7/site-packages/PIL/Image.py", line 401, in _getencoder
raise IOError("encoder %s not available" % encoder_name)
IOError: encoder jpeg not available
My program works fine on other systems and it runs on the centOS machine fine when I change it to png. I ran all commands with python2.7, and I already tried to reinstall PIL.
So in short: before installing PIL it runs within the selftest successfully, but after installing it it does not work any more.
I found the solution in the ubuntu forums
1/ Call 'pip install -I pil --no-install' to download and unpack the PIL source into your
build directory;
2/ Get into your build directory and edit setup.py;
3/ Find the line that says 'add_directory(library_dirs, "/usr/lib")' (line 214 here);
4/ Add the line 'add_directory(library_dirs, "/usr/lib/i386-linux-gnu")' afterwards;
5/ Call 'pip install -I pil --no-download' to finish the installation.