34
votes

I'm using python 2.7.2 and windows 7. I searched through internet, helps and other sources but i can't find an answer to my problem.

One of my source imports tkinter, and this one imports _tkinter. At this moment it say ImportError DLL load failed:

 Traceback (most recent call last): File "NERO/show_image.py", line 13,
 in <module> import Tkinter 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.
 2012-Jan-04 12:27:21.889374 (M) [python] Finished process 

I searched _tkinter and i found it in Python27/libs as a lib file.

On many sites it says to install tk/tcl or tkinter, but I don't find a separate installation for windows.

Using Windows x86 MSI Installer (2.7) from http://www.python.org/getit/releases/2.7/. In windows 7 64-bit. The python version is 32 bit.

12
Is your computer 64-bit ? You do not need to install anything to make python tkinter work right out of the box when using the official binary installer. Could you post the actual, full traceback? - joaquin
Yes, i have installed windows 7 64. The python version is 32 bit. Traceback (most recent call last): File "NERO/show_image.py", line 13, in <module> import Tkinter 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. 2012-Jan-04 12:27:21.889374 (M) [python] Finished process - paduraru2009
Not sure what your problem is, but this is a tipical error I get when having some conflict with 32/64-bits. Sorry I can not help more. Maybe you should try cleaning your actual setup and reinstalling python for 64-bits afresh. - joaquin
this problem madly occurs to me in 64bit windows with 64 bit python executable :( - Foggy Minded Greenhorn

12 Answers

3
votes

I was getting this error while trying to use matplotlib in a simple application.

Uninstall Python and remove its folder from your C-Drive. Download and Install 64bit python. Follow this to install pip on your machine. http://www1.cmc.edu/pages/faculty/alee/cs40/penv/installFlaskOnWindows.html This was finally what worked for me

28
votes

I had a similar problem importing Tkinter on Windows 7 64-bit - seems that the 64-bit library was still in the libs folder from a previous 64-bit python install.

Uninstalling 64-bit python properly and then repairing with the 32-bit installer fixed the problem for me - you don't need to use 64-bit python.

6
votes

Re-install Python.

If this still doesn't work, there is another simple solution:

  1. Uninstall your current python. Delete Python27 folder entirely from your C: drive.
  2. Download and install the 64-bit version of Python from http://www.python.org/download/.
  3. Next time do not mix your 32-bit application with 64-bit OS whenever a 64-bit choice for the application is available!
3
votes

I had the same issue and was able to uninstall Python 2.7 (using the Windows 7 'uninstall' service) and then reinstall it from here: python-2.7.6.msi

Also, if you're concerned about ensuring 64bit conformance across your python libraries then you may find the following library list site to be a great resource. It has numerous 64bit versions of python libraries.

3
votes

Please don't reinstall Python for this. A simple fix can resolve this issue as below:

  1. Find the matplotlibrc file at Python27\Lib\site-packages\matplotlib\mpl-data\matplotlibrc
  2. Open using notepad
  3. Change the backend parameter to 'backend: Qt5Agg'

And it will be solved. No need to reinstall.

1
votes

SOLVED without reinstalling anything:

1-add these 3 lines to your setup.py :

...
import os
os.environ['TCL_LIBRARY']= r'C:\<your python folder>\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\<your python folder>\tcl\tk8.6'
...
setup(
... 
) 

2- copy tcl86t.dll and tk86t.dll from C:\<your python folder>\DLLs to <your project folder>(where you have batch file, setup.py).

3- add "include_files": ["tcl86t.dll", "tk86t.dll"] to option in your setup.py, something like:

options= { 'build_exe':{'packages':[.....], "include_files": ["tcl86t.dll", "tk86t.dll"]}},

note: if you didn't find tcl86t.dll and tk86t.dll in DLLs folder as mentionned in step 2, then try again to search for it,but using research tab in DLLs folder this time.

1
votes

I had a similar problem. My Python version was 2.7.12 and 64bit and I was using Windows 10, 64bit OS. I tried to import Tkinter and what I got back was

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

I uninstalled Python and removed all traces of it. I then installed Python 2.7.14 (32bit) and this seems to have solved my problem. I don't get this error message any longer.

0
votes

I have a lot of installed python packages on my machine so I did not want to unistall and reinstall the whole python, I did as follow and the problem was solved:

  1. Change your C:\Python27 home folder to another name, for example C:\Python27_old

  2. Install a new Python27 on your computer (32 bit)

  3. Copy tcl and DLLs folder from the fresh installed python to the old one (Before this step make a copy of tcl and DLLs of C:\Python27_old to recover it if you face any problem in the next steps)

C:\Python27\tcl Copy and replace to C:\Python27_old

C:\Python27\DLLs Copy and replace to C:\Python27_old

  1. Delete the C:\Python27
  2. Rename the C:\Python27_old to the C:\Python27

Please pay attention to get a backup form your tcl and DLLs folder to recover it in case you face any further problem.

0
votes

Removing 64 bit python and doing a repair on 32 bit python worked for me. OS: 64 bit Windows Server 2008.

0
votes

I also met this issue, because I use 64-bit python. Maybe python 64-bit doesn't have a good support.

My way is to solve it:

  1. Uninstall python 64-bit.
  2. Install python 32-bit.
  3. Uninstall the 64-bit package. pip uninstall xxx.
  4. Install the 32-bit package. pip install xxx.
0
votes

For Windows 10,

  1. Uninstall all versions of Python
  2. Install Python 3.x (your latest version) with PATH variable
  3. python -mpip install -U matplotlib
  4. Install Python x.x (your other versions) without PATH variable

Done. Try running your scripts again.

0
votes

If Python was installed by OsGeo4W then you should also install the python-tcltk and/or python3-tcltk packages in the OsGeo4W setup tool.