首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >嵌入式python解释器无法导入c++模块。

嵌入式python解释器无法导入c++模块。
EN

Stack Overflow用户
提问于 2016-08-18 15:56:43
回答 1查看 979关注 0票数 2

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

模块迭代工具和其他一些工具的导入失败。但是,使用分布式独立python解释器,相应的导入可以正常工作:

代码语言:javascript
复制
>>> 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解释器:

代码语言:javascript
复制
(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.

Can:

  • 导入sys
  • 导入操作系统

不能:

  • 导入迭代工具
  • 进口托收
  • ..。

用于导入集合的错误消息

代码语言:javascript
复制
(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部分也可以由嵌入式解释器访问。

谢谢你的提示,我怎么能解决这个问题。

马库斯

EN

回答 1

Stack Overflow用户

发布于 2017-10-31 12:37:44

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

代码语言:javascript
复制
PYTHONPATH=C:\msys64\mingw64\lib\python2.7;C:\msys64\mingw64\lib\python2.7\lib-dynload;

在您的情况下,请确保设置:

代码语言:javascript
复制
PYTHONPATH=C:/AUEMARK/Programme/MinGW64/mingw64/opt/lib/python2.7;C:\AUEMARK\Programme\MinW64\mingw64\lib\python2.7\lib-dynload

我的PYTHONHOME变量指向python解释器:

代码语言:javascript
复制
PYTHONHOME=C:\msys64\mingw64\bin\pyhon.exe

我在msys2下构建了自己的gdb,它运行如下:

代码语言:javascript
复制
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)

在没有设置正确的环境变量的情况下,我遇到了同样的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39022702

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档