<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>「exe化」タグの記事一覧Python Tech</title>
	<atom:link href="https://tech.nkhn37.net/tag/exe%E5%8C%96/feed/" rel="self" type="application/rss+xml" />
	<link>https://tech.nkhn37.net</link>
	<description>Python学習サイト</description>
	<lastBuildDate>Sun, 11 Jan 2026 04:34:09 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>

<image>
	<url>https://tech.nkhn37.net/wp-content/uploads/2021/01/cropped-lion-normal-clear-1-32x32.png</url>
	<title>「exe化」タグの記事一覧Python Tech</title>
	<link>https://tech.nkhn37.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>【Python】PyInstallerでスクリプトをexe化する方法</title>
		<link>https://tech.nkhn37.net/python-pyinstaller-exe/</link>
					<comments>https://tech.nkhn37.net/python-pyinstaller-exe/#respond</comments>
		
		<dc:creator><![CDATA[naoki-hn]]></dc:creator>
		<pubDate>Fri, 30 Jun 2023 20:00:00 +0000</pubDate>
				<category><![CDATA[PyInstaller]]></category>
		<category><![CDATA[--onefile]]></category>
		<category><![CDATA[exe化]]></category>
		<category><![CDATA[spec]]></category>
		<guid isPermaLink="false">https://tech.nkhn37.net/?p=8360</guid>

					<description><![CDATA[Python開発においてPyInstallerを使ってスクリプトをexe化する方法について解説します。 Pythonスクリプトのexe化 Pythonでは、インタープリタで実行する言語のため実行のためPythonをインス [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Python開発において<span class="marker"><strong>PyInstallerを使ってスクリプトをexe化する方法</strong></span>について解説します。</p>



<h2 class="wp-block-heading jinr-heading d--bold">Pythonスクリプトのexe化</h2>



<p class="wp-block-paragraph">Pythonでは、インタープリタで実行する言語のため実行のためPythonをインストールして実行環境を整える必要があります。</p>



<p class="wp-block-paragraph">LinuxやmacOSといった開発者に優しいOSであれば、Python環境はインストール済みのため困ることは少ないですが、Windows環境でPython実行環境となると少し話が変わってきます。</p>



<p class="wp-block-paragraph">特にWindowsのユーザーはデスクトップのアプリケーション(exeファイル)をクリックして実行できることを期待する人が多いのではないでしょうか。Windows向けにPythonアプリケーションを配布する時には<span class="marker"><strong>Pythonスクリプトをexe化して配布できると便利</strong></span>です。</p>



<p class="wp-block-paragraph">この記事では、Pythonスクリプトをexe化する方法のうち、おすすめのツールである<span class="marker"><strong>PyInstaller</strong></span>の使い方を中心に紹介します。</p>



<h3 class="wp-block-heading jinr-heading d--bold">Pythonスクリプトのexe化で人気のあるツール</h3>



<p class="wp-block-paragraph">Pythonでは、スクリプトをexe化する機能は標準ではサポートされていません。しかし、いくつかの人気のあるツールがあります。よくツールとして候補になるツールを対応しているプラットフォームと共に簡単にまとめます。</p>



<figure class="wp-block-table"><table class="has-fixed-layout"><thead><tr><th>ツール名</th><th>対応プラットフォーム</th></tr></thead><tbody><tr><td>PyInstaller</td><td>Windows, Linux, macOS, AIX, Solaris, FreeBSD, OpenBSD</td></tr><tr><td>cx_Freeze</td><td>Windows, Linux, macOS</td></tr><tr><td>py2exe</td><td>Windows</td></tr><tr><td>py2app</td><td>macOS</td></tr></tbody></table></figure>



<p class="wp-block-paragraph"><span class="marker"><strong>PyInstaller</strong></span>は、Pythonスクリプトをexe化するツールの中では最も先進的なプログラムで、対応するプラットフォームも非常に多く、一番おすすめできます。本記事では後ほど使い方を紹介しますが、簡単なコマンドでPythonスクリプトをexe化できます。</p>



<p class="wp-block-paragraph"><span class="marker"><strong>cx_Freeze</strong></span>は、メジャーなWindows, Linux, macOSに対応しています。PyInstallerは独自のビルドフォーマットを提供しますが、cx_Freezeはdistutilsパッケージを拡張しているため、パッケージ配布に関わるsetup.pyスクリプトが使われます。既にパッケージ配布でsetuptools等を使用しているのであればcx_Freezeが使いやすいかもしれません。</p>



<p class="wp-block-paragraph"><span class="marker"><strong>py2exe</strong></span>と<span class="marker"><strong>py2app</strong></span>は異なるツールですが、使用方法や制約等が類似しています。py2exeはWindows向けのビルド、py2appはmacOS向けのビルドといったように単一のプラットフォームしか対応していません。PyInstallerやcx_Freezeよりも制約があり柔軟性に劣ると言われています。</p>



<p class="wp-block-paragraph">上記の通りPyInstallerかcx_Freezeが主な選択肢になるかなと思いますが、いずれのツールを使うにしてもプロジェクトの始めに決めておくことがおすすめです。後々で決めるとうまくビルドできるツールが見つからないというようなことが起こりえます。プロジェクトの開始時に決めておけば開発を進めながらツールにあわせた調整がしやすくなります。</p>



<p class="wp-block-paragraph">以降では、一番おすすめできるPyInstallerを中心に使い方を紹介していきます。</p>



<section class="wp-block-jinr-blocks-iconbox b--jinr-block b--jinr-iconbox"><div class="d--heading-iconbox1 ">
			<div class="a--heading-iconbox-title">
			<div class="a--iconbox-title-icon"><i class="jif jin-ifont-caution" aria-hidden="true"></i></div>
			<div class="a--iconbox-title-text">注意点</div>
			</div>
			<div class="a--jinr-iconbox">
<p class="wp-block-paragraph">PyInstaller は、クラスプラットフォームのビルドはサポートされていないので注意しましょう（cx_Freeze も同様）。特定のプラットフォームで動く実行形式にビルドしたい場合は、同じ環境でビルドする必要があります。近年では Vagrant などの仮想化ツールがあるため、うまく活用するとよいかと思います。</p>
</div>
		</div></section>



<h2 class="wp-block-heading jinr-heading d--bold">PyInstaller</h2>



<p class="wp-block-paragraph">以降では、<span class="marker"><strong>PyInstaller</strong></span>の使い方を紹介していきます。PyInstallerの公式ページは、<a rel="noreferrer noopener" href="https://pyinstaller.org/en/stable/" target="_blank">こちら</a>を参照してください。</p>



<h3 class="wp-block-heading jinr-heading d--bold">PyInstallerのインストール</h3>



<p class="wp-block-paragraph">PyInstallerは、以下のようにpipコマンドを使ってインストールできます。完了すればPyInstallerを使える環境が整います。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">pip install pyinstaller</pre>



<h3 class="wp-block-heading jinr-heading d--bold">基本的な使い方</h3>



<p class="wp-block-paragraph">PyInstallerの基本的な使い方を見ていきましょう。<a rel="noreferrer noopener" href="https://tech.nkhn37.net/pyqt-qtableview-qabstracttablemodel-csveditor/" target="_blank">こちら</a>のページで作成した簡易csvエディタ(csv_editor.py)をexe化して使えるようにしてみたいと思います。簡易csvエディタのPythonコードをcsv_editor.pyとして任意のフォルダに配置し、同フォルダにて以下のコマンドを実行してください。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">pyinstaller csv_editor.py</pre>



<p class="wp-block-paragraph">実行すると以下のような感じで処理が実行され、commpleted successfullyと表示されればビルドが完了です。表示が長いので以下では途中を省略しています。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">1183 INFO: PyInstaller: 5.13.0
1183 INFO: Python: 3.11.2
1196 INFO: Platform: Windows-10-10.0.19045-SP0
1197 INFO: wrote D:\PycharmProjects\python-tech-sample-source\python-libraries\pyinstaller\csv_editor.spec
(...途中省略...)
15503 INFO: Building COLLECT COLLECT-00.toc completed successfully.</pre>



<p class="wp-block-paragraph">出力結果のフォルダ構成は以下のような形となります。こちらも長くなるので一部省略しています。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">>tree /f  
D:.
│  csv_editor.py
│  csv_editor.spec
│
├─build
│  └─csv_editor
│      │  Analysis-00.toc
│      │  base_library.zip
│      │  COLLECT-00.toc
│      │  csv_editor.exe
│      │  csv_editor.exe.manifest
│      │  csv_editor.pkg
│      │  EXE-00.toc
│      │  PKG-00.toc
│      │  PYZ-00.pyz
│      │  PYZ-00.toc
│      │  warn-csv_editor.txt
│      │  xref-csv_editor.html
│      │
│      └─localpycs
│              pyimod01_archive.pyc
│              pyimod02_importers.pyc
│              pyimod03_ctypes.pyc
│              pyimod04_pywin32.pyc
│              struct.pyc
│
└─dist
    └─csv_editor
        │  api-ms-win-core-console-l1-1-0.dll
        │  api-ms-win-core-datetime-l1-1-0.dll
        │  api-ms-win-core-debug-l1-1-0.dll
        │  (...省略...)
        │  base_library.zip
        │  csv_editor.exe
        │  libcrypto-1_1.dll
        │  libssl-1_1.dll
        │  python3.dll
        │  python311.dll
        │  (...省略...)
        │
        └─PyQt6
            │  QtCore.pyd
            │  QtGui.pyd
            │  QtWidgets.pyd
            │  sip.cp311-win_amd64.pyd
            │
            └─Qt6
                ├─bin
                │      MSVCP140.dll
                │      MSVCP140_1.dll
                │      MSVCP140_2.dll
                │      opengl32sw.dll
                │      Qt6Core.dll
                │      (...省略...)
                │
                ├─plugins
                │  ├─generic
                │  │      qtuiotouchplugin.dll
                │  │
                │  ├─iconengines
                │  │      qsvgicon.dll
                │  │
                │  ├─imageformats
                │  │      qgif.dll
                │  │      qicns.dll
                │  │      qico.dll
                │  │      (...省略...)
                │  │
                │  ├─platforms
                │  │      qminimal.dll
                │  │      qoffscreen.dll
                │  │      qwindows.dll
                │  │
                │  └─styles
                │          qwindowsvistastyle.dll
                │
                └─translations
                        qtbase_ar.qm
                        qtbase_bg.qm
                        qtbase_ca.qm
                        (...省略...)</pre>



<p class="wp-block-paragraph">dist/csv_editorというフォルダにはユーザーに配布可能なビルド済みのアプリケーション(csv_editor.exe)が生成されます。このフォルダには、アプリケーションの実行に必要となるDLL等が含まれるため、このフォルダごとユーザーに配布するようにしてください。</p>



<p class="wp-block-paragraph">なお、pyinstallerコマンドにはオプションが用意されているため、以下のようにonefileオプションを指定するとよりコンパクトな配布物を生成することができます。pyinstallerのオプションについては<a rel="noreferrer noopener" href="https://pyinstaller.org/en/stable/usage.html#options" target="_blank">こちら</a>を参照してもらえればと思います。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">pyinstaller --onefile csv_editor.py</pre>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">>tree /f  
D:.
│  csv_editor.py
│  csv_editor.spec
│
├─build
│  └─csv_editor
│      │  Analysis-00.toc
│      │  base_library.zip
│      │  csv_editor.exe.manifest
│      │  csv_editor.pkg
│      │  EXE-00.toc
│      │  PKG-00.toc
│      │  PYZ-00.pyz
│      │  PYZ-00.toc
│      │  warn-csv_editor.txt
│      │  xref-csv_editor.html
│      │
│      └─localpycs
│              pyimod01_archive.pyc
│              pyimod02_importers.pyc
│              pyimod03_ctypes.pyc
│              pyimod04_pywin32.pyc
│              struct.pyc
│
└─dist
        csv_editor.exe</pre>



<p class="wp-block-paragraph">上記のように、onefileオプションを使った場合には、csv_editor.exeというexeファイルのみが生成されます。小規模なプログラムの場合はこちらのオプションを使う方がいいかと思います。</p>



<p class="wp-block-paragraph">実際に、csv_editor.exeを実行すると以下のように簡易csvエディタの画面表示して使うことができました。</p>


<div class="wp-block-image">
<figure class="aligncenter size-full"><img fetchpriority="high" decoding="async" width="642" height="392" src="https://tech.nkhn37.net/wp-content/uploads/2023/07/image.png" alt="簡易csvエディタ" class="wp-image-8366" srcset="https://tech.nkhn37.net/wp-content/uploads/2023/07/image.png 642w, https://tech.nkhn37.net/wp-content/uploads/2023/07/image-300x183.png 300w" sizes="(max-width: 642px) 100vw, 642px" /></figure>
</div>


<h3 class="wp-block-heading jinr-heading d--bold">specファイル</h3>



<p class="wp-block-paragraph">PyInstallerでPythonスクリプトをexe化する場合には、<span class="marker"><strong>specファイル(*.spec)</strong></span>というものができます。</p>



<p class="wp-block-paragraph">specファイルは生成されたPythonモジュールでソースコードからどのようにアプリケーションを構築するかといった内容が出力されています。今回ご紹介した例のcsv_editor.specは以下のような内容になっています。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group=""># -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
    ['csv_editor.py'],
    pathex=[],
    binaries=[],
    datas=[],
    hiddenimports=[],
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='csv_editor',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='csv_editor',
)</pre>



<p class="wp-block-paragraph">このspecファイルには、pyinstallerの実行のために必要な引数が含まれています。一度specファイルが生成されると以下のようなコマンドでビルドを実行することができます。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="raw" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="false" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">pyinstaller csv_editor.spec</pre>



<p class="wp-block-paragraph">specファイルをカスタマイズすることでビルドの挙動を変更することができます。ただ、ほとんどのアプリケーションのビルドは複雑な設定の変更をしなくても基本的な使い方で紹介したようなシンプルなコマンド実行でexe化が実現できるかと思います。</p>



<h2 class="wp-block-heading jinr-heading d--bold">まとめ</h2>



<p class="wp-block-paragraph">Python開発において<span class="marker"><strong>PyInstallerを使ってスクリプトをexe化する方法</strong></span>について解説しました。</p>



<p class="wp-block-paragraph">Pythonでは、スクリプトをexe化する機能は標準ではサポートされていませんが、PyInstaller, cx_Freeze, py2exe, p2appといった人気のツールがあります。本記事では、その中でも対応プラットフォームが多く一番おすすめできるPyInstallerについて使い方を紹介しました。</p>



<p class="wp-block-paragraph">PyInstallerは簡単なコマンドでPythonスクリプトをexe化できます。また、実行時に生成されるspecファイルをカスタマイズすることでビルドを拡張するといったことも可能になります。</p>



<p class="wp-block-paragraph">アプリケーションを配布する場合にはexe化ができると便利な場合があります。PyInstallerは使い方も簡単なので是非試してみてもらえたらなと思います。</p>



<section class="wp-block-jinr-blocks-iconbox b--jinr-block b--jinr-iconbox"><div class="d--simple-iconbox6 ">
			<i class="jif jin-ifont-v2books" aria-hidden="true"></i>
			<div class="a--jinr-iconbox">
<p class="wp-block-paragraph">PyInstaller の公式ドキュメントは<a href="https://pyinstaller.org/en/stable/" target="_blank" rel="noreferrer noopener">こちら</a>を参照してください。</p>
</div>
		</div></section>


<section class="b--jinr-block b--jinr-blogcard d--blogcard-hover-up d--blogcard-style1 d--blogcard-mysite t--round "><div class="a--blogcard-label ef">あわせて読みたい</div><a class="o--blogcard-link t--round" href="https://tech.nkhn37.net/python-tech-summary-page/"><div class="c--blogcard-image"><img decoding="async" class="a--blogcard-img-src" width="128" height="72" src="https://tech.nkhn37.net/wp-content/uploads/2024/08/Python-Tech-Pythonプログラミングガイド_new1-640x360.jpg" alt="【Python Tech】プログラミングガイド" /></div><div class="a--blogcard-title d--bold">【Python Tech】プログラミングガイド</div></a></section>


<p class="wp-block-paragraph"></p>
]]></content:encoded>
					
					<wfw:commentRss>https://tech.nkhn37.net/python-pyinstaller-exe/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Disk: Enhanced  を使用したページ キャッシュ

Served from: tech.nkhn37.net @ 2026-08-13 11:56:19 by W3 Total Cache
-->