美文网首页
Cython 简明手册

Cython 简明手册

作者: MrHamster | 来源:发表于2017-09-26 23:01 被阅读363次
    • 什么是Cython

    cython 是python的超集
    简单的说:python + c

    • 安装

       pip install Cython -U
      

      一次性安装

      pip install Cython -U--install-option="--no-cython-compile"
      
    • helloworld

      1. file: helloworld.pyx
        def hello_world(name="World"):
              print("Hello %s!" % name)
        
      2. file: setup.py
        from distutils.core import setup
        from Cython.Build import cythonize
        
        setup(
          name = 'Hello world app',
          ext_modules = cythonize("helloworld.pyx"),
          )
        
           3. build
               ```language-bash
               python setup.py build_ext --inplace
               ```
        
               在当前目录下生成```helloworld.so``` (mac/linux, pyd windows)
        
           4. file: main.py
               ```language-python
               from helloworld import hello_world
               hello_world() # out: Hello World
               ```
        
    • How

      • cython 是python的超集,可以被看成是python + c
      • install
        • 安装
        pip install Cython -U
        
        • 一次性安装
        pip install Cython -U--install-option="--no-cython-compile"
        
        • helloworld
          1. file: helloworld.pyx

            def hello_world(name="World"):
                print("Hello %s!" % name)
            
          2. file: setup.py

            from distutils.core import setup
            from Cython.Build import cythonize
            
            setup(
                name = 'Hello world app',
                ext_modules = cythonize("helloworld.pyx"),
            )
            
          3. build

            python setup.py build_ext --inplace
            

            在当前目录下生成helloworld.so (mac/linux, pyd windows)

          4. file: main.py

            from helloworld import hello_world
            hello_world() # out: Hello World
            

    相关文章

      网友评论

          本文标题:Cython 简明手册

          本文链接:https://www.haomeiwen.com/subject/uikxextx.html