Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【请教】修改c++代码后,如何将代码变成一个python包 #393

Closed
xiaoqing928 opened this issue Nov 8, 2023 · 5 comments
Closed

Comments

@xiaoqing928
Copy link

Issue Type

Build/Install

Modules Involved

SPU compiler

Have you reproduced the bug with SPU HEAD?

Yes

Have you searched existing issues?

Yes

SPU Version

0.5

OS Platform and Distribution

centos7

Python Version

3.8

Compiler Version

No response

Current Behavior?

【求助】
rt,spu提供了python的安装库,安装后即可使用。
本人修改了c++代码,有如下问题:
1、编译后如何变成可供python调用的形式;
2、如何打包为一个python库,像官网教程一样,安装即用。

Standalone code to reproduce the issue

rt

Relevant log output

No response

@anakinxc
Copy link
Contributor

anakinxc commented Nov 8, 2023

Hi @xiaoqing928

运行 python setup.py bdist_wheel

@xiaoqing928
Copy link
Author

Hi@anakinxc
编译后重新安装spu库,在引入时会出现如下问题:

  import spu.psi as psi
  File "/home/app/anaconda3/envs/sf/lib/python3.8/site-packages/spu/__init__.py", line 30, in <module>
    from .api import Io, Runtime, compile, check_cpu_feature
  File "/home/app/anaconda3/envs/sf/lib/python3.8/site-packages/spu/api.py", line 22, in <module>
    from . import libspu  # type: ignore
ImportError: /home/app/anaconda3/envs/sf/lib/python3.8/site-packages/spu/libspu.so: undefined symbol: PyFrame_GetCode

本人操作步骤如下:
1、编译打包
激活python虚拟环境(3.8.17),运行python setup.py bdist_wheel,经过漫长的编译,在dist文件目录下生成了spu-0.5.0.dev20231109-cp38-cp38-manylinux2014_x86_64.whl
2、安装whl文件
使用pip install dist/*.whl --force-reinstall,但是一些包会存在版本的问题,在提示下逐一替换,之后使用pip install dist/*.whl命令安装,显示结果如下:

Installing collected packages: spu
Successfully installed spu-0.5.0.dev20231109

不知道是哪里出来问题,还请帮忙看一下

@anakinxc
Copy link
Contributor

Hi @xiaoqing928

这个说明编译环境用的 python 版本不一致,建议切了 python venv 以后先 bazel clean --expunge 一下

@xiaoqing928
Copy link
Author

好的,我试一下

@xiaoqing928
Copy link
Author

Hi @xiaoqing928

这个说明编译环境用的 python 版本不一致,建议切了 python venv 以后先 bazel clean --expunge 一下

来反馈一下,这个方法确实是可行的!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants