matplotlib 1.3.0 ImportError: DLL load failed: %1

2019-06-20 04:38发布

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.

6条回答
ゆ 、 Hurt°
2楼-- · 2019-06-20 04:40

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.

查看更多
看我几分像从前
3楼-- · 2019-06-20 04:42

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
查看更多
放荡不羁爱自由
4楼-- · 2019-06-20 04:45

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.

查看更多
虎瘦雄心在
5楼-- · 2019-06-20 04:51

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

查看更多
叼着烟拽天下
6楼-- · 2019-06-20 04:59

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.

查看更多
仙女界的扛把子
7楼-- · 2019-06-20 05:04

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.

查看更多
登录 后发表回答