python_note
  • Introduction
  • My Python
    • Anaconda
    • argparse
    • datetime
    • json
    • logging
    • numpy
    • open
    • openCC
    • pandas & csv
    • Socket & SocketServer
    • re
    • yaml
    • smtp
    • 物件操作
    • unittest
    • 線程
    • prettytable
    • IO
    • pycurl
    • sys
    • pickle
    • auto-python-to-exe
    • cython
    • nuitka
  • Crawler
    • Urllib & Requests
      • User-agent
      • Percent-Encoding
      • mail code
    • Selenium
    • TCP & UDP
    • 控制字符(control character)
  • Web Development
    • Flask
      • RESTful api
      • Template
      • blueprint
    • Django
      • 環境佈署(windows)
    • 檢查Port
    • Apache
    • 使用者行為
    • jQuery
    • 壓力測試
    • DataTable
    • Bootstrap
    • CSS
    • JavaScript
    • Chart.js
  • Deep Learning
    • Keras 設定
    • RNN
    • LSTM
  • Test
    • T-Test
  • 資料結構
    • Hash
    • 時間複雜度
  • NLP
    • N-gram
    • CKIP
    • 中文轉數字
    • CRF
    • Mutual Information
    • 模糊比對
  • Linebot
    • Heroku
    • 圖文選單
    • channel
  • Linux
    • 常用指令
    • shell script
    • sshfs
    • ssh
    • nodejs & npm
    • debug
  • GCP
    • app engine
    • ssh(gcp)
    • gsutil
    • brabrabra
    • Load Balancer
    • k8s
  • Database
    • mysql
    • elasticsearch
      • Query
      • Backup and Restore
      • elasticdump
      • es2csv
      • ELK
    • mongodb
      • install
      • authentication
      • pymongo
    • sql server
  • go
    • Swarm
  • Docker
    • Kitematic
    • Dockerfile
    • Swarm
  • Git
  • 其他
    • USB軟體保護
    • Windows效能監視器
  • Blockchain
Powered by GitBook
On this page
  • 安裝
  • 進行封裝
  • 其他用法
  • issue
  • cannot run rc.exe
  • takes no keyword arguments

Was this helpful?

  1. My Python

cython

安裝

windows 10 + cython

套件安裝

pip install cython

進行封裝

新增一個setup.py撰寫指令

from distutils.core import setup
from Cython.Build import cythonize

py_list = [
    "./app.py",
    "./db.py",
]

setup(
    name='Anything you want',
    ext_modules=cythonize(
        py_list,
        language_level=3,
        build_dir="build",  # 存放.c
        compiler_directives={'always_allow_keywords': True}
    ),
)

再用cmd執行

python setup.py build_ext --inplace

作業系統不同輸出結果似乎也不同

在windows上會輸出.pyd,在linux上會有.so

主要都是把py編譯成二進制,比較安全且不容易反編譯

使用時一樣可以直接import

參考連結:

其他用法

包含可以製作自己的lib供他人使用,pip install xxx000,都是基於setup模組

issue

cannot run rc.exe

找檔案複製貼上即可

takes no keyword arguments

有些function雖然可以成功封裝,但是使用時會產生錯參數數量的錯誤,需在setup.py添加參數:

always_allow_keywords=True
Previousauto-python-to-exeNextnuitka

Last updated 5 years ago

Was this helpful?

https://blog.csdn.net/weixin_43684951/article/details/98055602
https://jennaweng0621.pixnet.net/blog/post/404275031-%5Bpython%5D-%E5%B0%87py%E6%96%87%E4%BB%B6%E6%AA%94%E8%BD%89%E6%88%90pyd%E6%96%87%E4%BB%B6%E6%AA%94%28dll%29
https://www.cnblogs.com/ldy-miss/p/11649318.html
https://stackoverflow.com/questions/34344934/specify-cython-output-file
http://o1o1o1o1o.blogspot.com/2017/02/python-setuppy.html
https://www.cnblogs.com/cposture/p/9029023.html#_lab2_2_2
https://moonlet.gitbooks.io/cython-document-zh_cn/content/ch1-basic_tutorial.html
https://zhuanlan.zhihu.com/p/65906685
https://zhuanlan.zhihu.com/p/66206425
https://stackoverflow.com/questions/14372706/visual-studio-cant-build-due-to-rc-exe
https://blog.csdn.net/qq_42849269/article/details/83275998
https://segmentfault.com/a/1190000015461497