PIL: DLL load failed: specified procedure could not be found - python

I've been beginning to work with images in Python and I wanted to start using PIL (Pillow). To install it, I ran pip install Pillow. When installing, PIL was not previously installed. I also tried uninstalling it and reinstalling it, as well as using pip3 install Pillow.
When I run it in Python, my first line is:
File "C:\Program Files\Python36\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 checked the directory, and the file _imaging.cp36-win_amd64.pyd is present under the PIL folder.
Why is this happening if the needed DLL is there? How can I fix it?

I had this problem as well with Python 3.6. I just avoided the problem by uninstalling pillow (4.1.0) and then installing an older version of pillow (4.0.0). It seems to run okay with the older version.

As in Sean's answer, I had to uninstall (I'm using Anaconda Python 3.6, BTW) with
conda uninstall pillow
I tried it with PIL, but there was no such package. Uninstalling pillow also meant uninstalling packages that depend on it, in my case "anaconda-navigator" and "scikit-image". After I reinstalled Pillow 4.0.0 with
conda install pillow=4.0.0
and tested it with
python -c "from PIL import Image"
which, if successful, you don't see an error message, I reinstalled the packages that were uninstalled along with Pillow 4.1.0.
conda install anaconda-navigator
conda install scikit-image

If you're using Anaconda, try
conda uninstall pillow and then pip install pillow
Came across this issue while working on Caffe2 on Windows 10 (Anaconda 4.5) and this worked for me. Here's the github post on this issue.

This problem is also fixed by upgrading Python to 3.6.1, per this GitHub discussion.
The difference is that Pillow 4.1.0 was built with Python 3.6.1 while Pillow 4.0.0 was built with Python 3.6.0.
Apparently PYTHON36.DLL from Python 3.6.0 is missing functions (PySlice_AdjustIndices and PySlice_Unpack) that are used when building with Python 3.6.1.
The solution is to upgrade to Python 3.6.1.

There's a problem in Python itself which means binary wheels build using Python 3.6.1 (like Pillow 4.1.0) won't install on Python 3.6.0.
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.
More info:
https://github.com/python-pillow/Pillow/issues/2479
https://mail.python.org/pipermail/python-dev/2017-March/147707.html
https://bugs.python.org/issue29943

for new people 2022
i solved it
you can look at this
https://pillow.readthedocs.io/en/latest/installation.html
if PIL dont want to uninstall delete or cut it to another folder

This works for me using win10 and py 3.6.
Simply uninstall Pillow 4.1.0
pip3 uninstall Pillow
Then install Pillow 4.0.0
pip3 install Pillow==4.0.0

I had the same problem with anaconda 5.0.1, using it with caffe on windows 10. i just did
conda install PIL
it worked for me.

Seems like some issue is there with tensorflow 1.12.0 +Python 3.6.0 + win10
Working fine with conda tensorflow.
below steps worked for me for pip tensorflow.
uninstall tensorflow
replace your python version with 3.6.1
install latest version of tensorflow(1.13.0)
For installing Tensorflow follow below link:-
https://www.tensorflow.org/install/pip

If you are a Windows user and do not have Microsoft Visual C++ the error occurs. I got the same error and resolved this by installing the Microsoft Visual C++. Link for downloading can be found here.
https://support.microsoft.com/en-us/topic/the-latest-supported-visual-c-downloads-2647da03-1eea-4433-9aff-95f26a218cc0

First uninstall existing version
pip uninstall pillow
Then try installing
pip install pillow==4.0.0

Related

I installed Pillow but i get "ModuleNotFoundError: No module named 'PIL'"

When I try to use from PIL import ImageGrab it gives me this error:
ModuleNotFoundError: No module named 'PIL'
I installed it with pip install pillow and checked if it is installed with pip show pillow. It says I have Version: 8.1.2
I am using python 3.9 and sublime text 3
In the internet I saw most people with that problem have a not maching python version with the pillow version, but mine should work as far as I understood..? (https://pillow.readthedocs.io/en/stable/installation.html)
However its not working and I am trying to fix this since about two hours and I hope somebody can help me.
You might have different versions of python installed and pip is installing pillow for a different version.
A good way to avoid this is using python -m pip install pillow instead of pip install pillow.
Try to install it with pip3 install pillow
The fact is that you installed it for python2 but your are using python3 ;)

How to upgrade OpenCV in Anaconda (windows)?

