0

我尝试使用优秀的pythran制作一个 python 包。

有了这个文件结构

$ tree ../proj
../proj
├── ccompile.py
├── Makefile
├── proj
│   ├── __init__.py
│   └── lib.py
└── setup.py

我的 pythran 东西在 ccompile.py 中:

$ cat ccompile.py
# pythran export get_fast_results(int[], int[][], (int, int):int dict)
def get_fast_results(mylist_of_int, myarray, dict_with_int_tuples_keys):
    # do stuff update dict_with_int_tuples_keys
    return dict_with_int_tuples_keys

setup.py 调用PythranExtension

$ cat setup.py
from setuptools import setup
from pythran.dist import PythranExtension

setup(name='proj',
      version=0.42,
      packages=['proj'],
      ext_modules=[PythranExtension("ccompile", ["ccompile.py"])],
      # ext_modules=[PythranExtension("proj.ccompile", ["proj/ccompile.py"])],
      zip_safe=False)

一切正常python setup.py install编译 ccompile.py 并安装.so在 egg 文件夹的根目录下::

$ tree
~/venv/lib/python2.7/site-packages/proj-0.42-py2.7-linux-x86_64.egg/
├── ccompile.py
├── ccompile.pyc
├── ccompile.so
├── EGG-INFO
│   └── ...
└── proj
    ├── __init__.py
    ├── __init__.pyc
    ├── lib.py
    └── lib.pyc

问题是我必须手动 mv ccompile.* from site-packages/proj-0.42-py2.7-linux-x86_64.egg/to site-packages/proj-0.42-py2.7-linux-x86_64.egg/proj/才能从 proj 包中导入 pythran 函数::

/tmp$ python -c 'from proj.ccompile import get_fast_results as gfr; print gfr.__doc__'
Supported prototypes:
    - get_fast_results(int[], int[][], (int, int):int dict)
    - get_fast_results(int[], int[][].T, (int, int):int dict)
 make it fast
/tmp$

如果我使用 distutils 扩展中的语法(参见 https://docs.python.org/2/distutils/examples.html#single-extension-module),例如ext_modules=[PythranExtension("proj.ccompile", ["proj/ccompile.py"])], 在 setup.py 中(在 proj 中移动 ccompile)我得到一个错误当pythran编译它时:

$ tree ../proj
../proj
├── Makefile
├── proj
│   ├── ccompile.cpp
│   ├── ccompile.py
│   ├── __init__.py
│   └── lib.py
└── setup.py

和::

$ more setup.py 
from setuptools import setup
from pythran.dist import PythranExtension

setup(...
      ext_modules=[PythranExtension("proj.ccompile", ["proj/ccompile.py"])],
      zip_safe=False)

我得到::

$ python setup.py install
running install
...
running egg_info
...
copying proj/__init__.py -> build/lib.linux-x86_64-2.7/proj
copying proj/ccompile.py -> build/lib.linux-x86_64-2.7/proj
copying proj/lib.py -> build/lib.linux-x86_64-2.7/proj
running build_ext
building 'proj.ccompile' extension
C compiler: x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/proj
compile options: '-DUSE_GMP -DENABLE_PYTHON_MODULE -I~/venv/local/lib/python2.7/site-packages/pythran -I/usr/include/python2.7 -c'
extra options: '-std=c++11 -fno-math-errno -w'
x86_64-linux-gnu-gcc: proj/ccompile.cpp
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
proj/ccompile.cpp:35:25: error: expected ‘{’ before ‘.’ token
 namespace __pythran_proj.ccompile
                         ^
proj/ccompile.cpp:35:25: error: expected unqualified-id before ‘.’ token
proj/ccompile.cpp:610:13: error: expected ‘}’ at end of input
             }
             ^
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
proj/ccompile.cpp:35:25: error: expected ‘{’ before ‘.’ token
 namespace __pythran_proj.ccompile
                         ^
proj/ccompile.cpp:35:25: error: expected unqualified-id before ‘.’ token
proj/ccompile.cpp:610:13: error: expected ‘}’ at end of input
             }
             ^
error: Command "x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -DUSE_GMP -DENABLE_PYTHON_MODULE -I~/venv/local/lib/python2.7/site-packages/pythran -I/usr/include/python2.7 -c proj/ccompile.cpp -o build/temp.linux-x86_64-2.7/proj/ccompile.o -std=c++11
-fno-math-errno -w" failed with exit status 1
$
4

1 回答 1

0

这是一个pythran问题。它已在提交18aefe0e2383中修复。

于 2016-02-10T10:00:05.243 回答