I have strange issue while loading matplotlib package. Never observed that before. The package is trying to load PIL from the wrong place. If I try to load PIL from the command line, it also loaded from the wrong place.
Here is matplotlib traceback:
>>> import matplotlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/XXX/python_rep/miniconda3/envs/work/lib/python3.9/site-packages/matplotlib/__init__.py", line 113, in <module>
from . import _api, _version, cbook, _docstring, rcsetup
File "/home/XXX/python_rep/miniconda3/envs/work/lib/python3.9/site-packages/matplotlib/rcsetup.py", line 27, in <module>
from matplotlib.colors import Colormap, is_color_like
File "/home/XXX/python_rep/miniconda3/envs/work/lib/python3.9/site-packages/matplotlib/colors.py", line 51, in <module>
from PIL import Image
File "/homeappl/common-software/sw/python3.6/lib/python3.6/site-packages/PIL/Image.py", line 69, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/homeappl/common-software/sw/python3.6/lib/python3.6/site-packages/PIL/__init__.py)
Please note that I use my own conda environment with python 3.9
It is activated and contained Pillow version 9.0.0
Other packages are loaded from that instance, but bloody PIL tries to reach the common area.
/home/XXX/python_rep/miniconda3/envs/work/bin/python3.9 -m pip install pillow
Requirement already satisfied: pillow in /homeappl/common-software/sw/python3.6/lib/python3.6/site-packages (7.0.0)
I have no idea why it tries to load package from old place. But I do not have access to that - due to admin rights.
How to force machine not to use wrong package?
Related
I have installed matplotlib on a Windows 10 machine using
pip3 install matplotlib
I get a message that it's using the wheel
matplotlib-3.4.1-cp39-cp39-win_amd64.whl1
When I type import matplotlib in a python 3.9 shell, I get the following message:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python39\lib\site-packages\matplotlib\__init__.py", line 107, in <module>
from . import _api, cbook, docstring, rcsetup
File "C:\Python39\lib\site-packages\matplotlib\rcsetup.py", line 26, in <module>
from matplotlib.colors import Colormap, is_color_like
File "C:\Python39\lib\site-packages\matplotlib\colors.py", line 82, in <module>
from matplotlib import _api, cbook, scale
File "C:\Python39\lib\site-packages\matplotlib\scale.py", line 18, in <module>
from matplotlib.ticker import (
File "C:\Python39\lib\site-packages\matplotlib\ticker.py", line 179, in <module>
from matplotlib import transforms as mtransforms
File "C:\Python39\lib\site-packages\matplotlib\transforms.py", line 46, in <module>
from matplotlib._path import (
ImportError: DLL load failed while importing _path: The specified module could not be found.
I ran the installation under Windows Terminal, as an administrator.
How can I fix this? I don't want to install anaconda or WinPython, if I can avoid it. I just want matplotlib to work.
This issue is present again with matplotlib 3.3.2, 3.3.3 and 3.3.4. .
matplotlib 3.3.0 3.3.1 work.
I found a solution by mkunzBGC on Github:
https://github.com/matplotlib/matplotlib/issues/18292#issuecomment-792634734
The downgrade to matplotlib 3.3.1 worked for me.
I figured it out. If you have already installed matplotlib, but the error still comes about. Then you have to download Microsoft C++ from their website. https://www.microsoft.com/en-US/Download/confirmation.aspx?id=48145
install Microsoft c++ then you can try again to run your code. it has worked for me like magic. I got the solution from a youtube video.
link here. https://www.youtube.com/watch?v=DpwsvUkNAmg
Traceback (most recent call last):
File "/home/raghav/Desktop/Everything/TinderAutomation-master/img_scrape.py", line 1, in <module>
from skimage.io import imread, imsave, imshow, show
File "/usr/local/lib/python3.7/dist-packages/skimage/io/__init__.py", line 7, in <module>
from .manage_plugins import *
File "/usr/local/lib/python3.7/dist-packages/skimage/io/manage_plugins.py", line 24, in <module>
from .collection import imread_collection_wrapper
File "/usr/local/lib/python3.7/dist-packages/skimage/io/collection.py", line 11, in <module>
from PIL import Image
File "/usr/lib/python3/dist-packages/PIL/Image.py", line 60, in <module>
from . import _imaging as core
ImportError: cannot import name '_imaging' from 'PIL' (/usr/lib/python3/dist-packages/PIL/__init__.py)
I've problem importing imaging modules like matplotlib and skimage.io. I'm fairly new to python. Can anyone help me with this problem?
Try this: I first installed PIL (not Pillow) using
pip3 install --no-index -f https://dist.plone.org/thirdparty/ -U PIL
Then I found Pillow and installed it using
pip3 install Pillow
What fixed my issues was uninstalling both and reinstalling Pillow
pip3 uninstall PIL
pip3 uninstall Pillow
pip3 install Pillow
Could anyone tell me what files I should download and which statements I must execute in the command line to install Matplotlib?
I have Python 2.7.13 on Windows 10 64 bit.
These are the files I unzipped:
All downloaded from: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
Commands I executed:
python -m pip install -U pip setuptools
python -m pip install matplotlib
python -m pip install -U pip
I am getting these two errors when checking if Numpy and Matplotlib are installed.
>>> import numpy
**Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
import numpy
File "numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: %1 no es una aplicación Win32 válida.**
>>> import matplotlib
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import matplotlib
File "matplotlib\__init__.py", line 122, in <module>
from matplotlib.cbook import is_string_like, mplDeprecation, dedent, get_label
File "matplotlib\cbook.py", line 33, in <module>
import numpy as np
File "numpy\__init__.py", line 142, in <module>
from . import add_newdocs
File "numpy\add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "numpy\lib\__init__.py", line 8, in <module>
from .type_check import *
File "numpy\lib\type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "numpy\core\__init__.py", line 26, in <module>
raise ImportError(msg)
ImportError:
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
If you're working with a numpy git repo, try `git clean -xdf` (removes all
files not under version control). Otherwise reinstall numpy.
Original error was: DLL load failed: %1 no es una aplicación Win32 válida.
This is a common issue for windows users. And you will probably need precompiled packages for some other libraries as well, e.g. scipy.
You will find on SourceForge the numpy superpack whose name structure is numpy-X.X.X-win32-superpack-python2.7.exe, e.g. numpy-1.9.2-win32-superpack-python2.7.
On Pypi (Python Package Index), you will find the matplotlib library, whose name structure is matplotlib-X.X.X.win32-py2.7.exe, e.g matplotlib-1.4.3.win32-py2.7.exe.
Installing matplotlib through pip by automatically downloading the files from the python index as you're trying to do here will most probably fail for windows.
There are two main options:
Install a complete distribution like Anaconda, Canopy, WinPython, etc. which already has all the respective libraries included.
Use precompiled wheels. A source for those is indeed this site by Christoph Gohlke. You would then need to make sure to install all dependencies first and matplotlib last. Starting with numpy is the best, then other dependencies, matplotlib last. To install those use
pip install <filename of wheel>
e.g.
pip install numpy‑1.13.0rc1+mkl‑cp27‑cp27m‑win_amd64.whl
I'm going through the API tutorial on New Coder (this one) and got the following error when I try to run the program:
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9Traceback (most recent call last):
File "api.py", line 7, in <module>
import matplotlib.pyplot as plt
File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 27, in <module>
import matplotlib.colorbar
File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/colorbar.py", line 32, in <module>
import matplotlib.artist as martist
File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/artist.py", line 12, in <module>
from .transforms import Bbox, IdentityTransform, TransformedBbox, \
File "/home/crash/TestEnv/venv/local/lib/python2.7/site-packages/matplotlib/transforms.py", line 39, in <module>
from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox,
ImportError: numpy.core.multiarray failed to import
I know it isn't my code because I tried running it with the example code too and had the same issue. One answer I saw suggested on here was to try Numpy 1.8, but that didn't work either.
Also, all of this is set up within a virtual environment as directed so I don't think it's an issue of what I have installed elsewhere.
Installing packets from file with requirements may cause failures. I mean something like pip install -r requirements.txt
It seems to me that pip just installs packets in order without dependencies (first line from file, second line, ...).
I had same issue because of having installed numpy outside of environment and numpy after matplotlib in requirements.txt Pip compiled matplotlib with system nympy, after that it installed new numpy and nothing worked.
I just have switched strings and set matplotlib after numpy. Now it works.
Try this:
pip install numpy --upgrade
It works for me
The full error:
import matplotlib
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import matplotlib
File "R:\Python34\lib\site-packages\matplotlib\__init__.py", line 180, in <module>
from matplotlib.cbook import is_string_like
File "R:\Python34\lib\site-packages\matplotlib\cbook.py", line 34, in <module>
import numpy.ma as ma
ImportError: No module named 'numpy.ma'
numpy is imported normally.
How do I install numpy.ma?
I also faced the same situation today. I found that I had saved a file as numpy.py, so check the filenames in your folder.
Re-install the correct version of numpy.
download correct .whl file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
pip install C:\Path\To\Wheel\Filename.whl # for example: numpy-1.9.2+mkl-cp34-none-win_amd64.whl
Use Your (via terminal) package manager and search.
Example on Ubuntu:
aptitude search numpy
and install package.
In my case:
apt-get install python-numpy