web-dev-qa-db-ja.com

cx_freezeを使用しているときに他のファイルをバンドルするにはどうすればよいですか?

WindowsシステムでPython 2.6およびcx_Freeze 4.1.2を使用しています。setup.pyを作成して実行可能ファイルをビルドしましたが、すべて正常に動作します。

Cx_Freezeが実行されると、すべてがbuildディレクトリに移動します。 buildディレクトリに含める他のファイルがいくつかあります。これどうやってするの?これが私の構造です:

src\
    setup.py
    janitor.py
    README.txt
    CHNAGELOG.txt
    helpers\
        uncompress\
            unRAR.exe
            unzip.exe

これが私のスニペットです。

セットアップ

( name='Janitor',
  version='1.0',
  description='Janitor',
  author='John Doe',
  author_email='[email protected]',
  url='http://www.this-page-intentionally-left-blank.org/',
  data_files = 
      [ ('helpers\uncompress', ['helpers\uncompress\unzip.exe']),
        ('helpers\uncompress', ['helpers\uncompress\unRAR.exe']),
        ('', ['README.txt'])
      ],
  executables =
      [
      Executable\
          (
          'janitor.py', #initScript
          )
      ]
)

これを機能させることはできません。 MANIFEST.inファイルが必要ですか?

52

理解した。

from cx_Freeze import setup,Executable

includefiles = ['README.txt', 'CHANGELOG.txt', 'helpers\uncompress\unRAR.exe', , 'helpers\uncompress\unzip.exe']
includes = []
excludes = ['Tkinter']
packages = ['do','khh']

setup(
    name = 'myapp',
    version = '0.1',
    description = 'A general enhancement utility',
    author = 'lenin',
    author_email = '[email protected]',
    options = {'build_exe': {'includes':includes,'excludes':excludes,'packages':packages,'include_files':includefiles}}, 
    executables = [Executable('janitor.py')]
)

注意:

  • include_filesには、setup.pyスクリプトへの「のみ」相対パスが含まれている必要があります。そうでない場合、ビルドは失敗します。
  • include_filesは、文字列のリスト、つまり相対パスを含むファイルの束にすることができます
    または
  • include_filesは、タプルの前半が絶対パスを持つファイル名で、後半が絶対パスを持つ宛先ファイル名であるタプルのリストにすることができます。

(ドキュメントが不足している場合は、カーミットザカエルに相談してください)

105

より複雑な例があります: cx_freeze-wxPyWiki

すべてのオプションのドキュメントが不足しています: cx_Freeze(Internet Archive)

ただし、cx_Freezeとは異なり、Py2Exeとは異なり、1つのフォルダーに11ファイルのビルド出力が表示されます。

代替手段: パッケージング|マウス対Python

6
Cees Timmerman

添付ファイル(include_files = [-> your attached files <-])setup.pyコードに次の関数を挿入する必要があります。

def find_data_file(filename):
    if getattr(sys, 'frozen', False):
        # The application is frozen
        datadir = os.path.dirname(sys.executable)
    else:
        # The application is not frozen
        # Change this bit to match where you store your data files:
        datadir = os.path.dirname(__file__)

    return os.path.join(datadir, filename)

cx-freeze:データファイルの使用を参照

2
Tiffy

また、ビルド後にファイルをコピーする別のスクリプトを作成できます。 Windowsでアプリを再構築するために使用するものです(「cp」を機能させるには、「win32用のGNUユーティリティ」をインストールする必要があります)。

build.bat:

cd .
del build\*.* /Q
python setup.py build
cp -r icons build/exe.win32-2.7/
cp -r interfaces build/exe.win32-2.7/
cp -r licenses build/exe.win32-2.7/
cp -r locale build/exe.win32-2.7/
pause
1
greene