首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用PythranExtension在python包中导入pythran模块

用PythranExtension在python包中导入pythran模块
EN

Stack Overflow用户
提问于 2016-02-07 01:46:20
回答 1查看 231关注 0票数 0

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

用这个文件结构

代码语言:javascript
复制
$ tree ../proj
../proj
├── ccompile.py
├── Makefile
├── proj
│   ├── __init__.py
│   └── lib.py
└── setup.py

我的pythran的东西在ccompile.py里:

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

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

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

代码语言:javascript
复制
/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编译它时得到了一个错误:

代码语言:javascript
复制
$ tree ../proj
../proj
├── Makefile
├── proj
│   ├── ccompile.cpp
│   ├── ccompile.py
│   ├── __init__.py
│   └── lib.py
└── setup.py

包括:

代码语言:javascript
复制
$ more setup.py 
from setuptools import setup
from pythran.dist import PythranExtension

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

我得到:

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

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-10 10:00:05

这是毕斯兰的问题。它已在commit 18aefe0e2383中得到修正。

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

https://stackoverflow.com/questions/35248795

复制
相关文章

相似问题

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