everyone.
My problem is that I need the last version of OpenCV (4.3.0) to run a code but when I checked my version of opencv with the line:
print(cv2.__version__)
it said that my version of cv2 is the 3.4.2. So I went into my anaconda, environment, I marked opencv for upgrade, but it seems it is the last version it can install. So I tried a command in the cmd.prompt of anaconda :
pip install --upgrade opencv-python==4.3.0.36
And then, when I checked "opencv" in the installed modules of my anaconda environment, I saw two opencv. One is "opencv" version 3.4.2, and then, just below, there is "opencv-pyton" version 4.3.0. BUT, when I checked again my version of cv2 with "print(cv2.version)", it was still telling me that my version is 3.4.2 (I also tried to uninstall the opencv 3.4.2 to see if anaconda would then take into account the opencv-pyton 4.3.0 but no, it gives me an error).
Does anyone have an idea how to upgrade my version of opencv with anaconda ? Thanks everyone.
You may be missing the conda-forge channel in your .condarc settings.
try this to install from conda-forge:
conda install -c conda-forge opencv=4.3.0

How to fix the error "QObject::moveToThread:" in opencv in python?

I am using opencv2 in python with the code
import cv2
cv2.namedWindow("output", cv2.WINDOW_NORMAL)
cv2.imshow("output",im)
cv2.resizeWindow('output', 400,400)
cv2.waitKey(0)
cv2.destroyAllWindows()
I have the error as
QObject::moveToThread: Current thread (0x1d2c9cf0) is not the object's thread (0x1d347b20).
Cannot move to target thread (0x1d2c9cf0)
I debug and found that it happened when I use cv2.waitKey(0). How should I fix it? Thanks
Update: I am using 3.3.0.0. If I use older version, I have error
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvDestroyAllWindows, file /io/opencv/modules/highgui/src/window.cpp, line 577
Traceback (most recent call last):
File "tools/demo_handbone.py", line 220, in <module>
demo(net, im_name)
File "tools/demo_handbone.py", line 159, in demo
cv2.destroyAllWindows()
cv2.error: /io/opencv/modules/highgui/src/window.cpp:577: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvDestroyAllWindows
I got same problem, it was from opencv-python version problem for me.
My Linux machine's environment is as following:
$ cat /etc/lsb-release
...
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
$ date
Tue Aug 11 11:43:16 KST 2020
$ python --version
Python 3.7.8
$ pip list|grep Qt
PyQt5 5.15.0
PyQt5-sip 12.8.0
$ pip list|grep opencv-python
opencv-python 4.3.0.38
I downgraded opencv-python 4.3.0.38 to 4.3.0.36.
$ pip uninstall opencv-python
$ pip install opencv-python==4.3.0.36
$ pip list|grep opencv-python
opencv-python 4.3.0.36
First, uninstall any versions of OpenCV you may have installed. If you installed using pip:
sudo pip uninstall opencv-python
Next, try installing OpenCV using your Linux distro's package manager. For Ubuntu/Debian, this is:
sudo apt-get install libopencv-dev python-opencv
This can happen if you are using an Anaconda virtual environment and did both conda install pyqt(1) and pip install opencv-python. This creates a conflict between the two PyQt versions (opencv-python ships with its own) and causes the errors.
The solution is to install PyQt via pip, i.e. pip install PyQt5.
(1) Or anything that depends on pyqt, e.g. conda install matplotlib.
I was able to fix this problem by installing new pyqt.
if you are using anaconda, just write down below:
$ conda install pyqt
I solved this issue and I posted my solution in related issue on OpenCV github page. But for your convenience, I will post it here also.
In my case, I did almost all the solutions:
installing using pip3 install opencv-python
installing using apt install python-opencv
I followed #areche solution, I end up with kdelibs5-plugins which was an important module for most of my desktop environments, so I give up on uninstalling it.
Finally, I found a solution for my case
pip uninstall opencv-python on all instances of my python and virtual environments
pip3 uninstall opencv-python on all instances of my python and virtual environments
sudo apt remove python-opencv
then I downloaded the most recent opencv, in my case opencv-4.1.1 , I build it.
for building :
mkdir build; cd build; ccmake ..
then I pressed pressed c, again pressed c, then pressed g to generate make files, then
sudo make -j8
after successful building, I copied build\lib\python3\cv2.cpython.xxxxxx.so to usr/local/lib/python3.5/dist-packages/ and renamed it to cv2.so
Do the same for each virtualenv that you have. ( I'm not sure if it is logical, but it worked for me).
then everything worked fine without any error.
Just reinstall opencv-python lib, it's OK.
pip uninstall opencv-python
pip install opencv-python=4.2.0.34
The version 4.2 is the latest opencv python that don't throw this error. I tried 4.3 or 4.4 +, it's don't work.
The main reason of this question may be the confliction between PyQt5 and Opencv.
refer to: https://blog.csdn.net/flyfor2013/article/details/110132458
pip3 uninstall opencv-python
pip3 install opencv-python==4.1.1.26
when I downgrade opencv-python 4.5 -> 4.1.1.26 then Ok
pip3 >= 20.3 use: pip3 install --use-deprecated=legacy-resolver opencv-python==
pip3 >= 9.0 use: pip3 install opencv-python==
and I try
pip3 uninstall opencv-python
pip3 install opencv-python==4.3.0.36
Ok, too
The openCv author says that this problem comes from different Qt versions in openCv and the linux distro. That is: openCv comes with Qt4, but Qt5 is already installed.
This problem is due to the conflict between opencv-python's own Qt5 and the one used by other packages. In my case, matplotlib is installed via conda, then pyqt is also installed as a matplotlib's dependency. My solution is as follows:
Uninstall matplotlib: conda remove matplotlib
Install opencv-python and matplotlib: pip install matplotlib opencv-python
Now, matplotlib installed via pip doesn't require pyqt and the conflict is solved.
Note: The latest version 4.5.4.x gets error with python 3.9, consider using lower version such as 4.5.1.x in this case.
The issue is with OpenCV version, The following version solved all issues for me.
pip uninstall opencv-python
pip install opencv-python==4.1.2.30
I am using - Python 3.8.5 with conda
I tried with upgrading pyqt too but it didn't work
I tried the above mentioned method and could get opencv module working for my project which uses python3.x interpreter.
After performing few experiments, i got it working by doing the below steps:
1) Install opencv-python in your machine using:
sudo pip3 install opencv-python
2) On the python3.x terminal find the version:
>>> import cv2
>>> cv2.__version__
'3.4.1'
3) Get the same version of OpenCV from their official page.
4) Perform the CMake settings as mentioned in opencv tutorial.
Note the location specified in PYTHON3_PACKAGES_PATH
5) Once build has been performed, got to the install location specified in PYTHON3_PACKAGES_PATH. Move the library named cv2.cpython-*-gnu.so to the current python3.x dist-packages path:
usr/local/lib/python3.5/dist-packages/cv2
6) Reload your python3 project and try again!
This problem not present if runing opencv without virtualenviroment.
My system:
Kbuntu 18.04 LTS
GTX 1050
CUDA 9.2
Tensorflow 1.9
I had the same problem when i tried to run a detectron2 demo. My OS is Centos7 and i
uninstall some applications about qt.
find applications about qt.
yum list installed |grep qt
remove applications
yum -y remove xxx...
This error occurs in higher versions of openCv like 4.3.0.38 or higher, i tried 4.3.0.36 version with pip and this problem solved for me, but in lower version i were facing lots of problems, like window not loading correctly,If are using Ubuntu i would recommend you to uninstall opencv from your system completely and try to reinstall with command given below,
pip install opencv-contrib-python3
It is the compatibility issue. Even the way of "conda install install pyqt" does work. Please make sure that you can install the opencv libraries with the specific versions. Higher versions may incur the same issues.
pip install opencv-python==4.1.1.26
pip install opencv-contrib-python==4.1.1.26
Cheers,
I had the same problem and I did not find any solution. By trial and error, I found that my OpenCV version is corrupted. As a result, I deleted it and install a new fresh one. You can use one of these two options:
1. Terminal
run brew uninstall opencv3 to uninstall opencv
then install it using sudo apt-get install libopencv-dev python-opencv command.
2. Anaconda
Actually, I used this method for my own problem.
open anaconda
go to the environment section and select your environment as follow:
then click on installed and search for opencv:
select opencv package and uninstall it. then try to re-install opencv by selecting not installed and searching for opencv. be careful to install the correct version.
In my application I wanted to use PyQt without any of opencv's GUI functionality, so the solution was to remove my current vertion of opencv-python, then instead pip install opencv-python-headless (or opencv-contrib-python-headless if you prefer). That way, opencv would be installed without its conflicting Qt library.
See: https://github.com/opencv/opencv-python#installation-and-usage
Downgrade the python version from 3.9.13 to 3.8.10
conda install python=3.8.10
pip install opencv-python==4.5.2.54
worked for me.
My system environment: Ubuntu 20.04 Anaconda 3.8
I was used matplotlib to display images and face this problem.
pip install opencv-python-headless not work for me.
pip uninstall pyqt5 then pip install pyqt5==5.12 and it works well.
The answer of #Mateen works great if you have Ubuntu version 17 and above. For Ubuntu 16, it's better to compile from sources your opencv python. As #Varun mentioned, follow the opencv tutorial. However, to successfully compile opencv with python 3 I have to add some flags in cmake command:
cmake -DCMAKE_BUILD_TYPE=RELEASE -DPYTHON_DEFAULT_EXECUTABLE=$(which python3) -DPYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python3.5m/ -DPYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.5/dist-packages/numpy/core/include/ ..
Hope that will be helpful.
I fixed this under Ubuntu 18.04 LTS by uninstalling any OpenCV packages from pip and apt and installing OpenCV directly from source. Maybe this tutorial will help:
https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/
I don't know why, but installation of matplotlib solved for me the problem with the error
QObject::moveToThread: Current thread (0x1d2c9cf0) is not the object's thread (0x1d347b20).
Cannot move to target thread (0x1d2c9cf0)
I emphasize that I prepared fresh conda environment where matplotlib was installed. Opencv was installed by pip in conda env as follow pip install opencv-python opencv-contrib-python.
I followed the solution suggested by #Varun and it worked for me (using Python 3).
However, I didn't install the built files, as I do not have the admin rights on the system where I need the cv package. A cmake, followed by make was enough, I then took the cv2.*.gnu file from ../build/lib/python3 folder and replaced the one in the site-packages/cv2 folder of my virtual environment
I had the same problem. Using opencv imshow function raised the moving thread error. Eventually, I found that Ubuntu 16.04 has a preinstalled pyqt5 while OpenCV needs pqty4.
Therefore, this may be caused by conflicting installations of Qt libraries. The following command fixed it for me:
sudo apt-get remove libqt5x11extras5 libqt5x11extras5-dev
I know the thread is a bit old but posting for anyone else out there, I faced the same problem and it was because even after running
pip3 uninstall opencv-python
there was another version of open-cv in my system which I checked by
pip list
(I'm guessing that pip only removes the first version it finds)
So I ran this command again
pip3 uninstall opencv-python
And now simply installing opencv by
pip install opencv-python
worked for me.
In case you are using matplotlib, see this answer: https://stackoverflow.com/a/49887744/13268880
TL;DR: matplotlib.use('Agg')
This may be caused by conflicting installations of Qt libraries. The following command fixed it for me:
sudo apt-get remove libqt5x11extras5 libqt5x11extras5-dev

Python - can not install some packages in latest version

I have installed 3.6.1 version of python interpreter. I have a project that need to use "PIL" library so I try to install it but it gives me error, "Error occurred when installing package 'PIL'". I search it out why it's happening and I think it can only be installed on lower version of interpreter 2.7 or something lower. Now how can I install PIL in 3.6.1 version of interpreter? Should I downgrade my interpreter instead? But if I do, can it cause some other packages to be unable to install for it is only for 3.X version. Thanks in advance.
Install Pillow, the packaged and maintained fork of PIL, using:
pip install pillow
download pillow based on your version. from python unofficial library ..
search pillow choose your python version and distribution from it... once you download,
move onto download path or
pip install ~/Downloads/Pillow‑4.2.1‑cp36‑cp36m‑win_amd64.whl

Unable to install Statsmodels...python

I am using 32 bit cmd, 64 bit windows, python 2.7
when I type the command pip install statsmodels
I get the following error for some module of scipy...
Failed building wheel for Scipy Failed cleaning build dir for scipy
install numpy
pip install numpy
If you face installation issues for numpy, get the pre-built windows installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/ for your python version (python version is different from windows version).
numpy 32-bit: numpy-1.11.1+mkl-cp27-cp27m-win32.whl
numpy 64-bit: numpy-1.11.1+mkl-cp27-cp27m-win_amd64.whl
Later you require VC++ 9.0, then please get it from below link Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
Then install
Get the pre-built windows installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/ for your python version (python version is different from windows version).
Scipy 32-bit: scipy-0.18.0-cp27-cp27m-win32.whl
Scipy 64-bit: scipy-0.18.0-cp27-cp27m-win_amd64.whl
If it fails saying whl is not supported wheel on this platform , then upgrade pip using python -m pip install --upgrade pip and try installing scipy
Now try
pip install scipy
Then try
pip install statsmodels
It should work like a charm
I have tried to write this on cmd.exe and it worked.
pip install statsmodels==0.6.0
install statsmodels for python 2.7 in windows
An easier way to install python libraries on Windows with C/C++/Fortran/... dependencies is to use conda. conda is available in MiniConda or Anaconda continuum products.
Another easy way to install scientific python libraries on windows is to use Christoph Gohlke's windows web page.
If you have no much idea about all of them and how to manage dependencies on windows I recommend you uninstalling your Python and installing anaconda. Anaconda already has Numpy, Scipy, Matplotlib,..., and statsmodels pre-installed (see the list of the packages included in the anaconda distribution).
Make sure you are using the latest version of pip
To check which version you are using try:
pip --version
To install statsmodels you can either go to cmd.exe or if you are using python pycharm use "Terminal Window" and type:
pip install statsmodels==0.9.0

Categories