凌的博客

您现在的位置是: 首页 > 学无止境 > python > 

python

python安装Cython打包.pyd(windows),.so(Linux) - 保护源码

2020-05-05 python 2191

pip install cython


或者去官网下载安装

安装 C++ 编译器

(如果不安装 C++ 编译器,就进行 编译命令,会发生报错,比如 unable to find vcvarsall.bat)

minGW 不支持 3.5  所以 安装 VS(也比较省事,不需要为 python 添加配置文件之类的麻烦事)

具体所需要的 VS 版本 要查看 Lib\distutils\_msvccompiler.py 文件里面的代码片段进行判断

如:

if version >= 14 and version > best_version:

表示需要 VS14 及以上版本,也就是 VS 2015 及其以上版本. python3.5 就是需要 VS 2015 以上

(相对的如果是9就是9以上即可这时VS10什么都是可以的)

VS 2015 社区版 下载安装器 链接: https://pan.baidu.com/s/1051Z8SoE7QJK2kMV0Y3CQw 提取码: tavx

安装时选择自定义安装,勾选上功能

Common Tools for Visual C++ 2015

Python Tools for Visual Studio(March 2016)

Microsoft Web Developer Tools 此项不是必要安装的,但是由于这是软件默认勾选的,所以也装了

# file hello.pyx
def say_hello(name):
    print("hello , %s" % name)
# pip install Cython
# cython --version
# py setup.py build_ext --inplace
# py setup.py build_ext --inplace
# file: setup.py
from distutils.core import setup
from Cython.Build import cythonize

setup(
    name='Hello world app',
    ext_modules=cythonize("hello.pyx")
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext

ext_modules = [Extension("hello", ["hello.pyx"])]

setup(
    name='Hello world app',
    cmdclass={'build_ext': build_ext},
    ext_modules=ext_modules
)


注意:走了好多弯路,总提示组件不存在,找了好多才找到需要c++库,并且需要安装visual studio 安装包竟然需要6G以上

文章评论

0条评论