I have installed OpenCV and the detail is as follows:
brew info opencv homebrew/science/opencv: stable 2.4.12 (bottled),
HEAD Open source computer vision library http://opencv.org/
/usr/local/Cellar/opencv/2.4.12 (225 files, 36M)
Then, I run the Python to import the library of cv and get the ImportError
ImportError: dlopen(./cv2.so, 2): Library not loaded:
/usr/local/lib/libpng16.16.dylib Referenced from:
/usr/local/Cellar/opencv/2.4.12/lib/libopencv_highgui.2.4.dylib
Reason: Incompatible library version: libopencv_highgui.2.4.dylib
requires version 35.0.0 or later, but libpng16.16.dylib provides
version 34.0.0
I have found some related questions and follow the suggestion to reinstall the libpng to obtain the latest version. Unfortunately, it still does not work..
Here is the details of libnpg:
brew info libpng libpng: stable 1.6.19 (bottled), HEAD Library for
manipulating PNG images http://www.libpng.org/pub/png/libpng.html
/usr/local/Cellar/libpng/1.6.19 (17 files, 1.2M)
I finally tackle the problem!
The "libpng16.16.dylib" in the directory: /usr/local/lib/libpng16.16.dylib is loaded when importing the cv, cv2 modules.
Even I update the version of libpng to be the latest version, new version of "libpng16.16.dylib" is still stored at: /usr/local/Cellar/libpng/1.6.19 but not /usr/local/lib/libpng16.16.dylib.
Therefore, I copy the latest version of "libpng16.16.dylib" to the directory: /usr/local/lib/libpng16.16.dylib, and it is solved!
I am not sure that it is the most appropriate solution, but at least it works.
Related
I need to be able to render text in python in various fonts and using various writing systems that use variable substitution of characters (Arabic, Hindi, Bengali). On a previous machine I had no issue doing this, but I just moved into a new machine with the same conda environment and it doesn't seme to work.
Mac OS 12.6
Python version 3.9.13
Libraqm version 0.9.0 (installed with brew)
Pillow version 9.2.0 (installed with pip)
Here's a minimal reproducible example. It should produce the Urdu word لڑكا – with the two groups of two letters attached – but instead it's producing something that looks like ا ک ڑ ل, with each letter disconnected. It's rendering the specific font correctly, so it's not a matter of the font not being found. When I run the last few lines of code checking for the 'raqm' feature, I get False.
from PIL import ImageFont
from PIL import ImageDraw
from PIL import Image
font = ImageFont.truetype('KawkabMono-Bold.ttf',12,layout_engine=ImageFont.Layout.RAQM)
img = Image.new('1', (200, 100), 'white')
d = ImageDraw.Draw(img)
d.text((100,50), 'لڑكا', fill='black', font=font)
img.save('test.png')
from PIL import features
features.check_feature(feature='raqm')
I've tried installing and reinstalling a few times, and building from different sources. My guess is that libraqm is not on the correct path for Pillow, but I'm not sure how to check or fix this.
I tried running the minimal reproducible text and expected to see a properly render, RTL text with the correct rendering of text. Instead, I got an image file of the text rendered left-to-right and disconnected.
I had the same issue and was able to resolve it by uninstalling Pillow
pip uninstall Pillow
Then reinstalling as follows
pip install --upgrade Pillow --global-option="build_ext" --global-option="--enable-raqm"
There is some more information on the build options here.
This assumes you have already installed libraqm with homebrew
brew install libraqm
I am unsure if this is necessary but you may also need these dependencies as mentioned by Mark Setchell
brew install freetype harfbuzz fribidi
On Mac Os 12.6.1 and Python 3.10.8 System Interpreter I was able to get libraqm to work with Pillow. Configuration follows:
Python Interpreter version 10.8 installed with Homebrew.
Libraqm version 0.9.0 installed with Homebrew.
Pillow version 9.3.0 installed with pip.
First, I tried using a python venv, and I got UserWarning: Raqm layout was requested, but Raqm is not available. Falling back to basic layout.
Next, I added the following to the code you posted: print(features.check("raqm")) and it printed False as expected.
I used my Python System Interpreter (3.10.8), installed Pillow and I was able to get libraqm to load with Pillow.
Image without libraqm. Image with libraqm
I added a fonts directory with the font specified on your snippet above. I loaded the font with the following code:
features.check_feature(feature='raqm')
print(features.check("raqm"))
custom_font = os.path.abspath(
os.path.join(
os.path.dirname(__file__), 'fonts/KawkabMono-Bold.ttf'
)
)
If the librqam library is not loaded by the python interpreter, then your ouput will be like you described it ( individual characters).
I think you additionally need fribidi and harfbuzz installed before PIL/Pillow:
brew install fribidi harfbuzz
Note that you can get PIL/Pillow's configuration, build settings, features and supported formats with:
python3 -m PIL
I am following this official guide for building a package for anaconda based on a skeleton. I just want to build the example package used in the tutorial, which is pyinstrument.
I am using anaconda2 version 4.5.11 under MacOS High Siera (10.13.6).
When running the command conda_build pyinstrument, I am getting the following error (full output here):
File
"/Users/me/anaconda2/envs/blbuild/lib/python2.7/site-packages/cffi/vengine_cpy.py",
line 159, in load_library
raise VerificationError(error) cffi.error.VerificationError: importing
'/Users/me/anaconda2/envs/blbuild/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_4ed9e37dx4000d087.so':
dlopen(/Users/me/anaconda2/envs/blbuild/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_4ed9e37dx4000d087.so,
2): Library not loaded: #loader_path/../../../libcrypto.1.0.0.dylib
Referenced from:
/Users/me/anaconda2/envs/blbuild/lib/python2.7/site-packages/cryptography/_Cryptography_cffi_4ed9e37dx4000d087.so Reason: image not found
I have already tried reinstalling openssl via brew, because I found this recommendation when searching SO for the error message, it had no effect on the error though. My openssl version from brew is 1.0.2p in case that matters.
What am I doing wrong?
I was able to finally resolve this issue. The solution was to manually install a package that seems to be required:
conda install cryptography
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.)
I installed the python igraph library for anaconda following the directions in this thread installing python igraph, So the C core library and the python package were successfully installed. However, when I tried to import the igraph library in python, I am getting the following error
>>> import igraph
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/user/anaconda/lib/python2.7/site-packages/igraph/__init__.py", line 34, in <module>
from igraph._igraph import *
ImportError: dlopen(/Users/user/anaconda/lib/python2.7/site-packages/igraph/_igraph.so, 2): Library not loaded: libxml2.2.dylib
Referenced from: /Users/user/anaconda/lib/python2.7/site-packages/igraph/_igraph.so
Reason: Incompatible library version: _igraph.so requires version 12.0.0 or later, but libxml2.2.dylib provides version 10.0.0
Looking for similar threads, I found a similar issue here Installation of python igraph with lxml problem. However, there is not a clear way on how to solve this issue. Does anyone know how to fix it? Thanks in advance.
Anaconda Python is weird - it ships with its own version of libxml2 and when you run pip install python-igraph, igraph is probably linked against it. However, when you try to import igraph, the linker finds the system-wide libxml2, which has a lower ABI version, so that's why you see the error message.
The workaround for this is to ensure that during the compilation stage, Anaconda Python's libxml2 is not picked up by the compiler. setup.py in the Python interface of igraph actually contains this workaround - it tries to detect when you are compiling igraph against Anaconda Python on OS X and then it tweaks the environment a bit to ensure that the linker picks up the right version of libxml2. However, this workaround is enabled only if you do not have the C core of igraph installed on your machine - the installer will download the C core, tweak the environment to work around Anaconda Python, then compile the C core and the Python interface together in one single step.
So, the solution is probably one of the following:
Move Anaconda Python's libxml2 out of the way (or maybe rename xml2-config from Anaconda Python's distribution temporarily), then compile and install the C core from Homebrew. (Use brew unlink igraph, brew uninstall igraph, brew install igraph to be on the safe side). Then you can run pip install python-igraph.
Remove Homebrew's igraph entirely and just run pip install python-igraph - it will download the C core, perform the necessary tweaks and then compile everything.
I had exactly the same issue and installing/force linking libxml2 worked for me:
brew install libxml2
brew link --force libxml2
Others also report the same solution and it appears to be working.
I'm trying to use pyinstaller, on OSX Mavericks, with one a Python script. Pyinstaller compiles and packs along until it finds an error with the Pillow library.
ImportError: dlopen(/Users/Rodolphe/.python-eggs/Pillow-2.2.1-py2.7-macosx-10.9-intel.egg tmp/PIL/_imaging.so, 2): Library not loaded: /usr/local/lib/libjpeg.8.dylib
Referenced from: /Users/Rodolphe/.python-eggs/Pillow-2.2.1-py2.7-macosx-10.9-intel.egg-tmp/PIL/_imaging.so
Reason: Incompatible library version: _imaging.so requires version 13.0.0 or later, but libjpeg.8.dylib provides version 9.0.0
It looks like Pyinstaller and Pillow are not getting along (it seems to be a known fact: http://www.pyinstaller.org/ticket/745 ). Is there a way around it? Should I try uninstalling Pillow and installing Pil instead (I chose Pillow out of discouragement from Pil's reluctancy to install on Mavericks, to begin with)? Or maybe update libjpeg.8.dylib to version 13.0.0 as it seems to be the problem?
[EDIT]
I have updated libjepeg thanks to the advice from #mimi.vx I now have another error at the very end of the process:
IOError: [Errno 20] Not a directory: '/Library/Python/2.7/site-packages/Pillow-2.2.1-py2.7-macosx-10.9-intel.egg/PIL/_imaging.so'
I tried reinstalling Pillow so Pyinstaller would maybe get the directory, but no luck yet...
[RE-EDIT]
Using py2app instead of pyinstaller worked for me!
Yes, first try update libjpeg
Good help for OS X can be found in this blog http://brantsteen.com/blog/python-27-libjpeg-pil-on-osx/
libjpg latest source is here www.ijg.org
And Pillow recommended install on OS X is described in pypi.python.org/pypi/Pillow/2.2.1
It is over homebrew $ brew install libtiff libjpeg webp littlecms
Pyinstaller was behaving strangely while importing PIL. I tried using py2app ( http://pythonhosted.org/py2app/ ) instead, and it worked like a charm. No lib ray import trouble or anything. I'd recommend it.