嵌入式Python解释器无法导入c模块

问题描述:

我在MinGW-w64项目(https://sourceforge.net/p/mingw-w64/discussion/723798/thread/4a8a9ed5/?limit=25)的gdborig.exe中有嵌入式python解释器问题。嵌入式Python解释器无法导入c模块

导入模块itertools和其他几个失败。但随着分布式独立Python解释器相应的进口做工精细:

>>> import sys 
>>> print sys.version 
2.7.9 (default, Jul 11 2016, 16:32:13) 
[GCC 6.1.0] 
>>> print sys.executable 
C:/AUEMARK/Programme/MinGW64/mingw64/opt/bin/python.exe 
>>> import itertools 
>>> itertools 
<module 'itertools' from 'C:\AUEMARK\Programme\MinGW64\mingw64\opt\libpython2.7\lib-dynload/itertools.pyd'> 

随着嵌入式Python解释器:

(gdb) python import sys 
(gdb) python print sys.version 
2.7.9 (default, Jul 11 2016, 16:32:13) 
[GCC 6.1.0] 
(gdb) python print sys.executable 
C:/AUEMARK/Programme/MinGW64/mingw64/opt/bin/python.exe 
(gdb) python import itertools 
Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
ImportError: No module named itertools 
Error while executing Python code. 

可以:

  • 进口SYS
  • 进口OS

不能:

  • 进口itertools
  • 进口藏品
  • ...

对集合的进口错误消息

(gdb) python import collections 
Traceback (most recent call last): 
    File "<string>", line 1, in <module> 
    File "C:\AUEMARK\Programme\MinW64\mingw64\opt\lib\python2.7/collections.py", line 8, in <module> 
    from _collections import deque, defaultdict 
Importerror: no module named _collections 
Error while executing Python code. 

所以看起来像嵌入式解释不能在C中导入模块。Python模块被导入,并且C模块的Python部分也可以被导入由嵌入式解释器访问。

感谢您的任何提示,我该如何解决这个问题。

Markus

我觉得这个问题存在,因为找不到itertools.pyd文件。 我必须设置环境变量:

PYTHONPATH=C:\msys64\mingw64\lib\python2.7;C:\msys64\mingw64\lib\python2.7\lib-dynload; 

你的情况,请确保您设置:

PYTHONPATH=C:/AUEMARK/Programme/MinGW64/mingw64/opt/lib/python2.7;C:\AUEMARK\Programme\MinW64\mingw64\lib\python2.7\lib-dynload 

我PYTHONHOME变量指向Python解释:

PYTHONHOME=C:\msys64\mingw64\bin\pyhon.exe 

我建立了自己的gdb在msys2下工作:

Microsoft Windows [Version 10.0.16299.19] 
(c) 2017 Microsoft Corporation. All rights reserved. 

C:\Users\tiit>C:\msys64\home\tiit\gdb-7.11-bin\bin\x86_64-linux-gnu-gdb.exe 
GNU gdb (GDB) 7.11.1.20160801-git 
Copyright (C) 2016 Free Software Foundation, Inc. 
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html> 
This is free software: you are free to change and redistribute it. 
There is NO WARRANTY, to the extent permitted by law. Type "show copying" 
and "show warranty" for details. 
This GDB was configured as "--host=x86_64-w64-mingw32 --target=x86_64-linux-gnu". 
Type "show configuration" for configuration details. 
For bug reporting instructions, please see: 
<http://www.gnu.org/software/gdb/bugs/>. 
Find the GDB manual and other documentation resources online at: 
<http://www.gnu.org/software/gdb/documentation/>. 
For help, type "help". 
Type "apropos word" to search for commands related to "word". 
(gdb) 

没有设置正确的环境变量我有同样的麻烦。