The _imaging C module is not installed (on windows) - python

I'm trying to generate some pdf with django/PIL/Imaging and everything is good until I attempt to put some images into the pdf:
Exception Type: ImportError
Exception Value:
The _imaging C module is not installed
Exception Location: D:\install\python27\lib\site-packages\PIL\Image.py in __getattr__, line 37
Python Executable: D:\install\python27\python.exe
Python Version: 2.7.1
Python Path:
['D:\\~Sasha\\Portman',
'D:\\install\\python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg',
'D:\\install\\python27\\lib\\site-packages\\pisa-3.0.33-py2.7.egg',
'D:\\install\\python27\\lib\\site-packages\\html5lib-0.95-py2.7.egg',
'D:\\install\\python27\\lib\\site-packages\\pypdf-1.13-py2.7.egg',
'D:\\install\\PyCharm 2.0.2\\helpers',
'D:\\~Sasha\\Portman',
'D:\\~Sasha',
'C:\\Windows\\system32\\python27.zip',
'D:\\install\\python27\\DLLs',
'D:\\install\\python27\\lib',
'D:\\install\\python27\\lib\\plat-win',
'D:\\install\\python27\\lib\\lib-tk',
'D:\\install\\python27',
'D:\\install\\python27\\lib\\site-packages',
'D:\\install\\python27\\lib\\site-packages\\PIL']
PIL was installed via pre-compiled bundle from PIL website and importing _imaging was giving this output:
Python 2.7.1 (r271:86832, Feb 7 2011, 11:33:02) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import _imaging
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: DLL load failed: %1 is not a valid Win32 application.
Could python x64 be causing this issue?
Python 2.7.1 (r271:86832, Feb 7 2011, 11:33:02) [MSC v.1500 64 bit (AMD64)] on win32
I got a pre-built package for x64 of PIL and installed it on top of existing bundle, now import via console does work:
>>> import _imaging
import _imaging # dynamically loaded from D:\install\python27\lib\site-packages\PIL\_imaging.pyd
but I keep getting the same error whilst trying to generate the pdf file.

Yes, this could definitely be (and most likely is) caused by an x64 issue. If you're running Python x64, any module that includes a native DLL needs to be installed in a version compiled for x64 too.
Edit: I cannot find an actual precompiled version for x64 at the PIL site, but here is a starting point if you're interested in compiling it yourself.

I had the same problem. I just simply uninstalled
PIL
and installed Pillow which is replacement for PIL
pip install pillow
This worked for me.

I am on Windows, and had a problem ""ImportError: The _imaging C module is not installed"".
The problem solved by installing Pillow from here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pil. (it's given by a post however I can't locate it back..)

This is an old question... but it seems the issue can still arise.
In my case (Windows 11/x64), I was able to solve the issue by using the pip version of pillow rather than the conda one:
pip install --force pillow
Not sure this is the cleanest way but at least it works!

I was having the same problem on windows. I simply uninstalled pillow and then installed it again, it worked for me.
pip uninstall pillow
pip install pillow
PS: I did this on anaconda's terminal and in the base environment.

Related

Pip successfully installed module not found: ImportError: No module named xlwt

My OS: win 10 ,
installed:
python 2.7 ( command is python)
python 3.9.5 ( command is python3)
pip , pip3 ( both for python3, seems )
pip command:
c:\>pip3 config list -v
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'c:\users\luelue\appdata\local\programs\python\python39\pip.ini'
c:\>pip config list -v
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\luelue\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'c:\users\luelue\appdata\local\programs\python\python39\pip.ini'
I installed xlwt via pip, and I can see it's installed :
c:\>pip install xlwt
Requirement already satisfied: xlwt in c:\users\luelue\appdata\local\programs\python\python39\lib\site-packages\xlwt-1.3.0-py3.9.egg (1.3.0)
However, when I try to import it, got error: No module named xlwt
c:\>python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named xlwt
>>> exit()
Also, I used pip3 install xlwt successfully, but run python3 ... import xlwt failed. full log:
C:\files\dong_tai_pai_fang_ji_suan\python_code>pip3 install xlwt
Requirement already satisfied: xlwt in c:\users\luelue\appdata\local\programs\python\python39\lib\site-packages\xlwt-1.3.0-py3.9.egg (1.3.0)
C:\files\dong_tai_pai_fang_ji_suan\python_code>python3
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xlwt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'xlwt'
>>>
how to resolve this?
should I configure the windows PATH or something for python/pip ?
thanks
edit:
maybe I installed multiple python3:
your python version is 2.7 in python console.
change to python 3.9 version.
maybe I installed multiple python3
Do python3 -m pip install xlwt, this always install for python3 (python launched when you do python3 in terminal), then it should be possible to import installed module in python3. If you want to know more about that read Installing Python Modules in docs.
OK at last I find the root cause.
There are 2 versions of python in my PC:
version 3.9, this is installed by myself.
version 2.7, this is automatically installed by electron-vue
and I believe there are some conflicts between these two version's configuration. ( e.g. execute path, pip path, etc ) which makes pip install work incorrectly.
solution is quite simple: uninstall all the python version and re-install 3.7, everything goes well!

ImportError: cannot import name 'animation' (matplotlib + python 3.8.5)

Why doesnt matplotlib imported with python 3.8.5 work?
Im running anaconda version 3 which is 64 bit. The error im getting is:
Matplotlib is installed with version 3.3.2:
Using cached matplotlib-3.3.2-cp38-cp38-win_amd64.whl (8.5 MB)
Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] :: Ana
conda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\Administrator\AppData\Roaming\Python\Python38\site-packages\mat
plotlib\__init__.py", line 139, in <module>
from . import cbook, rcsetup
File "C:\Users\Administrator\AppData\Roaming\Python\Python38\site-packages\mat
plotlib\rcsetup.py", line 26, in <module>
from matplotlib import animation, cbook
ImportError: cannot import name 'animation' from partially initialized module 'm
atplotlib' (most likely due to a circular import) (C:\Users\Administrator\AppDat
a\Roaming\Python\Python38\site-packages\matplotlib\__init__.py)
I had the same Issue. The site packages did not have the folder for animation at matplotlib folder. I uninstalled matplotlib and force reinstalled to have the packages added to the library and fixed the issue
pip install matplotlib --force-reinstall --user
I had so many problems with matplotlib it was unreal. In the end, I managed to get it working by removing matplotlib completely from my virtual env and then reinstalling using conda install matplotlib. I don't know what the problem was in the end but everything seems to be working now as it should.
Forcing reinstall didn't help me in any way. I removed the package and then manually deleted package folder from site-package directory as for some reason all the files were still there. After that installed and loaded package with no issues.

import _ssl error,DLL load failed ,Python 37 Anaconda Windows 10

I am struggling with _ssl issue on Win10.
I have moved python packages and code from Windows 7 to Windows 10. In the starting I was facing below issues :
ImportError: Missing required dependencies ['numpy']
But this one got resolved via reinstalling .whl packages of numpy and pandas.
Currently I am facing below issue, while executing the code:
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified procedure could not be found.
Referred to other Questions on Stack overflow and tried few steps:
Changed Path variables as advised in this Python 3.7 anaconda environment - import _ssl DLL load fail error
Installed pyopenssl .
Updated the system Environment variables.
Restarted the pycharm.
Currently on Anaconda prompt It's showing as :
(base) C:\>
(base) C:\>python
Python 3.7.0 (default, Aug 14 2018, 19:12:50) [MSC v.1900 32 bit
(Intel)] :: Ana
conda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import ssl
>>> import _ssl
>>>
which means there is no issue with _ssl.pyd file.
This is working perfectly fine on Windows 7, but not on Windows 10.
NO!! Of course you can keep using python 3.7 from PyCharm. There is another answer given for that question Python 3.7 anaconda environment - import _ssl DLL load fail error which allows you to get rid of this issue by copy/paste of two dll files regarding _ssl procedure.
Based on Pycharm forum post it's a known issue that will be fixed in the next release of Pycharm 2019.1. The only way to resolve this is to create an environment using python 3.6. If you use that environment as your interpreter PyCharm should work properly.
Cheers!!

Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: ...

