我尝试使用优秀的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_keyssetup.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::
$ 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问题是,I必须手动mv编译.*从site-packages/proj-0.42-py2.7-linux-x86_64.egg/到site-packages/proj-0.42-py2.7-linux-x86_64.egg/proj/才能从site-packages/proj-0.42-py2.7-linux-x86_64.egg/包导入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扩展( Cf )的语法。( https://docs.python.org/2/distutils/examples.html#single-extension-module )例如,ext_modules=[PythranExtension("proj.ccompile", ["proj/ccompile.py"])], in setup.py (在proj中移动c编译程序)我在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
$发布于 2016-02-10 10:00:05
这是毕斯兰的问题。它已在commit 18aefe0e2383中得到修正。
https://stackoverflow.com/questions/35248795
复制相似问题