6

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.

lskrinjar
  • 5,483
  • 7
  • 29
  • 54
  • @cgohlke thanks for the advice. I searched for two files in the suggested directory but none can be found. How can I ckeck/see if there are files in the windows DLL searsh PATH elswhere? I hope there is a solution to this problem. – lskrinjar Sep 21 '13 at 12:19
  • @cgohlke I have looked the system variables at: mycoputer/properties/addvanced system settings/more(or additional-I don't have english windows)/environment variables/system variables/path - is this what you suggested? What do I have to look for? – lskrinjar Sep 21 '13 at 14:06
  • I have found the files (TCL85.DLL and TK85.DLL) on path c:\Python27\DLLs\ – lskrinjar Sep 21 '13 at 14:38
  • See also: [ImportError: DLL load failed: %1 is not a valid Win32 application for Python Matplotlib](https://stackoverflow.com/questions/26638621/importerror-dll-load-failed-1-is-not-a-valid-win32-application-for-python-mat/26640324#) – martieva Jul 01 '18 at 22:29
  • More details: [\[SO\]: Python Ctypes - loading dll throws OSError: \[WinError 193\] %1 is not a valid Win32 application (@CristiFati's answer)](https://stackoverflow.com/a/57297745/4788546). – CristiFati Dec 20 '22 at 22:36

7 Answers7

5

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.

k_ssb
  • 6,024
  • 23
  • 47
lskrinjar
  • 5,483
  • 7
  • 29
  • 54
  • no, uninstall once, reinstall once. Restart twice. This worked for me. If you have multiple version of python (e.g., 2.7.1, and 2.7.15) uninstall them all, restart, reinstall the one you want, restart. Should work then. – hft Aug 17 '18 at 23:14
1

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. :-)

midoriha_senpai
  • 177
  • 1
  • 16
1

Do as follows:

  1. open the command prompt
  2. type the command-> pip uninstall matplotlib and then install again
Fatema Tuz Zuhora
  • 3,088
  • 1
  • 21
  • 33
0

After I installed Anaconda I uninstalled other version of python which I installed before and deleted the old libraries from C:\Python directory. Now it is working.

0

In case you want to avoid the reinstallation of Python, please use the following code to change the backend to QT4. Remember to install PySide and PyQt4 packages before adding this to your code.

import matplotlib
matplotlib.use('QT4Agg')
import matplotlib.pyplot as plt
AbhiGupta
  • 474
  • 1
  • 6
  • 14
0

I installed it with Anaconda3 in windows 10. I used powershell in admin mode.

then I just

pip uninstall matplotlib

and then,

pip install matplotlib

It worked in my case.

clemens
  • 16,716
  • 11
  • 50
  • 65
Jaeyoon Jeong
  • 569
  • 4
  • 8
0

Kindly check your interpreter. The error means you are using incorrect bit of software. It can be your interpreter is for 32-bit but you're using matplotlib and python of 64-bit, or any among these that does not match. Just solved mine. Add new interpreter of 64-bit version.

  • this answer is a repeat of the other answers already present and adds nothing new IMO. – rene Jun 02 '19 at 15:23