Python 3.x pyinstaller:从导入的模块添加缺少的数据

Python 3.x pyinstaller:从导入的模块添加缺少的数据,python-3.x,pyinstaller,Python 3.x,Pyinstaller,我正在尝试用pyinstaller打包PyQt应用程序。我的简化目录树如下所示: maindir/ ├── build/ ├── dev_tool.py ├── dev_tool.spec ├── dist │   └── dev_tool/ └── ... 当我从dist/文件夹运行可执行文件dev\u tool时 $。/dist/dev_工具/dev_工具 我得到一个错误,它无法找到../dev\u tool/langdetect/utils/messages.properties。但是,

我正在尝试用pyinstaller打包PyQt应用程序。我的简化目录树如下所示:

maindir/
├── build/
├── dev_tool.py
├── dev_tool.spec
├── dist
│   └── dev_tool/
└── ...
当我从
dist/
文件夹运行可执行文件
dev\u tool

$。/dist/dev_工具/dev_工具

我得到一个错误,它无法找到
../dev\u tool/langdetect/utils/messages.properties
。但是,当我手动添加
langdetect
文件夹时(在
pip安装langdetect
-ed之后,我只是从我的python站点包复制了该文件夹),它就可以工作了。现在我了解了如何通过在
.spec
-文件中定义文件来添加文件,但是,如果我尝试将
langdetect/
文件夹从Python站点包复制到
dist/dev\u tool/
文件夹中,它仍然不起作用

我在我的
dev_tool.spec
文件中添加了以下几行

a = Analysis (...
datas=[('path_to.../site-packages/langdetect', 'dist/dev_tool/langdetect')]
...)
这难道不应该将站点包langdetect文件夹中的所有内容复制到
dist/dev\u tool/langdetect/


非常感谢您的帮助。

您可以使用中的


然后用
dev_tool.spec
作为参数运行
pyinstaller
,将把
langdetect
中所有必要的数据文件放入
dist\dev_tool\langdetect
中,这样
dev_tool
就可以在运行时找到它们。

您可以使用

然后用
dev_tool.spec
作为参数运行
pyinstaller
,将
langdetect
中所有必要的数据文件放入
dist\dev_tool\langdetect
中,这样
dev_tool
可以在运行时找到它们。

这对我来说很有效:

a = Analysis(
    # your other stuff here...
    datas=[
        ('langdetect/utils', 'csg_fileutil_libs/langdetect/utils'),  # for messages.properties file
        ('langdetect/profiles', 'csg_fileutil_libs/langdetect/profiles'),
          ]
    # the rest of your analysis spec...
    )
这对我很有用:

a = Analysis(
    # your other stuff here...
    datas=[
        ('langdetect/utils', 'csg_fileutil_libs/langdetect/utils'),  # for messages.properties file
        ('langdetect/profiles', 'csg_fileutil_libs/langdetect/profiles'),
          ]
    # the rest of your analysis spec...
    )