PIL installation under CentOS selftest fine but jpeg not working - centos

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.

Related

How can i use PIL in python?

I have successfully installed Pillow:
chris#MBPvonChristoph sources % python3 -m pip install --upgrade Pillow
Collecting Pillow
Using cached Pillow-9.0.1-1-cp310-cp310-macosx_11_0_arm64.whl (2.7 MB)
Installing collected packages: Pillow
Successfully installed Pillow-9.0.1
but when i try to use it in pycharm got:
Traceback (most recent call last):
File "/Users/chris/PycharmProjects/pythonProject2/main.py", line 1, in
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
or using in Blender i got:
ModuleNotFoundError: No module named 'PIL'
I am not a python lib installing pro...so obviously i made something wrong. But how do i fix that?
Maybe i have to say i am working on a M1 Macbook
looks like you may need to repoint your pycharm to your installed python interpreter.
go to command line and find out python interpreter path. On windows you can where python in your command line an it will give you where your python and packages are installed.. You could also activate python directly in command line and find paths from there. For example, open command line then;
python
press enter = activates python
within then you can do:
import sys
for x in sys.path: x
In pycharm make sure you point to path discovered from step 1 and select that to be your python interpreter within pycharm --- check out examples here https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#add-existing-interpreter
Should work. Not sure about all the steps you took, but if you installed python with pycharm on top of your regular installation of python i would recommend :
finding all the paths from step 1
deleting python using system
checking if folders found from paths step still exist
if they do, delete those as well
start over just with one python installation
repoint to that in pycharm
first
pip uninstall PIL
after uninstall
python3 -m pip install --upgrade pip
python3 -m pip install --upgrade Pillow
or
brew install Pillow

Open WebP images in GCE Deep Learning VM

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!

Issue with dependencies running python file on another PC

I have a python file running perfectly in the IDE.
I want to run it on a different PC without any IDE.
I run the program from the command line: python program.py
Error message: File "program.py", line 8, in
from mpl_finance import candlestick_ohlc
ModuleNotFoundError: No module named 'mpl_finance'
When trying: pip install mpl_finance (or pip install mpl_toolkits)
I get the message: No matching distribution found for mpl_finance (or mpl_toolkits)
There also seems to be a problem with matplotlib backend.
Looking for a solution please.
After many failed paths, here's what worked:
matplotlib.finance is deprecated and it is now mpl_finance.
Create 2 files named mpl_finance.py and setup.py and get their contents from here.
Then from the command-line: python setup.py install
Fixing the backend (this can save you a few days):
If the backend of matplotlib was set in a file original PC (and not in the code). Then you need to do the same on the second PC.
Windows Path: C:\Program Files\Python36\Lib\site-packages\matplotlib\mpl-data\matplotlibrc
Change (probably line 38) to this: backend : Qt5Agg

Open Babel can't convert from mol2 to png because Cairo library is not loaded

I first installed Open Babel through brew. When I tried to run the command: "obabel -:"CC(=O)Cl" -opng -O mymol.png", I got this error message: " Open Babel Error in PNG Format
PNG2Format not found. Probably the Cairo library is not loaded." I then proceeded to use brew to uninstall Open Babel. Then, I installed Cairo with brew and then installed Open Babel with brew again. Still though, I try to create a PNG output and it gives me the same error message. I just do not know what's going on??
I’ve found that when using brew to install open-babel, I do not need to install Cairo in a separate step. The open-babel formula includes a '--with-cairo’ option that installs all the required dependencies, including Cairo.
Here is how I installed open-babel with Cairo support:
$ brew install --with-cairo open-babel

libxml-ruby on windows xp problem

About a month ago I installed libxml-ruby using
gem install libxml-ruby
and it worked fine.
Then i went to install it on another machine today and it failed with this error:
C:\Windows\system32>gem install -r libxml-ruby
Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake RUBYARCHDIR=c:/ruby/lib/ruby/
gems/1.8/gems/libxml-ruby-1.1.3-x86-mswin32-60/lib RUBYLIBDIR=c:/ruby/lib/ruby/g
ems/1.8/gems/libxml-ruby-1.1.3-x86-mswin32-60/lib
'c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake' is not recognized as an int
ernal or external command,
operable program or batch file.
Gem files will remain installed in c:/ruby/lib/ruby/gems/1.8/gems/libxml-ruby-1.
1.3-x86-mswin32-60 for inspection.
Results logged to c:/ruby/lib/ruby/gems/1.8/gems/libxml-ruby-1.1.3-x86-mswin32-6
0/ext/mingw/gem_make.out
I have rake installed and win32-api
I then got confused if I had really installed libxml-ruby on my machine previously and tried uninstalling and reinstalling it. It now fails with the same error message on my machine and some scripts i've written to parse xml, which used to work, no longer work. Has anyone else tried installing libxml-ruby lately on windows xp? It appears to be completely broken.
I got the same problem, and ended up figuring out a decent work-around.
It seems the error is correct
'c:/ruby/lib/ruby/gems/1.8/gems/rake-0.8.4/bin/rake'
isn't a valid executable. It needs to run rake from the root ruby/bin folder, where the wrapping batch file can be found.
Rummaging through the rubygems code, I found that Gem::Ext::RakeBuilder tries to build extensions using
cmd = ENV['rake'] || Gem.bin_path('rake') rescue Gem.default_exec_format % 'rake'
So, simply setting the rake environment variable to something valid before running the gem install should help:
C:\>set rake=c:\ruby-1.8.6-26\bin\rake.bat
C:\>gem install libxml-ruby --no-rdoc --no-ri
Building native extensions. This could take a while...
Successfully installed libxml-ruby-1.1.3-x86-mswin32-60
1 gem installed
(I skipped installing rdoc and ri because it prints out a bunch of formatting warnings, making it more difficult to paste the results in here.)