I am using Cuda and run into a RuntimeError.
Environment:
Python 2.7
Cuda 9.0
Torch 0.4.0
Torchvision 0.1.8
Matplotlib 1.2.0
error message:
File "/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py", line 13, in <module>
import gtk; gdk = gtk.gdk
File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 64, in <module>
_init()
File "/usr/lib64/python2.7/site-packages/gtk-2.0/gtk/__init__.py", line 52, in _init
_gtk.init_check()
RuntimeError: could not open display
Adding "MPLBACKEND=Agg" still outputs the above error message.
Anyone knows how to fix it?
I said that I would close this question. But since the answer might be interesting to some people, I leave it open. Maybe someone can explain to me why my solution worked?
I work remotely. echo $DISPLAY gives nothing. lshw -C display gives two displays. One is Nvidia's.
My problem is actually solved via adding
import matplotlib as mpl
mpl.use('Agg')
before import matplotlib.pyplot as plt.
Related
I have a numerical simulation program that works fine at the institute I'm in, there I have a Win10 box where I installed Python 3.7.3 64-bit. I am trying to run the same program in my laptop with Manjaro and Python 3.8.1 (It was also 3.7.3 at the time I installed it, but rolling release ¬¬). The problem is that in my laptop I am getting the following error when trying to import pyFFTW
Traceback (most recent call last):
File "/home/User/Documents/Program.py", line 22, in <module>
import pyfftw # Pythonic wrapper for FFTW
File "/usr/lib/python3.8/site-packages/pyfftw/__init__.py", line 43, in <module>
from . import interfaces
File "/usr/lib/python3.8/site-packages/pyfftw/interfaces/__init__.py", line 237, in <module>
from . import scipy_fftpack
File "/usr/lib/python3.8/site-packages/pyfftw/interfaces/scipy_fftpack.py", line 65, in <module>
from scipy.fftpack import (dct, idct, dst, idst, diff, tilbert, itilbert,
ImportError: cannot import name '_fftpack' from 'scipy.fftpack' (/usr/lib/python3.8/site-packages/scipy/fftpack/__init__.py)
Process finished with exit code 1
As far as I can tell the problem is arising from the libraries within the pyFFTW package itself, but I have no idea how to fix it. I tried uninstalling and reinstalling both pyFFTW (1.17.4) and scipy (1.4.1) with little success.
I thought that I could install another version on Python in my Manjaro box and simply "match" all the versions of the packages in the Win box, but I'm looking for a less nuclear solution.
Just for completeness sake, MWE:
$ python
>>> import pyfftw
This is fixed in master. A release should be made shortly. You can either wait for that or pull from github.
Edit: Release made that fixes this on Feb 3 2020.
I know other people went through this kind of problem but I still can't fix the problem. I just began to programming.
I use spyder IDE and get the following error when I run the code.
File "C:\Users\kaany\AppData\Roaming\Python\Python36\site-packages\matplotlib\path.py", line 25, in <module>
from . import _path, rcParams
ImportError: cannot import name '_path'
When I remove 'import matplotlib as plt' from my code everything goes fine.
I have numpy 1.13.3 and matplotlib 2.1.0
I'd appreciate if someone provided any solution to this.
Using the code below, a TclError is generated.
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()
When I execute my script in terminal, I get the following:
/Users/<username>/anaconda/lib/python2.7/site-packages/matplotlib/__init__.py:1035: UserWarning: Duplicate key in file "/Users/<username>/.matplotlib/matplotlibrc", line #2
(fname, cnt))
objc[44479]: Class TKApplication is implemented in both /Users/<username>/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[44479]: Class TKMenu is implemented in both /Users/<username>/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[44479]: Class TKContentView is implemented in both /Users/<username>/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
objc[44479]: Class TKWindow is implemented in both /Users/<username>/anaconda/lib/libtk8.5.dylib and /System/Library/Frameworks/Tk.framework/Versions/8.5/Tk. One of the two will be used. Which one is undefined.
2016-02-01 20:45:40.991 python[44479:21064918] setCanCycle: is deprecated. Please use setCollectionBehavior instead
2016-02-01 20:45:41.000 python[44479:21064918] setCanCycle: is deprecated. Please use setCollectionBehavior instead
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/<username>/anaconda/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
return self.func(*args)
File "/Users/<username>/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 283, in resize
self.show()
File "/Users/<username>/anaconda/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 355, in draw
tkagg.blit(self._tkphoto, self.renderer._renderer, colormode=2)
File "/Users/<username>/anaconda/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 30, in blit
id(data), colormode, id(bbox_array))
TclError
What is causing this error? I have tried adding backend: TkAgg to my matplotlibrc file, to no avail.
Please advise
Figured this out:
Instead of using:
matplotlib.use('TkAgg')
use:
matplotlib.use('Qt4Agg')
or any other backend
You can use 'TkAgg' but need to install Tkinter not with conda. The Anaconda packages for pil/pillow and matplotlib seem not to have TK properly included. Install pip with conda and then run pip install pillow matplotlib (Linux)
On windows you can use the packages from gohlke
http://www.lfd.uci.edu/~gohlke/pythonlibs/
install with --force-reinstall pillow matplotlib
then Tkinter TkAgg will work.
In a round about way, I corrupted my scipy/numpy installation on my IntelX64/Windows 7/Python 2.7 computer. I did this by trying to play around with some neural network libraries (lasagne/theano).
To fix this, I completely removed/reinstalled python 2.7.9. After that, I went to http://www.lfd.uci.edu/~gohlke/pythonlibs/ to download and install numpy and scipy with commands:
pip install C:\Users\me\Documents\numpy-1.9.2+mkl-cp27-none-win_amd64.whl
This went well and succeeded. (I can import numpy from python)
pip install C:\Users\me\Documents\scipy-0.15.1-cp27-none-win_amd64.whl
This appeared to go well too. Except the error occurs in the python console:
>>> from scipy import stats
Gives:
Traceback (most recent call last):
File "<stdin>", line1, in <module>
File "C:\Python27\lib\site-packages\scipy\stats\__init__.py", line 338, in <module>
from .stats import *
File "C:\Python27\lib\site-packages\scipy\stats\stats.py", line 184, in <module>
import scipy.special as special
File "C:\Python27\lib\site-packages\scipy\special\__init__.py", line 586, in <module>
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
I read up on the DLLs required and ran the 'dependency walker' (http://www.dependencywalker.com/) on "c:\python27\lib\site-packages\scipy\special_UFUNCS.PYD" and it seems there are a few DLL files not found.
libifcoremd.dll
libiomp5md.dll
libmmd.dll
msvcr90.dll
dcomp.dll
ieshims.dll
and a 6 files that look like 'api-ms-win-....dll'
From my looking around, people have solved this by reinstalling numpy, then scipy. I have tried that and the same thing occurs.
Has anyone else run into this issue and solved it?
I fixed this by a complete removal of everything (python and packages) and then installing everything again.
Just reinstalling the offending packages did not work. Neither did system restore. I will not accept this answer, because removing/installing is a work around to the real problem. I just want to post this to help anyone else in this position.
Simply install 'NumPy-1.9+MKL' from this page, it should work fine.
Acknowledgement: Another post here :)
I am working in Eclipse on Mac. I am using PyDev version 2.6.0.2012062818. I have a program that was running perfectly, but after I updated my Lion OS to Mountain Lion OS I have the following error while running:
Traceback (most recent call last):
File "/Users/Mihails/Projects/memsim/src/memsim/memsim.py", line 7, in <module>
from simulation import SimulationHP
File "/Users/Mihails/Projects/memsim/src/memsim/simulation.py", line 9, in <module>
import matplotlib.pyplot as plt
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/pyplot.py", line 95, in <module>
new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 25, in pylab_setup
globals(),locals(),[backend_name])
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/backends/backend_wxagg.py", line 23, in <module>
import backend_wx # already uses wxversion.ensureMinimal('2.8')
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/backends/backend_wx.py", line 63, in <module>
backend_version = wx.VERSION_STRING
AttributeError: 'module' object has no attribute 'VERSION_STRING'
I don't understand wx module at all. I don't have wx folder in site-packages. I have wxPython. wxPython init.py file :
# The "old" wxPython package
import warnings
warnings.warn(
"The wxPython compatibility package is no longer automatically generated "
"or actively maintained. Please switch to the wx package as soon as possible.",
DeprecationWarning, stacklevel=2)
# We need to be able to import from the wx package, but there is also
# a wxPython.wx module and that would normally be chosen first by
# import statements. So instead we'll have a wxPython._wx module and
# then stuff it into sys.modules with a wxPython.wx alias so old
# programs will still work.
import _wx
import sys
sys.modules['wxPython.wx'] = _wx
wx = _wx
del sys
from wx import __version__
I think when you update, some files have been replaced.
On Ubuntu 11.04 wx.VERSION_STRING, return string value.
Try reinstall WX, or append the 'VERSION_STRING', to WX main file.
I have experienced similar problem just now. I am working on Winodws and MacOSX.
Today when I excute my python program that use matplotlib and wx, it just pops out that message.
I fixed by:
1. I uninstalled the wx through pip;
2. install wxpython;
3. update matplotlib from 1.2.0 to 1.2.1;
I guess the problem is the package wxI installed from pip is not wx at all and it override my wxpython import somehow.
Hope this information could give you some hint on your problem as well as others.