2014-09-22 85 views
1

在Python中,如果为了使它与Py3与Py2兼容,在编写C++库的Python包装方面是否有区别?为Python 3和Python 2编写包装

或者最初为Py2编写的包装器应该以相同的方式用于Py3,反之亦然?据我了解,Python包装是用C++编写的.cxx文件,然后必须编译。

详细

我问,因为我想安装Aggdraw(包装的C++反谷物几何绘图库),这在Python 2.6-7的作品,但在关于Python 3.4(Windows 7的32位错误结果在命令行中通过“PATH = C:/ Python27 [或Python34]”和“python setup.py install”)。我的希望是为Python 3重振这个惊人的包装模块,并希望这里的其他人在帮忙时会很有趣。

我可以在没有任何问题的情况下在Python 2.6和2.7上编译它,并且我有Visual C++ 2008和2010,所以它不是编译器问题。问题似乎在实际的.cxx包装代码中。

是不是因为Aggdraw包装器只是用Python 2x编写的(大约10年前),所以它没有考虑到Python 3x中可能出现的问题?我最好的猜测是,由于3.4版本中的弃用和更改功能,wrapper未能将某些C++对象/类型转换为Python。

如果有人可以帮助我确定故障部件是什么(请参阅下面的命令行错误代码),我可能愿意通过.cxx包装代码更改必要的部件。如果我们修复了这个问题,那么我会通过链接到“复活”的封装代码来更新这篇文章。

如果Python 2和3包装之间应该没有区别,那么为什么我会在Py3中获取错误代码而不是Py2?

谢谢!

原始包装代码:click here

C:\Users\BIGKIMO\Desktop\aggdraw-master>python setup.py build 
=== freetype not available (edit setup.py to enable) 
running install 
running build 
running build_ext 
building 'aggdraw' extension 
C:\Program Files\Microsoft Visual Studio 10.0\VC\BIN\cl.exe /c /nologo /Ox /MD/
W3 /GS- /DNDEBUG -Iagg2/include -IC:\Python34\include -IC:\Python34\include /Tpa 
ggdraw.cxx /Fobuild\temp.win32-3.4\Release\aggdraw.obj 
aggdraw.cxx 
aggdraw.cxx(124) : error C2440: 'initializing' : cannot convert from 'const char 
[5]' to 'Py_ssize_t' 
     There is no context in which this conversion is possible 
aggdraw.cxx(126) : error C2440: 'initializing' : cannot convert from 'destructor 
' to 'printfunc' 
     This conversion requires a reinterpret_cast, a C-style cast or function- 
style cast 
aggdraw.cxx(128) : error C2440: 'initializing' : cannot convert from 'getattrfun 
c' to 'setattrfunc' 
     This conversion requires a reinterpret_cast, a C-style cast or function- 
style cast 
aggdraw.cxx(142) : error C2440: 'initializing' : cannot convert from 'const char 
[4]' to 'Py_ssize_t' 
     There is no context in which this conversion is possible 
aggdraw.cxx(144) : error C2440: 'initializing' : cannot convert from 'destructor 
' to 'printfunc' 
     This conversion requires a reinterpret_cast, a C-style cast or function- 
style cast 
aggdraw.cxx(161) : error C2440: 'initializing' : cannot convert from 'const char 
[6]' to 'Py_ssize_t' 
     There is no context in which this conversion is possible 
aggdraw.cxx(163) : error C2440: 'initializing' : cannot convert from 'destructor 
' to 'printfunc' 
     This conversion requires a reinterpret_cast, a C-style cast or function- 
style cast 
aggdraw.cxx(187) : error C2440: 'initializing' : cannot convert from 'const char 
[5]' to 'Py_ssize_t' 
     There is no context in which this conversion is possible 
aggdraw.cxx(189) : error C2440: 'initializing' : cannot convert from 'destructor 
' to 'printfunc' 
     This conversion requires a reinterpret_cast, a C-style cast or function- 
style cast 
aggdraw.cxx(191) : error C2440: 'initializing' : cannot convert from 'getattrfun 
c' to 'setattrfunc' 
     This conversion requires a reinterpret_cast, a C-style cast or function- 
style cast 
aggdraw.cxx(207) : error C2440: 'initializing' : cannot convert from 'const char 
[5]' to 'Py_ssize_t' 
     There is no context in which this conversion is possible 
aggdraw.cxx(209) : error C2440: 'initializing' : cannot convert from 'destructor 
' to 'printfunc' 
     This conversion requires a reinterpret_cast, a C-style cast or function- 
