ImportError DLL load failed importing _tkinter

匿名 (未验证) 提交于 2019-12-03 09:02:45

问题:

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  import Tkinter File "C:\Python27\lib\lib-tk\Tkinter.py", line 38,  in  import FixTk File "C:\Python27\lib\lib-tk\FixTk.py", line 65,  in  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.

回答1:

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.



回答2:

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:

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.



回答4:

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.



回答5:

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.



回答6:

SOLVED without reinstalling anything:

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

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

2- copy tcl86t.dll and tk86t.dll from C:\\DLLs to (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.



回答7:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!