简体   繁体   中英

ImportError: No module named _tkinter

I want to use python in c++ code, but it got an error, it is the simplest "hello word" program.

It is Ok to import PIL.Image, but for Tkinter, it will output "ImportError: No module named _tkinter". I had print the sys.path, but no clue.

Following snapshot show you the detail infomation: http://i.minus.com/iWoCUlidmq5M3.jpg

Env: Visual Studio 2010. Python 2.7.2, 32bit.

I am a new user, so I can't upload the picture. :(

This problem cost me several days, hope someone can give me some suggestions, very thanks.

here is another infomations:

source code :

int _tmain(int argc, _TCHAR* argv[])
{

    Py_Initialize();
    if(!Py_IsInitialized())
        cout<< "init failed"<<endl;
    PyRun_SimpleString ("import sys, struct, zlib ");
    PyRun_SimpleString ("sys.path.append('C:\\Python27\\DLLs')");
    PyRun_SimpleString ("sys.path.append('C:\\Python27\\libs')");
    PyRun_SimpleString ("sys.path.append('C:\\Python27\\Lib\\lib-tk')");
    PyRun_SimpleString ("sys.path.append('C:\\Python27\\Lib\\idlelib')");
    PyRun_SimpleString ("sys.path.append('C:\\Python27\\lib\\plat-win')");
//  PyRun_SimpleString ("print sys.path ");
    PyRun_SimpleString ("import PIL.Image, StringIO");

    PyRun_SimpleString ("import Tkinter");
}

error info:

Traceback (most recent call last):

    File "<string>", line 1, in <module>
    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: No module named _tkinter

It is possible that your exe can't access the DLLs (or PYDs that's the same) in C:\\Python27\\DLLs. You should add this folder to your Windows path. See https://stackoverflow.com/a/428217/117092

i had solved this problem, because i used the debug python_d.dll, it will find the debug version pyd file, so it failed.

then i change the python.dll to python_d.dll, and delete the debug proprocesser in pyconfig, it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM