c++ - 导入错误:没有名为 _tkinter 的模块

标签 c++ python visual-studio tkinter importerror

我想在c++代码中使用python,但是出现错误,这是最简单的“hello word”程序。

导入PIL.Image是可以的,但是对于Tkinter,它会输出“ImportError: No module named _tkinter”。 我打印了 sys.path,但没有任何线索。

以下快照显示了详细信息:http://i.minus.com/iWoCUlidmq5M3.jpg

环境: Visual Studio 2010。 Python 2.7.2,32 位。

我是新用户,无法上传图片。 :(

这个问题困扰了我几天,希望有人能给我一些建议,非常感谢。

这是另一个信息:

源代码:

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");
}

错误信息:

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

最佳答案

您的 exe 可能无法访问 C:\Python27\DLLs 中的 DLL(或相同的 PYD)。您应该将此文件夹添加到您的 Windows 路径中。参见 https://stackoverflow.com/a/428217/117092

关于c++ - 导入错误:没有名为 _tkinter 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8470412/

相关文章:

c++ - 以 root ubuntu 身份自动运行我的可执行文件

c++ - -Wstrict-函数定义中的溢出警告

python - 计算 Python/pandas 数组中的连续正值

python - 自定义类对象和 "in"集合运算符

visual-studio - Visual Studio 线条颜色

c++ - Linux C++ GUI编程工具

python - 如何从 Pandas 中的 groupby 对象中选择不同的行

c++ - Visual Studio C++错误读取位置

java - 如何用 if-else 或 try-catch 结构包围 Java 语句?

c++ - C++除法精度不够如何提高结果精度