Pypy and Matplotlib error in virtual environment - python

I am using Ubuntu 16.04 and Python 2.7, and I have set up a virtual environment (virtualenv) using a pypy interpreter.
I even installed succeffully the matplotlib library.
However, we it comes to using it on my own code I get this error messagge:
Traceback (most recent call last):
File "my_script.py",
line 20, in
import matplotlib.pyplot as plt
File "/home/.../venv/site-packages/matplotlib/pyplot.py",
line 115, in
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File
"/home/.../venv/site-packages/matplotlib/backends/init.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/home/.../venv/site-packages/matplotlib/backends/backend_tkagg.py",
line 13, in
import matplotlib.backends.tkagg as tkagg
File "/home/.../venv/site-packages/matplotlib/backends/tkagg.py",
line 9, in
from matplotlib.backends import _tkagg RuntimeError: Cannot dlopen tkinter module file
What can I do to fix it?
EDIT: The solution proposed here is the same, but I think that the problem (pypy and matplotlib) and the error message are quite different.

Related

Matplotlib won't run on Windows 10 -- DLL fails to load

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

Tkinter in virtual environment (PyCharm/Mac OS 10.13.4)

I have set up a virtual environment and when I try to run matplotlib on it, I get the following error:
Traceback (most recent call last):
File "/Users/sumeet/PycharmProjects/VISM/test2.py", line 2, in <module>
import matplotlib.pyplot as plt
File "/Users/sumeet/tensorflow/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/sumeet/tensorflow/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
[backend_name], 0)
File "/Users/sumeet/tensorflow/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
from . import tkagg # Paint image to Tk photo blitter extension.
File "/Users/sumeet/tensorflow/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
from six.moves import tkinter as Tk
File "/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/Cellar/python/2.7.14_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
From what I understand, I need to
set the environment variables correctly in the activate script
or I can symlink tkinter folder to virtualenv python2.7.
I have followed the steps here: TKinter in a Virtualenv, but I am still getting the error.
Steps that I followed are:
To virtualenv/bin/activate, I added
TK_LIBRARY=/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/site-packages/PIL:/usr/lib
TKPATH=/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/site-packages/PIL:/usr/lib
TCL_LIBRARY=/usr/lib
export TCL_LIBRARY TK_LIBRARY TKPATH
In virtualenv/lib/python2.7 I ran, ln -s /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_tkinter.so
Note that when I am using the system Python as an interpreter on PyCharm, matplotlib works fine which gives me a feeling that Tkinter is available somewhere on my system but I am failing to call it from my virtual environment.
The link above seems to be working for Ubuntu. I am wondering if anyone know what is the analogous version for Mac.
Thanks!
If you are not specific to using tkinter in virtual environment then you can use the following lines of code:
import matplotlib
matplotlib.use(‘TkAgg’)
import matplotlib.pyplot as plt
I hope this solves the problem.

Python DLL load failed, whilst having installed packages

I'm trying to run a python script however I get the message
ImportError: DLL load failed: %1 is geen geldige Win32-toepassing.
Full error:
Traceback (most recent call last):
File "ROC_plotting.py", line 2, in <module>
import matplotlib.pyplot as plt
File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "C:\Python27\lib\site-packages\matplotlib\backends\__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "C:\Python27\lib\site-packages\six.py", line 203, in load_module
mod = mod._resolve()
File "C:\Python27\lib\site-packages\six.py", line 115, in _resolve
return _import_module(self.mod)
File "C:\Python27\lib\site-packages\six.py", line 82, in _import_module
__import__(name)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 38, in <module>
import FixTk
File "C:\Python27\lib\lib-tk\FixTk.py", line 68, in <module>
import _tkinter
ImportError: DLL load failed: %1 is geen geldige Win32-toepassing.
It seems some of these errors are concerning Matplotlib, however when I run
pip list
It seems that I do have installed matplotlib
pip list output:
cycler (0.10.0)
functools32 (3.2.3.post2)
matplotlib (2.0.2)
numpy (1.11.3+mkl)
opencv-python (2.4.13.2)
pip (9.0.1)
pyparsing (2.2.0)
python-dateutil (2.6.0)
pytz (2017.2)
scikit-learn (0.18.1)
setuptools (28.8.0)
six (1.10.0)
wheel (0.29.0)
My python version is 2.7.13, I'm running on a 64-bit Windows system.
If it's not your python version, make sure you have Microsoft Visual C++ 2008 64bit installed as it's used by matplotlib check in Control Panel > Programs

How to resolve import matplotlib.pyplot as plt error?

I am having trouble getting my matplotlib library to work. I am running it on a virual environment, and I have installed numpy, and matplotlib. I first open my virtual environment, activate python, then I enter,
import matplotlib
everything goes fine, but then I enter,
import matplotlib.pyplot as plt
I get the error,
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/Users/kendallreid/.virtualenvs/cv/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
I have tried a number of different solutions to no avail. What could be the problem?
Use the below mentioned commands:
import matplotlib
matplotlib.use(‘TkAgg’)
import matplotlib.pyplot as plt
This worked for me. I hope it helps.

Error In Spyder After Anaconda Install

I just installed Anaconda. I already had Spyder 3.0.0 installed on my Windows 8.1 (64 bit). I also already had Python 3.4 installed. But, after installing Anaconda, I went into Preferences and pointed the Python executable to the Anaconda3 folder to utilize the 3.5 version. But when I started up Spyder again, got the following error:
An error ocurred while starting the kernel
C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\PIL\Image.py:81: RuntimeWarning: The _imaging extension was built for another version of Python.
RuntimeWarning
C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\PIL\Image.py:81: RuntimeWarning: The _imaging extension was built for another version of Python.
RuntimeWarning
Traceback (most recent call last):
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\spyderlib\widgets\externalshell\start_ipython_kernel.py", line 187, in
from ipykernel.kernelapp import IPKernelApp
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\ipykernel\__init__.py", line 2, in
from .connect import *
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\ipykernel\connect.py", line 18, in
import jupyter_client
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\jupyter_client\__init__.py", line 4, in
from .connect import *
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\jupyter_client\connect.py", line 21, in
import zmq
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\zmq\__init__.py", line 66, in
from zmq import backend
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\zmq\backend\__init__.py", line 40, in
reraise(*exc_info)
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\zmq\utils\sixcerpt.py", line 34, in reraise
raise value
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\zmq\backend\__init__.py", line 27, in
_ns = select_backend(first)
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\zmq\backend\select.py", line 27, in select_backend
mod = __import__(name, fromlist=public_api)
File "C:\WinPython󈛤bit𔂭.4.4.2\python𔂭.4.4.amd64\lib\site‑packages\zmq\backend\cython\__init__.py", line 6, in
from . import (constants, error, message, context,
ImportError: Module use of python34.dll conflicts with this version of Python.
Any ideas?
Suggestion:
rename your directory "C:\WinPython-64bit-3.4.4.2" in "C:\WinPython-64bit-3.4.4.2bis"
relaunch your Anaconda Spyder
if it doesn't help, rename it back to "C:\WinPython-64bit-3.4.4.2"

Categories