Open WebP images in GCE Deep Learning VM - python-imaging-library

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!

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

How to install YoloV3 in python using some codes in anaconda?

Anaconda Prompt
I used to follow this article: https://medium.com/deepquestai/train-object-detection-ai-with-6-lines-of-code-6d087063f6ff, but I can't proceed because I can't install YoloV3. The line which I followed here is pip install https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5 but it appears error on anaconda.
The output is Cannot unpack file c:\users\appdata\local\temp\pip-unpack-vo7bb6\pretrained-yolov3.h5 (downloaded from c:\users\appdata\local\temp\pip-req-build-pfzpqr, content-type: application/octet-stream); cannot detect archive format
Cannot determine archive format of c:\users\appdata\local\temp\pip-req-build-pfzpqr
Follow the instructions in the article exactly. The YOLO model is not a PIP package but a file to download and put in the same folder as your other code. It's not using pip but wget
!wget https://github.com/OlafenwaMoses/ImageAI/releases/download/essential-v4/pretrained-yolov3.h5

orange add-ons error Orange3-Text 0.1.9

my orange version 3.3
i installed all add-ons but when i want to install Orange3-Text 0.1.9
(i have xcode and python-3.4.4-macosx10.6)
An error occurred while running a subprocess
Command failed: python -m pip install
Orange3-Text exited with non zero status.
Show Details
Collecting Orange3-Text
Using cached Orange3-Text-0.1.10.tar.gz
Collecting gensim>=0.12.3 (from Orange3-Text)
Using cached gensim-0.12.4-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting nltk (from Orange3-Text)
Using cached nltk-3.2.1.tar.gz
Requirement already satisfied (use --upgrade to upgrade): numpy in /Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from Orange3-Text)
Requirement already satisfied (use --upgrade to upgrade): scikit-learn in /Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from Orange3-Text)
Requirement already satisfied (use --upgrade to upgrade): scipy in /Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from Orange3-Text)
Collecting setuptools-git (from Orange3-Text)
Using cached setuptools-git-1.1.tar.gz
Collecting smart-open>=1.2.1 (from gensim>=0.12.3->Orange3-Text)
Using cached smart_open-1.3.2.tar.gz
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.0 in /Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages (from gensim>=0.12.3->Orange3-Text)
Collecting boto>=2.32 (from smart-open>=1.2.1->gensim>=0.12.3->Orange3-Text)
Using cached boto-2.39.0-py2.py3-none-any.whl
Collecting httpretty==0.8.10 (from smart-open>=1.2.1->gensim>=0.12.3->Orange3-Text)
Using cached httpretty-0.8.10.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/var/folders/75/kxgr97zd7kggxsp8r0v12tph0000gn/T/pip-build-a9iyny1h/httpretty/setup.py", line 86, in <module>
version=read_version(),
File "/private/var/folders/75/kxgr97zd7kggxsp8r0v12tph0000gn/T/pip-build-a9iyny1h/httpretty/setup.py", line 46, in read_version
finder.visit(ast.parse(local_file('httpretty', '__init__.py')))
File "/private/var/folders/75/kxgr97zd7kggxsp8r0v12tph0000gn/T/pip-build-a9iyny1h/httpretty/setup.py", line 78, in <lambda>
open(os.path.join(os.path.dirname(__file__), *f)).read()
File "/Applications/Orange3.app/Contents/Frameworks/Python.framework/Versions/3.4/lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 133: ordinal not in range(128)
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/75/kxgr97zd7kggxsp8r0v12tph0000gn/T/pip-build-a9iyny1h/httpretty
You are using pip version 7.1.2, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
We are well aware of this problem and are currently trying to resolve it with authors of smart_open (which we require through gensim - one of our dependencies). The problem occurs since gensim cannot be installed with environment variable LC_ALL=C which is how we install add-ons. Currently, I would suggest to install it through the terminal. On a Mac this can be done by going to Orange's installation folder and running the pip install:
cd /Applications/Orange3.app/Contents/MacOS
./pip install Orange3-Text
Beware that Orange3-Text is still in development and some major changes are coming through the summer. So if you encounter any issues, please report them on our issue tracker.

pip install PIL doesn't install into virtualenv

How do I install PIL?
>pip install PIL
Downloading/unpacking PIL
Could not find any downloads that satisfy the requirement PIL
Some externally hosted files were ignored (use --allow-external PIL to allow).
Cleaning up...
No distributions at all found for PIL
Storing debug log for failure in /root/.pip/pip.log
>pip uninstall PIL
Can't uninstall 'PIL'. No files were found to uninstall.
pip install PIL --allow-external PIL --allow-unverified PIL
This is due to changes in the new version of Pip. Run pip --version and I'm willing to bet you are running 1.5. See the changelog here. This new default behavior enhances security. In PIL's case, the file you are installing actually comes from effbot.org (thus --allow-external) and PyPi doesn't have a checksum to guarantee validity (thus --allow-unverified).
Also, you might consider using the Pillow replacement to PIL.
Updated info for those reading in 2016:
--allow-external
and
--allow-unverified
were recently deprecated. Installing packages external to PyPi using pip is no longer supported: http://www.python.org/dev/peps/pep-0470/
As an alternative, when you really need to install that external package, you can download the source code and run its setup.py. For example, for PIL 1.1.7, download from http://www.pythonware.com/products/pil/, then:
$ tar xvfz Imaging-1.1.7.tar.gz
$ cd Imaging-1.1.7
$ python setup.py install
(^ from the PIL README)
If you only want to install the package to a specific virtualenv, you can just activate your virtualenv first. ** thanks #Caumons
Alternatively, substitute the path to your virtualenv for 'python' in the third line, e.g.:
$ /home/username/virtualenv-name/bin/python setup.py install

PIL installation under CentOS selftest fine but jpeg not working

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.