#author("2023-07-05T14:58:37+09:00","default:irrp","irrp")
#author("2023-07-05T15:11:44+09:00","default:irrp","irrp")
→Python関連Tips

#contents


----
-exe化することでプログラムの速度が遅くなる可能性があります。exe化されたプログラムは、Pythonインタプリタが持つ高い最適化機能を持っていないため。
-また、exe化されたプログラムは、外部ライブラリやモジュールが含まれているため、起動時間が長くなることもあります。
-スピードを上げるには以下の方法が考えられます。
--不要なモジュールやライブラリを削除する
--アプリケーションの起動時間を短縮するために、py2exeのオプションを調整する
--CythonなどでPythonコードをコンパイルし、exe化する


* 一般 [#leeb00c3]
-[[mypyc/mypyc: Compile type annotated Python to fast C extensions>https://github.com/mypyc/mypyc]] 2023.6
--Mypyc compiles Python modules to C extensions. 
--It uses standard Python type hints to generate fast code. 
--Mypyc uses mypy to perform type checking and type inference.

-[[1. C や C++ による Python の拡張 — Python 3.11.4 ドキュメント>https://docs.python.org/ja/3/extending/extending.html]] 2023.6

-[[The structure of .pyc files | Ned Batchelder>https://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html]] 2008

-[[エクセルをPythonで操作したい!〜xlwings×Pyinstaller〜|分析屋|note>https://note.com/bunsekiya_tech/n/n16a4573b9a76]] 2022.9
--Python環境が無い⼈にまるっとPython+ライブラリ+実⾏コードを渡す「Pyinstaller」。エクセルとPythonを連携させる「xlwings」。
--2つを連携させることでPython×エクセルアプリが誰にでも配布できるようになりました。


*py2exe [#uaf3be70]
-fletなどで作ったプログラムをコンソールを出さないexeにするには
 freeze(
    # console=["flet_main.py"],
    windows=["flet_main.py"],
    options={
        "packages": ["common"],
        "includes": [],
        "excludes": [],
    },
 )
--このとき、ログがstdoutへ出力されると終了時に「Errors in xxx.exe」「See the logfile 'xxxx.log' for details」と言うダイアログが出てしまうが、これを抑制するにはロガーのハンドラを調整してstdout へ出さないようにする
 #こういうことをしていると必ずダイアログが出てしまう。root のレベルは ERRORにしておいた方が無難
     root: Logger = getLogger()
     root.setLevel(DEBUG)
--面倒ならメインモジュールで以下のような呪文を入れると良い模様
 sys.stderr = sys.stdout = os.devnull
--参考:[[python - Py2Exe generate log file - Stack Overflow>https://stackoverflow.com/questions/20549843/py2exe-generate-log-file]] 2013

-[[Selenium用WebDriverManagerを使うとpy2exeでexe化したときだけImportエラーが起きる問題について - Qiita>https://qiita.com/smats-rd/items/aa1334c476c752cf979d]] 2023.6

-[[DeprecationWarning: the `setup.py py2exe` command line interface is deprecated · Issue #150 · py2exe/py2exe · GitHub>https://github.com/py2exe/py2exe/issues/150]] 2022
--[[py2exe/migration.md at master · py2exe/py2exe · GitHub>https://github.com/py2exe/py2exe/blob/master/docs/migration.md]] 2022.9
--[[py2exe/py2exe.freeze.md at master · py2exe/py2exe · GitHub>https://github.com/py2exe/py2exe/blob/master/docs/py2exe.freeze.md]] 

-[[py2exe公式>http://www.py2exe.org/index.cgi/FrontPage]] 
-[[python - Multiple top-level packages discovered in a flat-layout - Stack Overflow>https://stackoverflow.com/questions/72294299/multiple-top-level-packages-discovered-in-a-flat-layout]] 2022
--下記のようなエラーが出る場合、setup() の引数に py_modules=[] を追加すると回避できる場合がある
 error: Multiple top-level packages discovered in a flat-layout: ['xxx'...].
 
 To avoid accidental inclusion of unwanted files or directories,
 setuptools will not proceed with this build.
 
 If you are trying to create a single distribution with multiple packages
 on purpose, you should not rely on automatic discovery.
 Instead, consider the following options:
 
 1. set up custom discovery (`find` directive with `include` or `exclude`)
 2. use a `src-layout`
 3. explicitly set `py_modules` or `packages` with a list of names
 
 To find more information, look for "package discovery" on setuptools docs.


-[[python - py2exe - generate single executable file - Stack Overflow>https://stackoverflow.com/questions/112698/py2exe-generate-single-executable-file]] 2022.10

-[[python py2exeでexe化した後、pyside周りとかでエラーがでた場合の対処のメモ – SAKAIDEN>https://www.sakaiden.com/?p=31200]] 2022.10

-[[pyhon.py→exe化→軽量化→高速化 忘備録(pyinstaller py2exe) | by Yutaka_kun | LSC PSD | Medium>https://medium.com/lsc-psd/pyhon-py-exe%E5%8C%96-%E8%BB%BD%E9%87%8F%E5%8C%96-%E9%AB%98%E9%80%9F%E5%8C%96-%E5%BF%98%E5%82%99%E9%8C%B2-pyinstaller-py2exe-4cd7c5f70c99]] 2020


*PyInstaller [#c0d83c45]
-PyInstallerは作成したexeの起動が遅いという難点が指摘されている

-[[PyInstallerによるPythonスクリプトのexe化とエラー対処方法まとめ - Qiita>https://qiita.com/kunishou/items/b2e8754886107292926d#4.%E5%90%84%E7%A8%AE%E3%82%A8%E3%83%A9%E3%83%BC%E5%AF%BE%E5%87%A6%E6%96%B9%E6%B3%95]] 2023.1
-[[PyInstallerのImportErrorとModuleNotFoundErrorで躓いた話 - Qiita>https://qiita.com/__Lily__/items/b2d55965e417f2997324]] 2023.6

-[[Pythonファイルを超簡単にexeファイル化するGUIソフト - Qiita>https://qiita.com/osorezugoing/items/4ea5249c43c0ba8b89aa]] 2022.6
-[[Pythonスクリプトのexe化>https://qiita.com/ybsh2891/items/afd741153593d2d9e021]] 2021.7


*Codon [#b43a50fd]
-[[Codonを使いPythonで作成したプログラムをC/C++で活用する - Qiita>https://qiita.com/cha84rakanal/items/1aa3963596f8323ca451]] 2023.5

-[[Pythonを高速化する「Codon」コンパイラを使ってみた | DevelopersIO>https://dev.classmethod.jp/articles/python-compiler-codon-trial-use/]] 2023.4

-[[あなたのPythonを100倍高速にする技術 / Codon入門>https://zenn.dev/turing_motors/articles/e23973714c3ecf]] 2023.3
--[[GitHub - exaloop/codon: A high-performance, zero-overhead, extensible Python compiler using LLVM>https://github.com/exaloop/codon]] 2023.3


*Nukita [#d03ac545]
-[[NuitkaでPythonプログラムを配布してみよう | インフォメーション・ディベロプメント>https://www.idnet.co.jp/column/page_245.html]] 2020

-[[PyInstaller より圧倒的に優れている Nuitka の使い方とハマったポイント | つくみ島だより>https://blog.tsukumijima.net/article/python-nuitka-usage/]] 2022



*モジュール化 [#l5b281a0]
-[[Pythonで自分だけのクソライブラリを作る方法>https://zenn.dev/karaage0703/articles/db8c663640c68b]] 2023.5

-[[[Python] 最小限setup.pyでのビルドを通じてsetuptoolsの気持ちを聞いてみた | DevelopersIO>https://dev.classmethod.jp/articles/python-setup-minimum/]] 2023.4

-[[setuptools でサクッと自作モジュールを作る(python) - Qiita>https://qiita.com/kenmaro/items/78006af7d72d18e3121b]] 2020

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS