PIL installation on anaconda for windows 10, 64 bit - python

when I ran conda-forge to get xgboost running, it seems to have affected few running packages, one of them being PIL. It was running properly until I ran conda-forge, but now I am getting the following error.
ImportError Traceback (most recent call last)
<ipython-input-3-588a23339ee5> in <module>()
5 import matplotlib.pyplot as plt
6 import scipy
----> 7 from PIL import Image
8 #from pillow import Image
9 from scipy import ndimage
C:\Anaconda3\lib\site-packages\PIL\Image.py in <module>()
54 # Also note that Image.core is not a publicly documented interface,
55 # and should be considered private and subject to change.
---> 56 from . import _imaging as core
57 if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
58 raise ImportError("The _imaging extension was built for another "
ImportError: DLL load failed: The specified module could not be found.
when I try to install PIL again using conda install pil, I get the following error message
(C:\Anaconda3) C:\Users\P Srinivasa Rao>conda install pil
Fetching package metadata ...............
Solving package specifications: .
UnsatisfiableError: The following specifications were found to be in conflict:
- pil -> python 2.6*
- python 3.6*
Use "conda info <package>" to see the dependencies for each package.
I then installed pillow, which seems to have gone well. But when I run from PIL import image, I still get the same error as above. I tried from pillow import image, it says no module found named pillow
Any advice on how to resolve this issue and get PIL working again?
I am using anaconda3 on windows 10, 64bit.

The problem looks like you have both pythons 2.x versions and a 3.x version. try the following
create a conda environment with python 3.6
conda create -n pil-env python=3.6
load PIL
conda install Pillow==4.0.0
I found Pillow 4.0.0 to be the most stable while using it on 3.6

Related

Fixing "DLL load failed: The specified module could not be found." error in python for importing rasterio

I am trying to download the package rasterio for analyzing raster datasets in python within the geospatial analysis disciplines.
I have downloaded the package dependencies for rasterio, including gdal, pyproj, and fiona via the wheel files from this geospatial analysis binaries resource: https://www.lfd.uci.edu/~gohlke/pythonlibs/
I installed these packages through pip.
I then downloaded from this resource the wheel file rasterio through pip.
I received the following message from Window Command Prompt after installing rasterio: Successfully installed affine-2.3.0 numpy-1.21.4 pyparsing-3.0.6 rasterio-1.2.10 snuggs-1.4.7.
I want to use this package in Jupyter Notebook, and so I open a Jupyter Notebook file and run import rasterio, and receive this error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-17-350e27267e59> in <module>
----> 1 import rasterio
~\Anaconda3\lib\site-packages\rasterio\__init__.py in <module>
15 from pathlib import Path
16
---> 17 from rasterio._base import gdal_version
18 from rasterio.drivers import driver_from_extension, is_blacklisted
19 from rasterio.dtypes import (
ImportError: DLL load failed: The specified module could not be found.
How can I address this "DLL load failed" issue and address this error so that I can use rasterio? I was told this could be an issue of not having Visual C++ installed on my computer, and so I installed Visual Studio 2022 on my computer, but this did not help.
I solved this problem with the following steps:
I created a fresh environment
I installed the gdal library (since rasterio is built on top of it), with the command:
conda install -c conda-forge gdal
I installed rasterio with the command:
conda install -c conda-forge rasterio

Tensorflow import error when loading PIL (pillow)

I'm having an issue with my tensorflow on windows 10 (python 3.7, tf 2.1.0, keras 2.3.1, pillow 7.1.1). I had some code I wrote on an osx machine and was porting over to windows. I am using conda envs and have all the necessary packages installed (tensorflow, keras, pillow, opencv, etc) but I am getting the following error
Traceback (most recent call last):
...
"...\venv\lib\site-packages\keras_preprocessing\image\utils.py", line 108, in load_img
raise ImportError('Could not import PIL.Image. '
ImportError: Could not import PIL.Image. The use of `load_img` requires PIL.
I have tried reinstalling pillow, tensorflow, keras, creating a new environment, installing with pip and repeated this in about every location I can think of but this issue remains persistent. Any help would be greatly appreciated.
Thank you
One solution that might work for your case:
First, you need to : pip install pillow (uninstall + reinstall / upgrade it it's the case)
Second, you need to change your imports in this way:
from IPython.display import display
from PIL import Image
This solution can be found in the following thread:
ImportError: Could not import the Python Imaging Library (PIL) required to load image files on tensorflow

rasterio and gdal DLL load fail in PyCharm

I have a conda environment with rasterio installed and a whole load of other libraries, including gdal.
When I do:
import rasterio
on jupyter notebook, it loads fine and I can utilise it's methods etc..
When I do exactly the same thing on PyCharm, with the same environment and interpreter, I can the following error:
from rasterio._base import gdal_version
ImportError: DLL load failed: The specified module could not be found.
I'm struggling to understand why this is the case, as it loads fine in jupter notebook.
I encountered the same problem as you and has finished solving it.
First, You need to ensure that gdal version is still 2.x. If no, just remove it.
conda remove rasterio gdal -y
then reinstall gdal with specifying the installation version:
conda install rasterio gdal=2 -y
Then, you need add GDAL_DATA which containing a gcs.csv file to environment,
for me in Windows:
setx /m GDAL_DATA C:\Users\Admin\AppData\Local\ESRI\conda\envs\python3\Library\share\gdal
reboot your computer, and import gdal before importing rasterio:
In [1]: import rasterio
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-350e27267e59> in <module>
----> 1 import rasterio
~\AppData\Local\ESRI\conda\envs\python3\lib\site-packages\rasterio\__init__.py in <module>
20 pass
21
---> 22 from rasterio._base import gdal_version
23 from rasterio.drivers import is_blacklisted
24 from rasterio.dtypes import (
ImportError: DLL load failed: 找不到指定的模块。
In [2]: from osgeo import gdal
In [3]: import rasterio

DLL load failed: The specified module could not be found

I have installed Python 3.6.4. When I import cv2, it throws this error:
DLL load failed: The specified module could not be found.
I have OpenCV version 2.4.13.
What should i do?
It's possible that you have Python 2 and 3 installed and Python 3 doesn't know about your opencv installation. Try this:
pip3 install opencv-python
That will install opencv for Python 3 and hopefully that fixes your problem.
Try doing this:
Go to command prompt and "cd" the directory of python.
Enter this if you are running Python 3.x.x
pip3 install opencv-python
OR
2.If on Python 2.x.x
pip2 install opencv-python
DO NOT USE:
pip install opencv
That was my mistake and had to dig a lot to find a solution.
In my situation,
ImportError Traceback (most recent call last)
in ()
10 import os.path
11 from keras.models import load_model
---> 12 import cv2
13 from utils.utils import get_yolo_boxes, makedirs
14 from PIL import Image
ImportError: DLL load failed: The specified module could not be found.
Face this ImportError in the pass week, and I solved with enter below scripts in the Anaconda Prompt.
conda install -c menpo opencv
And here is my environment:
Python 3.6.5 Anaconda
Keras 2.2.2
tensorflow 1.9.0
For more details, here is the log I tried to solved this ImportError:
micky619/holiday-similarity#3
This can happen if you are using windows 10 N distribution, the N distributions does not come pre installed with windows media feature pack, which is required after OpenCV version 3.4 and onwards.
The preferred solution is to install the feature pack at : https://www.microsoft.com/en-us/software-download/mediafeaturepack
Be careful to choose the version that works with your current version of windows.
If that is not an option, fall back to an earlier version of OpenCV that does not have dll dependencies, you can do that by:pip install opencv-python=3.3.0.9
If the problem still persists try using Dependency walker to find out where specifically your problems stem from and then try fixing them individually.
Since windows rolled out it's N version this problem has been seen at many places, and has many impacts across the windows environment, the fastest way to identify if you have this problem is open youtube in Edge browser, if it says HTML5 media plugin not found, this is the problem.

How to install scipy misc package

I have installed (actually reinstalled) scipy:
10_x86_64.whl (19.8MB): 19.8MB downloaded
Installing collected packages: scipy
Successfully installed scipy
But the misc subpackage is apparently not included?
16:03:28/shared $ipython
In [1]: from scipy.misc import imread
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-f9d3d927b58f> in <module>()
----> 1 from scipy.misc import imread
ImportError: cannot import name imread
What is the way to install the scipy.misc package?
I think you need to install PIL as well. From the scipy.misc docs:
Note that the Python Imaging Library (PIL) is not a dependency of SciPy and therefore the pilutil module is not available on systems that don’t have PIL installed.
I had same problem, running Python 2.7.12 on an old Windows XP/SP3 box. I had some stuff running on Python on MacBook, and wanted to make it work on an old Windows box. It can be done. The winbox had pip ver. 8, and I upgraded it to pip ver. 9, from within Python, using the suggestion pip provides when you run it. I had installed numpy and Pillow (current ver of PIL), using "pip install numpy" and "pip install Pillow", but "pip install scipy" and "pip install scipy.misc" failed with "no matching distribution found". I had to uninstall numpy, and then install two files: 1) numpy+mkl and then 2) scipy, both files installed are binaries for Windows, in .whl (wheel) archive format, downloaded from: http://www.lfd.uci.edu/~gohlke/pythonlibs/
site maitained by Christoph Gohlke. Find the binary versions you need for your flavour of Windows, and downloaded them into C:\some\directory. Installation order is important. First the numpy+mkl is installed, using pip, with the scipy file second. I downloaded the files from Gohlke's site, and then used pip to install them. For my old winbox, this was:
C:\some\directory\> pip install numpy-1.12.1rc1+mkl-cp27-cp27m-win32.whl
(you should see)
Installing collected packages: numpy
Successfully installed numpy-1.12.1rc1+mkl
(then, you can run)
C:\some\directory\> pip install scipy-0.18.1-cp27-cp27m-win32.whl
and you should see the "Successfully installed..." message. I had already installed Pillow.
Confirm by starting Python, and trying:
>>> import numpy as np
>>> from PIL import Image, ImageDraw
>>> import scipy.misc
and all these should work. You should be able to render a .jpg with:
image = Image.open("Somefile.jpg")
image.show()
and your somefile.jpg will be displayed.

Categories

Resources