Can't from PIL import Image? - python

I have tried to install pillow version 7.0.0 but get the following error below. Please suggest a solution.
ImportError Traceback (most recent call last)
<ipython-input-32-b7f01c2f8cfe> in <module>
----> 1 from PIL import Image
~\Anaconda3\envs\streamlined\lib\site-packages\PIL\Image.py in <module>
42 # PILLOW_VERSION was removed in Pillow 7.0.0.
43 # Use __version__ instead.
---> 44 from . import ImageMode, TiffTags, UnidentifiedImageError, __version__, _plugins
45 from ._binary import i8, i32le
46 from ._util import deferred_error, isPath
ImportError: cannot import name 'UnidentifiedImageError' from 'PIL' (unknown location)

This looks like a library that you are using, or that is interfacing with PIL/Pillow was built for a previous version, so you either need to update the library/code calling PIL/Pillow, or install the version of Pillow that your library/code is written for.
Example of how to install pillow version 5.0.0
$ pip install pillow==5.0.0

Related

Conda 3.9 is not working with numpy on macOS ("Reason: Image not found")?

I just installed a python3.9 environment for conda. It works for base python but apparently not for numpy. The error is "Reason: Image not found":
The installation of numpy had been successful:
conda install numpy
The following NEW packages will be INSTALLED:
blas conda-forge/osx-64::blas-2.106-openblas
libblas conda-forge/osx-64::libblas-3.9.0-6_openblas
libcblas conda-forge/osx-64::libcblas-3.9.0-6_openblas
libgfortran conda-forge/osx-64::libgfortran-5.0.0-9_3_0_h6c81a4c_18
libgfortran5 conda-forge/osx-64::libgfortran5-9.3.0-h6c81a4c_18
liblapack conda-forge/osx-64::liblapack-3.9.0-6_openblas
liblapacke conda-forge/osx-64::liblapacke-3.9.0-6_openblas
libopenblas conda-forge/osx-64::libopenblas-0.3.12-openmp_h54245bb_1
llvm-openmp conda-forge/osx-64::llvm-openmp-11.0.1-h7c73e74_0
numpy pkgs/main/osx-64::numpy-1.19.2-py39h0fa1045_0
numpy-base pkgs/main/osx-64::numpy-base-1.19.2-py39h3a452eb_0
Proceed ([y]/n)?
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
The installation conda install ipython was also successful. But ipython is not working:
$ipython
Python 3.9.1 (default, Dec 11 2020, 06:28:49)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.20.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import numpy as np
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/__init__.py in <module>
21 try:
---> 22 from . import multiarray
23 except ImportError as exc:
~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/multiarray.py in <module>
11
---> 12 from . import overrides
13 from . import _multiarray_umath
~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/overrides.py in <module>
6
----> 7 from numpy.core._multiarray_umath import (
8 add_docstring, implement_array_function, _get_implementing_args)
ImportError: dlopen(/Users/steve/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): Library not loaded: #rpath/libopenblas.dylib
Referenced from: /Users/steve/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
Reason: image not found
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
<ipython-input-1-0aa0b027fcb6> in <module>
----> 1 import numpy as np
~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/__init__.py in <module>
138 from . import _distributor_init
139
--> 140 from . import core
141 from .core import *
142 from . import compat
~/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/__init__.py in <module>
46 """ % (sys.version_info[0], sys.version_info[1], sys.executable,
47 __version__, exc)
---> 48 raise ImportError(msg)
49 finally:
50 for envkey in env_added:
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/Users/steve/miniconda3/envs/python39/bin/python"
* The NumPy version is: "1.19.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: dlopen(/Users/steve/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so, 2): Library not loaded: #rpath/libopenblas.dylib
Referenced from: /Users/steve/miniconda3/envs/python39/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-darwin.so
Reason: image not found
I am on macOS Catalina.
Channel Mixing: Incompatible Binaries
One possible issues is channel mixing. Different channels often use different build stacks, which can result in referencing different symbols in linked libraries. In this case, try ensuring everything comes from conda-forge, e.g.
conda install -c conda-forge conda-forge::numpy
Longer term, maybe consider adding conda-forge to the global channels configuration and possibly setting priority to "strict". See conda config --describe channels channel_priority. Also, the --env flag can be useful for changing such settings in an environment specific way.

Getting numpy error when using azureml-sdk

hy I followed the installation instructions here
and installed with
pip install --upgrade azureml-sdk[notebooks,automl] azureml-dataprep --ignore-installed PyYAML
It seem to work but a simple
import azureml.core
azureml.core.VERSION
Throws me a numpy error
> AttributeError Traceback (most recent call
> last) <ipython-input-3-08b704cd5542> in <module>
> ----> 1 import azureml.core
> 2 azureml.core.VERSION
c:\users\werth\appdata\local\continuum\anaconda3\envs\azuresdk\lib\site-packages\azureml\core\__init__.py in <module>
4
5 """Setup file for core package."""
----> 6 from azureml.core.workspace import Workspace
7 from azureml.core.experiment import Experiment
8 from azureml.core.runconfig import RunConfiguration
... I did not include the total traceback as it is apparently a Azure import problem.
AttributeError: type object 'numpy.ndarray' has no attribute '__array_function__'
It seems that the workspace has a problem. But I cannot think why. The Notebook is in a subfolder of the working directory. Numpy is installed.
If you would have an idea I would be thankfull.
Hi greatest Floridaman,
the answer is simple. During the installation of the azureml-train-automl 1.0.8 package, the numpy package needs to be maximum at version 1.15.0
So just downgrade numpy to that version
conda install numpy=1.15.0

Trying to plot an image in python (using scipy and numpy)

I'm trying to run this code:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-19
so I change it to this one:
and then I got this:
http://forumbilder.se/H8CIL/skarmavbild-2018-10-08-kl-21-22-47
What's wrong? I'm a newbie, and fyi, I'm only have anaconda installed to my Python 3.6.6 .
Regards,
--
and in code:
from skimage import data
photo_data = misc.imageio('./wifire/sd-3layers.jpg')
type(photo_data)
and i get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-9-c8186ae7b8e9> in <module>()
1 from skimage import data
2
----> 3 photo_data = misc.imageio('./wifire/sd-3layers.jpg')
4
5 type(photo_data)
AttributeError: module 'scipy.misc' has no attribute 'imageio'
So I change it to:
You have to import imageio. You might have to install the library if you don't have it yet (on your terminal):
pip install imageio
(If you don't have pip install yet, you can do on your terminal sudo easy_install pip, see here: How do I install pip on macOS or OS X?)
And then your code to use read the image with imageio:
import imageio
im = imageio.imread('./wifire/sd-3layers.jpg')
type(im)
To display your image, you can use visvis library (https://imageio.readthedocs.io/en/stable/examples.html). Then you total code would be:
import imageio
import visvis as vv
im = imageio.imread('./wifire/sd-3layers.jpg')
vv.imshow(im)

Pip not installing package properly

So I am trying to get hmmlearn working in Jupyter, and I have come across an error while installing Hmmlearn using pip. I have tried this solution, but it didn't work.
It seems to me that pip does install the _hmmc file, but it does so incorrect. instead it has the name
_hmmc.cp35-win_amd64
and the file extesion is .PYD, instead of .c
When I run the code to import it, I get this error :
ImportError Traceback (most recent call last)
<ipython-input-1-dee84c3d5ff9> in <module>()
7 import os
8 from pyAudioAnalysis import audioBasicIO as aB
----> 9 from pyAudioAnalysis import audioAnalysis as aA
C:\Users\gover_000\Documents\GitHub\Emotion-Recognition-Prototype\pyAudioAnalysis\audioAnalysis.py in <module>()
15 import audioFeatureExtraction as aF
16 import audioTrainTest as aT
---> 17 import audioSegmentation as aS
18 import audioVisualization as aV
19 import audioBasicIO
C:\Users\gover_000\Documents\GitHub\Emotion-Recognition-Prototype\pyAudioAnalysis\audioSegmentation.py in <module>()
16 import sklearn
17 import sklearn.cluster
---> 18 import hmmlearn.hmm
19 import cPickle
20 import glob
C:\Users\gover_000\Anaconda3\envs\python2\lib\site-packages\hmmlearn\hmm.py in <module>()
19 from sklearn.utils import check_random_state
20
---> 21 from .base import _BaseHMM
22 from .utils import iter_from_X_lengths, normalize
23
C:\Users\gover_000\Anaconda3\envs\python2\lib\site-packages\hmmlearn\base.py in <module>()
11 from sklearn.utils.validation import check_is_fitted
12
---> 13 from . import _hmmc
14 from .utils import normalize, log_normalize, iter_from_X_lengths
15
ImportError: cannot import name _hmmc
I don't know why pip just doesn't install it correctly, even when I tried to use --no-cache-dir
Edit: So i figured out what the problem was. my active python enviroment was python 3.5, as i was manually transferring the installed files to my enviroment, it failed because i had the wrong version.
I had to change my active python enviroment: using activate <my_enviroment name>
after that i could just use pip to install it again and it worked this time.
Looking at your error message I guess that you have downloaded the hmmlearn package from GIT. Have you tried using a wheel (*.whl) file instead? You can download one from here. Check out which version fits your python installation.
Then use:
pip install <the_wheel_that_corresponds_to_your_python_version>.whl
Hope it helps.
So i figured out what the problem was. my active python enviroment was python 3.5, as i was manually transferring the installed files to my enviroment, it failed because i had the wrong version. I had to change my active python enviroment: using activate <my_enviroment_name> after that i could just use pip to install it again and it worked this time.
not sure if it could be helpful to anyone but I installed hmmlearn as follows in my Jupyter Lab:
import sys
!{sys.executable} -m pip install hmmlearn

ImportError: cannot import name murmurhash3_32

I am trying to use the sklearn.qda package in python. I have installed it successfully but when Itry to import it I get the error message below. Can anybody tell me what should I do to fix this?
In [3]: from sklearn.qda import QDA
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-7d7abf937d66> in <module>()
----> 1 from sklearn.qda import QDA
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/qda.py in <module>()
12
13 from .base import BaseEstimator, ClassifierMixin
---> 14 from .utils.fixes import unique
15 from .utils import check_arrays, array2d
16
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/utils/__init__.py in <module>()
7 import warnings
8
----> 9 from .murmurhash import murmurhash3_32
10 from .validation import (as_float_array, check_arrays, safe_asarray,
11 assert_all_finite, array2d, atleast2d_or_csc,
ImportError: cannot import name murmurhash3_32
I had the same problem, I run:
sudo pip install -U scikit-learn
and now everything is working fine
I started a new shell and this problem went away
I faced the similar situation of getting mumurhash error while installing sklearn.preprocessing library.
I upgraded numpy version from 1.13 to 1.15
using
pip install --upgrade numpy
After this, I was able to import the sklearn library.
I fixed this by upgrading murmurhash to 1.0.5.
I faced a similar problem, so there are mainly two solutions
Either run it in administrator mode and install all the libraries and run in admin mode. Something that I would not recommend
Use virtualenv to install the libraries again and run your command in the virtualenv. This worked for me.
Hope this helps

Categories

Resources