相关疑难解决方法(0)

使用PyInstaller捆绑数据文件(--onefile)

我正在尝试使用PyInstaller构建一个单文件EXE,它包含一个图像和一个图标.我无法为我的生活而努力--onefile.

如果我这样做--onedir,一切工作都很顺利.当我使用时--onefile,它找不到引用的附加文件(运行编译的EXE时).它找到了DLL和其他一切都很好,只是不是两个图像.

我查看了运行EXE时生成的temp-dir(\Temp\_MEI95642\例如),文件确实在那里.当我将EXE放入该临时目录时,它会找到它们.非常困惑.

这是我添加到.spec文件中的内容

a.datas += [('images/icon.ico', 'D:\\[workspace]\\App\\src\\images\\icon.ico',  'DATA'),
('images/loaderani.gif','D:\\[workspace]\\App\\src\\images\\loaderani.gif','DATA')]     
Run Code Online (Sandbox Code Playgroud)

我应该补充一点,我也试过不把它们放在子文件夹中,没有什么区别.

编辑: 由于PyInstaller更新,标记的较新答案正确.

python pyinstaller

88
推荐指数
7
解决办法
8万
查看次数

VS Code:如何打开 settings.json 文件?

我做了很多次,每次都忘记它在哪里。

文件 -> 首选项 -> 设置。

我明白了:

在此处输入图片说明

我想打开 settings.json (只是可编辑的 txt 文件)。怎么做?

visual-studio-code vscode-settings

9
推荐指数
6
解决办法
4135
查看次数

如何设置相对路径以使用 Python 3 在 PyInstaller 中构建可移植的 .exe?

我到处查找,但对一个相当琐碎的问题没有得到明确的答复。

我在 Windows 7 上的 PyCharm 中有一个 Python 项目,其中包含多个.py文件(通过“”连接from %package_name%.%script_name% import %class_name%)和项目内的一个文件夹,其中包含两个简单的文本文件。我已将 PyInstaller 3.6 安装到项目中venv并将其用作指向.spec文件的外部工具。到目前为止,一切都很好。文件.spec内容如下:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['C:\\Users\\%username%\\PycharmProjects\\%project_folder%\\%project_folder%\\main.py'],
             pathex=['C:\\Users\\%username%\\PycharmProjects\\%project_folder%\\%project_folder%'],
             binaries=[],
             datas=[('txt_files\\file1.txt', '.'), ('txt_files\\file2.txt', '.')],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
a.datas += [
    ("C:\\Users\\%username%\\PycharmProjects\\%project_folder%\\%project_folder%\\txt_files\\file1.txt","txt_files\\file1.txt","DATA"),
    ("C:\\Users\\%username%\\PycharmProjects\\%project_folder%\\%project_folder%\\txt_files\\file2.txt","txt_files\\file2.txt","DATA"),
]
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='%project_name%',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe, …
Run Code Online (Sandbox Code Playgroud)

python exe build pyinstaller

1
推荐指数
1
解决办法
5925
查看次数