I have two python 3 locations. One is located here,
"C:\Users\Ryano\AppData\Local\Programs\Python\Python37-32"
The other is related to Anaconda3 here,
"C:\Users\Ryano\Anaconda3"
I want run a .py file that uses the numpy package in the command prompt using the Anaconda3 python version. I go to import numpy and it doesn't recognize it:
C:\Users\Ryano\Anaconda3>python
Python 3.7.1 (default, Oct 28 2018, 08:39:03) [MSC v.1912 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
import numpy
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'numpy'
So I go to install the numpy package to the Anaconda 3 version python and this error pops up:
C:\Users\Ryano\Anaconda3\Scripts>pip install numpy
Collecting numpy
Using cached https://files.pythonhosted.org/packages/00/0e/5a8c34adb97fc1cd6636d78050e575945e874c8516d501421d5a0f377a6c/numpy-1.15.4-cp37-none-win_amd64.whl
Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: 'c:\users\ryano\anaconda3\lib\site-packages\html5lib-1.0.1.dist-info\METADATA'
Looking at the other posts similar to this one I could not find any solution that worked for my computer. Essentially I'm having issues with installing using pip.
Reinstall html5lib with conda:
conda install html5lib
There can be issues with using multiple installations on Windows.
Please check the answer to this question: what is the process of installing and working with PIL - Python Imaging Library ?
Hopefully one of the questions will fix the issue. If not, let me know.

Python module for OpenCV requires a library that's unavailable to Ubuntu 14.04

I'm trying to use OpenCV from within Python on an system using Ubuntu 14.04. When I try to import cv2, I get the following error:
me#Bedrock1:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libavcodec.so.53: cannot open shared object file: No such file or directory
A search for libavcodec.so.53 reveals that my system has only libavcodec.so.54.
A search of the internet reveals that libavcodec.so.53 has been removed from the 14.04 repository (http://www.ubuntuupdates.org/package/core/trusty/universe/base/libavcodec53). This, probably, explains my inability to apt-get install this library:
me#Bedrock1:~$ sudo apt-get install libavcodec53 libavcodec-extra-53
...
E: Package 'libavcodec53' has no installation candidate
E: Package 'libavcodec-extra-53' has no installation candidate
Unfortunately, now I'm truly stuck.
Is there a way to get the cv2 module to use libavcodec.so.54, or a way to find & install libavcodec.so.53?
NOTE: I just tried reinstalling by following the instructions at https://help.ubuntu.com/community/OpenCV
but I still am getting the same libavcodec.so.53 error....
Try this script. Ubuntu man page has an old version of this script. This should work.
https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_9.sh
Check if reinstalling opencv resolves the issue
sudo apt-get install --reinstall python-opencv
BTW how did you install it before ?
I got the same problem on Ubuntu 14.04 64bit, as reported here:
https://bugs.launchpad.net/ubuntu/+source/opencv/+bug/1161485/comments/2
I tried downloading the source package and recompiling, in order to get the correct libraries linked, but with no luck.
At the end, I recompiled from source, following these instructions:
http://docs.opencv.org/doc/tutorials/introduction/linux_install/linux_install.html
Everything goes fine except for the python module compilation, which was disable at configure time (listed in Opencv modules: Unavailable: section).
I used cmake-gui to configure the build and generate makefiles. The configuration step was correctly setting PYTHON2_INCLUDE_DIR, PYTHON2_INCLUDE_DIR2 and PYTHON2_LIBRARY, but it was NOT setting PYTHON_INCLUDE_DIR, PYTHON_INCLUDE_DIR2 and PYTHON_LIBRARY.
In order to actually build the python module, you should set these PYTHON_ variables equal to their corresponding PYTHON2_ variables. Then, the make step will build also cv2.so.

Categories

Resources