Python unicode、UCS4版本或UCS2版本

Python unicode、UCS4版本或UCS2版本,python,c++,Python,C++,在我的Linux机器上,直接执行python命令,它表明我的python是UCS4构建的 Python 2.7.3 (default, Jan 8 2018, 17:43:28) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import sys &g

在我的Linux机器上,直接执行python命令,它表明我的python是UCS4构建的

Python 2.7.3 (default, Jan  8 2018, 17:43:28)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> if sys.maxunicode > 65535:
...     print 'UCS4 build'
... else:
...     print 'UCS2 build'
...
UCS4 build

但是,在C++程序中使用y/p>调用Python时

Py_Initialize();
PyRun_SimpleString("import sys");
PyRun_SimpleString("if sys.maxunicode > 65535:\n    print 'UCS4 build'\nelse:\n    print 'UCS2 build'");
它打印“UCS2构建”。 由C++调用的Python的其他信息是:

平台:Linux-2.6.32_1-19-0-0-x86_64-with-centos-6.3-Final

('Python','2.7.5(默认,2016年4月13日,14:25:24)

[GCC 4.4.6 20120305(Red Hat 4.4.6-4)])

('Python','*****/venv')

我已经仔细检查了python可执行文件路径。它们来自相同的路径,但python版本和gcc版本不同


有人知道这个奇怪的症状的原因吗?

嗯,我解决了这个问题。使用ldd命令,我发现libpython2.7.so.1.0指向错误的默认路径,而不是以前打印的路径。更正LD_LIBRARY_路径解决了这一困惑….

您是如何安装python的?python virtualenv