style cast 
aggdraw.cxx(211) : error C2440: 'initializing' : cannot convert from 'getattrfun 
c' to 'setattrfunc' 
     This conversion requires a reinterpret_cast, a C-style cast or function- 
style cast 
aggdraw.cxx(488) : error C3861: 'PyString_Check': identifier not found 
aggdraw.cxx(489) : error C3861: 'PyString_AS_STRING': identifier not found 
aggdraw.cxx(575) : error C3861: 'PyString_Check': identifier not found 
aggdraw.cxx(583) : error C3861: 'PyString_AS_STRING': identifier not found 
aggdraw.cxx(584) : error C3861: 'PyString_GET_SIZE': identifier not found 
aggdraw.cxx(730) : error C3861: 'PyInt_Check': identifier not found 
aggdraw.cxx(730) : error C3861: 'PyInt_AS_LONG': identifier not found 
aggdraw.cxx(731) : error C3861: 'PyInt_Check': identifier not found 
aggdraw.cxx(731) : error C3861: 'PyInt_AS_LONG': identifier not found 
aggdraw.cxx(735) : error C3861: 'PyInt_Check': identifier not found 
aggdraw.cxx(735) : error C3861: 'PyInt_AS_LONG': identifier not found 
aggdraw.cxx(736) : error C3861: 'PyInt_Check': identifier not found 
aggdraw.cxx(736) : error C3861: 'PyInt_AS_LONG': identifier not found 
aggdraw.cxx(742) : error C3861: 'PyInt_Check': identifier not found 
aggdraw.cxx(742) : error C3861: 'PyInt_AS_LONG': identifier not found 
aggdraw.cxx(745) : error C3861: 'PyInt_Check': identifier not found 
aggdraw.cxx(745) : error C3861: 'PyInt_AS_LONG': identifier not found 
aggdraw.cxx(759) : error C3861: 'PyInt_Check': identifier not found 
aggdraw.cxx(760) : error C3861: 'PyInt_AsLong': identifier not found 
aggdraw.cxx(763) : error C3861: 'PyString_Check': identifier not found 
aggdraw.cxx(765) : error C3861: 'PyString_AS_STRING': identifier not found 
aggdraw.cxx(788) : error C3861: 'PyString_Check': identifier not found 
aggdraw.cxx(789) : error C3861: 'PyString_AS_STRING': identifier not found 
aggdraw.cxx(1157) : error C3861: 'PyString_FromStringAndSize': identifier not fo 
und 
aggdraw.cxx(1289) : error C3861: 'PyString_FromString': identifier not found 
aggdraw.cxx(1294) : error C3861: 'Py_FindMethod': identifier not found 
aggdraw.cxx(1482) : error C3861: 'Py_FindMethod': identifier not found 
aggdraw.cxx(1890) : error C3861: 'Py_FindMethod': identifier not found 
aggdraw.cxx(1910) : error C3646: 'initaggdraw' : unknown override specifier 
aggdraw.cxx(1911) : error C2091: function returns function 
aggdraw.cxx(1911) : error C4430: missing type specifier - int assumed. Note: C++ 
does not support default-int 
aggdraw.cxx(1912) : error C2039: 'ob_type' : is not a member of '_typeobject' 
     c:\python34\include\object.h(334) : see declaration of '_typeobject' 
aggdraw.cxx(1912) : error C2039: 'ob_type' : is not a member of '_typeobject' 
     c:\python34\include\object.h(334) : see declaration of '_typeobject' 
aggdraw.cxx(1913) : error C2039: 'ob_type' : is not a member of '_typeobject' 
     c:\python34\include\object.h(334) : see declaration of '_typeobject' 
aggdraw.cxx(1913) : error C2039: 'ob_type' : is not a member of '_typeobject' 
     c:\python34\include\object.h(334) : see declaration of '_typeobject' 
aggdraw.cxx(1913) : error C2039: 'ob_type' : is not a member of '_typeobject' 
     c:\python34\include\object.h(334) : see declaration of '_typeobject' 
aggdraw.cxx(1915) : error C3861: 'Py_InitModule': identifier not found 
aggdraw.cxx(1940) : warning C4508: 'DL_EXPORT' : function should return a value; 
'void' return type assumed 

回答

0

在根据以前的答案不断扩大的利益,也有很多的功能,其采取行动在Py2.7字符串,现在请在PY 3个字节或Unicode行动。同样,所提到的int现在可以指long。作为这个导致问题的一个例子,pyString_Check已被pyBytes_Check弃用。阅读以下内容了解更多详情:

https://docs.python.org/3/howto/cporting.html?highlight=pystring