Pillow not detecting the libraqm DLL file - python

I am having issues with Pillow's text rendering features. I wanted to enable kerning for the font so that it looked nicer, but have descended into an endless rabbit hole of insanity.
When trying to run this code line:
draw.text((1255, 224), desc, font=font.font_variant(size=94), fill=0xff0000ff, features=['kern'])
I receive the following error message:
size, offset = self.font.getsize(
KeyError: 'setting text direction, language or font features is not supported without libraqm'
I've searched online for a long while and have found a few answers that have not yielded any results...
Most notably How to install pre-built Pillow wheel with libraqm DLLs on Windows? and Installing Raqm (Libraqm) Windows 10.
I was so stressed that I eventually copied and pasted the DLL files in every folder I could think of (such as System32, SysWOW64, Python38, Python38\Scripts, Python38\DLLs, etc.), but still failed.
I was even changing PATH, PYTHONPATH, and sys.path.
>>> from PIL import features
>>> features.check('raqm')
False
The check above always printed False
I inspected the code that checks if a feature is present and checked myself, it cannot find any DLL:
>>> imported_module = __import__('PIL._imagingft', fromlist=['PIL'])
>>> vars(imported_module)
{ ..., 'HAVE_RAQM': False, 'HAVE_FRIBIDI': False, 'HAVE_HARFBUZZ': False, ... }
For reference, these are my versions:
Windows 10 Pro 20H2
Pillow 8.2.0
Python 3.8.7
I have become very desperate for any answer... Looked online for a while and was not able to find much information, always only one or two Google results had some relevance to this issue.

I have the same problem
I tried placing libraqm.dll everywhere possible
After googling for days with no hope,
At the end I installed virtualbox and continued my project on Manjaro linux.
I have windows 10 Home
Version 10.0.19042 Build 19042
Pillow 8.2.0
Python 3.9.5

Related

Programmatically check if wheel is compatible with Python installation

Is it possible to programmatically check if a wheel (whl) is compatible with the chosen Python installation before attempting to install?
I'm making an automated packages installer (packages needed for my Python project to work), and I need to only attempt to install compatible pkgs, so if there are errors, I know they are only from the compatible modules and I should see what happened (not errors also from incompatible pkgs, which I wouldn't care). Example: I'd have wheels for Python 3.5 and 3.7, and in a 3.5 installation, 3.7 wheels could not be tried to be installed.
I've tried pkginfo (https://pypi.org/project/pkginfo/), but on wheel.supported_platforms, it returns an empty array and I can't do anything with that (a wheel with "any" or with "win32" on their name in the platform part, returned an empty array, so I can't use that, it seems).
Also tried the output from python -m pip debug --verbose, but the following appears:
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without no
tice.
This makes the command not possible to use, even though bellow that it prints the "Compatible tags", which more or less I could use to determine if a wheel is supported or not from its name. Example of those "Compatible tags" in a Python array:
['cp39-cp39-win_amd64', 'cp39-abi3-win_amd64', 'cp39-none-win_amd64', 'cp38-abi3-win_amd64', 'cp37-abi3-win_amd64', 'cp36-abi3-win_amd64', 'cp35-abi3-win_amd64', 'cp34-abi3-win_amd64', 'cp
33-abi3-win_amd64', 'cp32-abi3-win_amd64', 'py39-none-win_amd64', 'py3-none-win_amd64', 'py38-none-win_amd64', 'py37-none-win_amd64', 'py36-none-win_amd64', 'py35-none-win_amd64', 'py34-no
ne-win_amd64', 'py33-none-win_amd64', 'py32-none-win_amd64', 'py31-none-win_amd64', 'py30-none-win_amd64', 'cp39-none-any', 'py39-none-any', 'py3-none-any', 'py38-none-any', 'py37-none-any
', 'py36-none-any', 'py35-none-any', 'py34-none-any', 'py33-none-any', 'py32-none-any', 'py31-none-any', 'py30-none-any']
With, for example, "pyHook-1.5.1-cp36-cp36m-win32.whl", I could check the name and see if it's compatible or not (except because of the warning above...).
Any other ideas?
Thanks in advance for any help!
EDIT: I could go manually and pull things from the name and hard-code the some possibilities I see on documentation, like "win32" and "win_amd64" (as I did before), but then I'd need to know exactly all the possibilities that the parts of the name can have (I saw a cool expression on the documentation: "e.g." - which means there are more than the mentioned things) and have a lot of work on that. I was hoping there was already someone that had made such thing (maybe even Python itself has some way in any of its internal packages).
You can do this using packaging.
pip install packaging
An example code to get the tags similar to how you got from pip would be:
from packaging.tags import sys_tags
tags = sys_tags()
print([str(tag) for tag in tags])
# ['cp39-cp39-manylinux_2_33_x86_64', 'cp39-cp39-manylinux_2_32_x86_64', 'cp39-cp39-manylinux_2_31_x86_64', ..... , 'py31-none-any', 'py30-none-any']
Of course, you can do much more things programmatically with the above variable tags:
>>> tags = sys_tags()
>>> for tag in list(tags)[:3]:
... print(tag.interpreter, tag.abi, tag.platform)
...
cp39 cp39 manylinux_2_33_x86_64
cp39 cp39 manylinux_2_32_x86_64
cp39 cp39 manylinux_2_31_x86_64
For more in-depth documentation, check: https://packaging.pypa.io/en/latest/tags.html#packaging.tags.sys_tags

MLWIC: Machine Learning for Wildlife Image Classification in R Issues with Python

I am a wildlife PhD researcher manually identifying ~1.5 million game camera photos by species. A machine learning package in R has recently come out of a research project and I've been trying to get the script to run in R for about 12 hours and can't seem to get it right (I have used R and python a lot, but I am no expert and this is the first question I have asked on here so forgive me if I haven't done this correctly).
The ReadMe (To understand what I am trying to do you will probably have to read this, I apologize) for the package downloaded on Github is located at: https://github.com/mikeyEcology/MLWIC/blob/master/README.md
Unfortunately for me, the package was developed on a Macintosh platform and I have Windows.
I followed the steps in the ReadMe as follows:
1: Installed the MLWIC package using the code:
devtools::install_github("mikeyEcology/MLWIC")
library(MLWIC)
2: Followed the instructions to install "pip", python, and "TensorFlow" at
https://www.tensorflow.org/install/pip
3: Downloaded the L1 folder
4: I ran a different code than outlined in the ReadMe, it is as follows:
setup(python_loc = "I used this location I got from running "where python" in Anaconda")
After this initial setup, I ran the code for the "classify function":
library(MLWIC)
setup(python_loc = "C:/ProgramData/Anaconda3", conda_loc = "auto", r_reticulate = FALSE)
setwd("C:/Users/werdel/Desktop/MachineLearning")
help("classify")
classify(path_prefix = "C:/Users/werdel/Desktop/MachineLearning/images",# this is the absolute path to the images.
data_info = "C:/Users/werdel/Desktop/MachineLearning/image_labels.csv", # this is the location of the csv containing image information. It has Unix linebreaks and no headers.
model_dir = "C:/Users/werdel/Desktop/MachineLearning", # assuming this is where you stored the L1 folder in Step 3 of the instructions: github.com/mikeyEcology/MLWIC/blob/master/README
python_loc = "C:/ProgramData/Anaconda3/python.exe", # the location of Python on your computer.
save_predictions = "model_predictions.txt" # this is the default and you should use it unless you have reason otherwise.)
This is where the problem seemed to arise. It seems to run fine, with the output showing a file created in my working directory, but when I check, there is no file. I have tried changing python location, downloading new and old versions of anaconda, messing with environments, but nothing has changed the fact that there is no file created in my working directory:
> library(MLWIC)
> setup(python_loc = "C:/ProgramData/Anaconda3", conda_loc = "auto", r_reticulate = FALSE)
Remove all packages in environment C:\PROGRA~3\ANACON~1\envs\r-reticulate:
## Package Plan ##
environment location: C:\PROGRA~3\ANACON~1\envs\r-reticulate
The following packages will be REMOVED:
ca-certificates: 2018.03.07-0
certifi: 2018.10.15-py37_0
openssl: 1.1.1a-he774522_0
pip: 18.1-py37_0
python: 3.7.1-he44a216_5
setuptools: 40.6.2-py37_0
vc: 14.1-h0510ff6_4
vs2015_runtime: 14.15.26706-h3a45250_0
wheel: 0.32.3-py37_0
wincertstore: 0.2-py37_0
Solving environment: ...working... done
## Package Plan ##
environment location: C:\PROGRA~3\ANACON~1\envs\r-reticulate
added / updated specs:
- python
The following NEW packages will be INSTALLED:
ca-certificates: 2018.03.07-0
certifi: 2018.10.15-py37_0
openssl: 1.1.1a-he774522_0
pip: 18.1-py37_0
python: 3.7.1-he44a216_5
setuptools: 40.6.2-py37_0
vc: 14.1-h0510ff6_4
vs2015_runtime: 14.15.26706-h3a45250_0
wheel: 0.32.3-py37_0
wincertstore: 0.2-py37_0
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
#
# To activate this environment, use:
# > activate r-reticulate
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#
Solving environment: ...working... failed
UnsatisfiableError: The following specifications were found to be in conflict:
- argparse
- tensorflow
Use "conda info <package>" to see the dependencies for each package.
Error: Error 1 occurred installing packages into conda environment r-reticulate
> classify(path_prefix = "C:/Users/werdel/Desktop/MachineLearning/images", # this is
the absolute path to the images.
+ data_info = "C:/Users/werdel/Desktop/MachineLearning/image_labels.csv", #
this is the location of the csv containing image information. It has Unix linebreaks
and no headers.
+ model_dir = "C:/Users/werdel/Desktop/MachineLearning", # assuming this is
where you stored the L1 folder in Step 3 of the instructions:
github.com/mikeyEcology/MLWIC/blob/master/README
+ python_loc = "C:/ProgramData/Anaconda3/python.exe", # the location of Python
on your computer.
+ save_predictions = "model_predictions.txt" # this is the default and you
should use it unless you have reason otherwise.
+ )
[1] "evaluation of images took 0.000504970550537109 secs. The results are stored in
C:/Users/werdel/Desktop/MachineLearning/L1/model_predictions.txt. To view the results
in a viewer-friendly format, please use the function make_output"
So my final question is, does it seem like I set something up wrong while downloading pip, tensorflow, anaconda, and python, is it something with the way I am coding, etc.?
If I am not mistaken there is a small bug in their code that ignores the "data_info" path. Try renaming your "image_labels.csv" to "data_info.csv" and put the file inside the model_dir. This solved the problem for me. Also, use "C:/ProgramData/Anaconda3/" instead of "C:/ProgramData/Anaconda3/python.exe"
I was able to get MLWIC to run relatively pain-free on Mac. Getting it running on windows was a little more frustrating. I followed issue threads #6 and #13 on the MLWIC github page. On a machine running Windows 10 I downloaded Anaconda 3 5.2.0 which includes python 3.6.5. After many hours of troubleshooting I got it to work.
Once Anaconda is installed I used Anaconda Navigator to install tensorflow 1.11.0, cuddn 6.0, setuptools 40.6.2. Note this is the only place that I installed tensorflow. I did not bother with the pip install as mentioned on the tensorflow web page.
From there when first opening R I installed the following packages MLWIC, keras, cloudml, Rcpp, and reticulate. Then ran them with the library function. Also as Faisal Ahmed stated above rename image_labels.csv to data_info.csv, and move that file to the L1 folder. From here I was able to get the MLWIC provided code to run on windows. When I first ran the setup function it looked like this setup(python_loc = "C:/Users/kvanatta/Anaconda3/python")
Note: I was originally trying to get MLWIC to run with the files saved on the server in my office (S: drive) and could not get it to work. Upon transferring the files to a 1tb external hard drive (F: drive) everything worked fine from the new location.
I also downloaded the program notepad ++ to be able to convert the data_info.csv file to unix(lf) linebreaks. I believe since windows does not use these linebreaks, opening the .csv file in excel will change the line breaks. You can use notepad ++ to change them back.
Hope this helps ease some frustrations.
Cheers
I really struggled to get MLWIC working on my Windows computer and followed a number of the issues on the MLWIC github page until I came up with a solution that worked for me.
I wrote up a guide for windows users and it's been added to the MLWIC_examples repo. You can find it here. It is a step-by-step guide.
As as aside, I found a way to use Unix-type linebreaks without leaving the R environment:
# Write to UNIX type doc (required)
output.file <- file("L1\\data_info.csv", "wb")
write.table(data_info,
row.names = FALSE,
col.names = FALSE,
file = output.file,
quote = FALSE,
append = TRUE,
sep = ",")
close(output.file)
rm(output.file)

Psychopy unexpected keyword argument 'languageStyle'

I saw that psychopy now has support for RTL language:
http://www.psychopy.org/api/visual/textstim.html
https://discourse.psychopy.org/t/reshaping-english-text-to-arabic/4235/16
I used this manual to install the latest version using conda:
http://psychopy.org/installation.html
My version is: 1.90.2 with Python 3.5
However, when init TextStim with languageStyle I get an error:
from psychopy import visual
text_stim = visual.TextStim(self.window, height = height, wrapWidth = wrapWidth, bold= True, text= sentence, pos = (0,0) , color='white', languageStyle='RTL')
Any idea how can I use it?
Yes, #deceze is correct, this feature in the latest beta, available for download from this page: https://github.com/psychopy/psychopy/releases rather than the latest stable release available from http://psychopy.org/installation.html
EDIT: actually I see that you're installing PsychoPy via pip under Anaconda. I guess the pip version is also lagging behind the current beta release. You might need to clone or download from the PsychoPy GitHUb repository if you want the latest developer release running under your own Python installation.
Note that this feature still doesn't handle multi-line text correctly in Python experiments (the text flows from right to left but also from bottom-to-top). This is due to a limitation in the underlying pyglet library we use for drawing text. However, the latest betas also allow for generating online Javascript experiments that can be run from a browser. These handle Arabic text correctly without any issues whatsoever (and with no need to specify the language style setting at all).

Sublime Text 3 plugin Anaconda can't do multiple-line lint

I am using Sublime Text 3 (build 3047) using package control and the newest Anaconda plugin for python development. However I am facing a rather odd issue.
Using the default linter included in anaconda (not pylint), the plugin only displays the very first error it encounters.
So, if for example I am having errors in line 3, 5 and 10, only line number 3 will be highlighted. PEP8 is also currently disabled.
Is there any way to work around this problem and show all errors in a file at once?
Thank you.
There is no reason that you don't get any more errors linted in the buffer. The only thing that come to my mind is a possible incompatibility with any other ST3 plugin that you have installed as well.
You can do several things to try to figure out what can be wrong:
1) Take a look at the Sublime Text console to see if there are errors raised by Anaconda or other plugin
2) Take a look at your Anaconda JsonServer logs, you can fin them on: $HOME/Library/Caches/Jedi on Mac OS X, $HOME/.cache/jedi on GNU/Linux or %APP_DATA%\Jedi\Jedi on Windows.
You can get some support as well just joining the Anaconda mailing list at https://groups.google.com/forum/#!forum/anaconda-st3-plugin or just opening a new ticket in the project GitHub site: https://github.com/DamnWidget/anaconda/issues

Why do no Python DLLs built with MSVC load with mod_wsgi?

I recently updated from Python 2.5 to 2.7 (I tried 2.6 during my hassles) and while everything works fine from the command line or in the Django runserver, mod_wsgi cannot load any module that contains DLLs (pyd) built with MSVC.
For example, if I build my own versions of pycrypto or lxml then I will get the following error only from mod_wsgi:
ImportError at /
DLL load failed: The specified module could not be found.
Even the official PIL binaries will fail to import the _imaging C module in mod_wsgi but that may be another problem.
However, if I use a version of pycrypto built with MinGW from somewhere like http://www.voidspace.org.uk/python/modules.shtml#pycrypto then it will import fine even in mod_wsgi. I don't find this solution satisfactory though since the whole reason I updated Python was to avoid needing to hunt for prebuilt binaries and I can't build them myself because MinGW fails >50% of the time for me.
EDIT2:
I noticed this in Python27/Lib/distutils/msvc9compiler.py on lines 680-705:
try:
# Remove references to the Visual C runtime, so they will
# fall through to the Visual C dependency of Python.exe.
# This way, when installed for a restricted user (e.g.
# runtimes are not in WinSxS folder, but in Python's own
# folder), the runtimes do not need to be in every folder
# with .pyd's.
manifest_f = open(manifest_file)
try:
manifest_buf = manifest_f.read()
finally:
manifest_f.close()
pattern = re.compile(
r"""<assemblyIdentity.*?name=("|')Microsoft\."""\
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
re.DOTALL)
manifest_buf = re.sub(pattern, "", manifest_buf)
pattern = "<dependentAssembly>\s*</dependentAssembly>"
manifest_buf = re.sub(pattern, "", manifest_buf)
manifest_f = open(manifest_file, 'w')
try:
manifest_f.write(manifest_buf)
finally:
manifest_f.close()
except IOError:
pass
This probably explains why everything works from the command line but not in mod_wsgi. Commenting all this out seems to fix the problem but doesn't feel like the proper fix. The question now is where to put msvcr90.dll so that Apache can use it? I notice that Apache's bin folder contains msvcr70.dll and msvcr80.dll but putting 90 in there doesn't work.
I've had a similar issue and eventually found a solution here: download/update your apache server with one from http://www.apachelounge.com/download/.
While I don't know anything about mod_wsgi, I dare to guess that the most probable reason is missing runtime dependencies. You may want to inspect your MSVC-build with Dependency Walker that ships with MSVC (e.g., in MSVC 2005, it's located at \Common7\Tools\Bin\Depends.Exe). It will show you which DLLs are required by a binary.
As another workaround, it should be possible to build your modules with statically linked runtime (see Project Properties -> C/C++ -> Code Generation -> Runtime -- choose "Multithreaded" (not "Multithreaded DLL"); or, if building from command line, make sure /MT is used instead of /MD). However there may be problems if runtime-dependent things (e.g. FILE* objects) cross module boundary.
UPD If you have correct VC redist installed, the reason may be a problem with SxS configuration (i.e. manifest of .pyd itself is wrong or missing, or conflicts with manifest of the application that loads the .pyd). You can use sxstrace utility to see what exactly is going on. See Diagnosing SideBySide failures.
Also, did you try static linking of the runtime? Or, better yet, check what are requirements of your host process.
I was getting this error with zmq. The solution was to include the python27.dll manifest in the libzmq.pyd file (and it'll most likely work for other pyd/dll's). Make sure you use all 64-bit or all 32-bit.
"C:\Program Files (x86)\Windows Kits\8.0\bin\x64\mt.exe" -inputresource:C:\windows\system32\python27.dll;#2 -outputresource:libzmq.pyd;#2
See https://code.google.com/p/pyodbc/issues/detail?id=214

Categories