How can Pillow and MATLAB Runtime be used together on macOS? - python

In order to use the MATLAB runtime on macOS, the DYLD_LIBRARY_PATH must be updated to point to the MATLAB Runtime.
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/Applications/MATLAB_R2017b.app/runtime/maci64:/Applications/MATLAB_R2017b.app/sys/os/maci64:/Applications/MATLAB_R2017b.app/bin/maci64
Then, to use Pillow, it must be installed:
$ pip3 install Pillow
When running the following code:
from PIL import Image, ImageTk
print('Hello World')
The following error is shown:
Traceback (most recent call last):
File "main.py", line 1, in <module>
from PIL import Image, ImageTk
File "/Users/user/venv/py-test/lib/python3.6/site-packages/PIL/Image.py", line 58, in <module>
from . import _imaging as core
ImportError: dlopen(/Users/user/venv/py-test/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-darwin.so, 2): Library not loaded: #loader_path/.dylibs/libtiff.5.dylib
Referenced from: /Users/user/venv/py-test/lib/python3.6/site-packages/PIL/_imaging.cpython-36m-darwin.so
Reason: Incompatible library version: _imaging.cpython-36m-darwin.so requires version 9.0.0 or later, but libtiff.5.dylib provides version 6.0.0
If run without the first export command, Pillow works fine, but I can't find out a way to get both to work at once. The MATLAB Runtime is exporting an older version of libtiff that Pillow (even though it's install via a binary wheel) is loading:
/Applications/MATLAB_R2017b.app/bin/maci64/libtiff.5.dylib
System configuration
macOS 10.11.6
Python 3.6.4 installed via Homebrew
Pillow 5.0.0
MATLAB Runtime 2017b

Related

Pillow working in python 3.10.x but not in 3.11

I am using the pillow library for images in python. With python 3.10.x I dont get an error when I import Image from PIL
from PIL import Image
However if I run the same code in python 3.11.x, I get an error
Traceback (most recent call last):
File "C:\Users\einfa\Downloads\Displaying-Images-With-Turtle_ORIGINAL\main\main.py", line 8, in <module>
from libs.PIL import Image
File "C:\Users\einfa\Downloads\Displaying-Images-With-Turtle_ORIGINAL\main\libs\PIL\Image.py", line 100, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'libs.PIL' (C:\Users\einfa\Downloads\Displaying-Images-With-Turtle_ORIGINAL\main\libs\PIL\__init__.py)
Does somebody know a solution so I can run my program with PIL in both versions?
I tried installing different pillow versiosn at first which did't work. After that I installed python 3.11.x and python 3.10.x and noticed this difference. I installed pillow via pip with the command pip3 install pillow

How can I import in Python simple coding error

I have started any coding for example: from PIL import Image, I encountered such an error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
I will be pleased that guide me.
In shell, run:
pip install Pillow
PIL is deprecated - Pillow is its replacement
This means that the package is not installed. To install it, you will need pip, a package installer for python.
Here is the Pillow package official website, which you can use to understand how to install the package: https://pillow.readthedocs.io/en/stable/installation.html. All the commands on the site are typed into Terminal on MacOS and Linux and the cmd on Windows.

Installing RasterIO with pyenv

RasterIO appears to be a very promising library for geospatial IO and much easier for me to navigate than gdal's python bindings. I am having trouble installing it correctly.
Currently, I have am using pyenv and pyenv-virtualenv to manage python distributions and environments, respectively. I installed gdal with brew using the following steps.
I navigated to my project folder, activated the virtual environment and downloaded rasterio from PyPI: pip install rasterio. However, the only way to correctly import the package is to import osgeo first?!? I am concerned that this means I have some broken dependencies or I have installed rasterio incorrectly.
Specifically,
import osgeo
import rasterio
works fine (tested using with about half of their quickstart), but
import rasterio
does not. The latter producing:
Traceback (most recent call last):File "<string>", line 1, in <module>
File "/Users/home/.pyenv/versions/virtual_env_name/lib/python3.6/site-packages/rasterio/__init__.py", line 15, in <module>
from rasterio._base import (
ImportError: dlopen(/Users/home/.pyenv/versions/virtual_env_name/lib/python3.6/site-
packages/rasterio/_base.cpython-36m-darwin.so, 2): Symbol not found: _CPLMalloc
Referenced from: /Users/home/.pyenv/versions/virtual_env_name/lib/python3.6/site-packages/rasterio/_base.cpython-36m-darwin.so
Expected in: flat namespace in /Users/home/.pyenv/versions/virtual_env_name/lib/python3.6/site-packages/rasterio/_base.cpython-36m-darwin.so
Any suggestions on how to debug/interpret this error would be invaluable to me. Thanks!
If possible, I would prefer not build from source per these instructions.

Importing PIL, more specifically Image from PIL, isn't working

Here is a description of what I've done.
I'm trying to write a program using PIL, but, when trying to import it (as shown bellow), an error appears (also shown below).
from PIL import Image
Here is the error.
Traceback (most recent call last):
File "C:/Users/user/Desktop/Wook/Test Bench.py", line 1, in <module>
from PIL import Image
File "C:\Python\lib\site-packages\PIL\Image.py", line 56, in <module>
from . import _imaging as core
ImportError: DLL load failed: The specified procedure could not be found.
I have tried to simply import Image:
But, it also displays an error:
Here is the error to the second situation.
Traceback (most recent call last):
File "C:/Users/user/Desktop/Wook/Test Bench.py", line 1, in <module>
import Image
ModuleNotFoundError: No module named 'Image'
Here is a very short list of what I've tried to do to solve the issue:
Installing PIL (Could not find a version that satisfies the requirement PIL (from versions: ) No matching distribution found for PIL), suffice it to say, it didn't work;
Uninstalling PIL, but I cannot uninstall what I don't have installed (Cannot uninstall requirement PIL, not installed);
I've tried to install pillow, but it is already installed;
I've tried to uninstall pillow (to then install it again, and see if it would work), it did not resolve a thing.
That's all I've tried. If anyone can help me, it would be deeply appreciated, and if, any further information needs to be provided, it can, and will, be provided.
There's a Python problem which means wheels built against Python 3.6.1, such as Pillow 4.1.0, won't work on Python 3.6.0.
The fix is to update to Python 3.6.1, or install Pillow 4.0.0 (which was built against Python 3.6.0).
For more info see:
https://github.com/python-pillow/Pillow/issues/2479
https://mail.python.org/pipermail/python-dev/2017-March/147707.html
https://bugs.python.org/issue29943
Update:
This has affected a number of Python libraries.
However, there's the new Pillow 4.1.1 release works around this, so you can now update to Pillow 4.1.1 and use it with both Python 3.6.0 and 3.6.1.

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.

Categories

Resources