Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib 1.3.0 ImportError: DLL load failed: %1 is not a valid Win32 application

I have 2 pc (laptop and workstation), when I run code for version check I get on laptop:

computer
LAPTOP
OS props
Windows-7-6.1.7601-SP1
python props
('default', 'May 15 2013 22:44:16')
python version
2.7.5
OS bit and OS type
('64bit', 'WindowsPE')
check if system is 32bit or 64bit
('7fffffffffffffff', True)
numpy version
1.7.1
matplotlib version
1.3.0

and on workstation:

computer
WORKSTATION
OS props
Windows-7-6.1.7601-SP1
python props
('default', 'May 15 2013 22:44:16')
python version
2.7.5
OS bit and OS type
('64bit', 'WindowsPE')
check if system is 32bit or 64bit
('7fffffffffffffff', True)
numpy version
1.7.1
matplotlib version
1.3.0

the software is mainly the same except some additional packages. But when I try to run the following code on the workstation computer:

import numpy as np
import matplotlib
# matplotlib.use('QTAgg')
from matplotlib import pyplot as plt

I get the following error:

Traceback (most recent call last):
  File "C:\Users\WORKSTATION\python\src\gibljiv_kontakt_E11_vzmet\preview_and_sort_measurement_data.py", line 9, in <module>
    from matplotlib import pyplot as plt
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 98, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "C:\Python27\lib\site-packages\matplotlib\backends\__init__.py", line 28, in pylab_setup
    globals(),locals(),[backend_name],0)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_tkagg.py", line 8, in <module>
    import Tkinter as Tk, FileDialog
  File "C:\Python27\lib\lib-tk\Tkinter.py", line 38, in <module>
    import FixTk
  File "C:\Python27\lib\lib-tk\FixTk.py", line 65, in <module>
    import _tkinter
ImportError: DLL load failed: %1 is not a valid Win32 application

I would like to know what is wrong and how can this be repaired? The code works (it does not return any error) if I uncomment the line:

matplotlib.use('QTAgg')

but as I use this for showing plots no plots are shown. Any suggestions what is wrong and how to fix this. I would like to add, that like a month ago before I updated python and python's packages on my workstation computer the matplotlib was working without problems, but now I get this error.

like image 655
lskrinjar Avatar asked Sep 19 '13 14:09

lskrinjar


3 Answers

I have solved the problem. Here is the solution procedure:

  1. uninstall python 2.7.5 (64 bit)
  2. restart PC
  3. install python 2.7.5 (64 bit)
  4. restart PC
  5. it should be working

If I choose the repair option when uninstalling, it didn't solve the problem. Thanks for your help @cgohlke.

like image 193
lskrinjar Avatar answered Nov 04 '22 17:11

lskrinjar


I was experiencing something similar just now. But then I realized I had accidentally installed the 64-bit Matplotlib into a 32-bit Python distribution [slaps self on forehead]. I promptly uninstalled Matplotlib and re-installed the 32-bit version and it works beautifully now. :-)

like image 32
midoriha_senpai Avatar answered Nov 04 '22 15:11

midoriha_senpai


Do as follows:

  1. open the command prompt
  2. type the command-> pip uninstall matplotlib and then install again
like image 1
abhijeet nashte Avatar answered Nov 04 '22 17:11

abhijeet nashte