本文介绍了带有命名空间包的 pyinstaller的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模块/包结构,我使用命名空间包,我有多个用户创建的库,我保存在单独的存储库中,它们有相当通用的名称,如 db、io、utils 等.为了避免与其他包冲突,我有一个名为 acme 的顶级/命名空间包,即我的包是 acme.io、acme.db、acme.utils 等.为了完成这项工作,所有 acme 文件夹中的 __init__.py 都有以下几行

I have a module/package structure where I am using namespace packages, I have multiple user made libraries which I keep in separate repositories, and they have fairly generic names like db, io, utils and so on. To avoid conflict with other packages I have a top level/namespace package named acme, i.e. my packages are acme.io, acme.db, acme.utils and so on. To make this work, the __init__.py in all the acme folders has the following lines

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

这在运行使用 python 中这些包的软件时效果很好.

This works well when running the software which uses these packages from python.

但后来我尝试使用 pyinstaller 制作一个 EXE.pyinstaller 只找到这些包之一.我试图将 pathex 设置为每个这些库所在的文件夹:

But then I try making an EXE using pyinstaller. pyinstaller finds only one of these packages. I tried to set the pathex to the folder where each of these libraries reside:

a = Analysis(['.\\src\\myPgogram.py'],
         pathex=['C:\\Data\\python\\myProgram', 'C:\\Data\python\\dbrepo', 'C:\\Data\\python\\utilsrepo', 'C:\\Data\\python\\iorepo'],
         hiddenimports=['acme', 'acme.io', 'acme.utils', 'acme.db'],
         hookspath=None,
         runtime_hooks=None)

在文件夹 dbrepo、iorepo 和 utilsrepo 中,有一个名为 acme 的文件夹,其中包含上述 __init__.py 文件和相应的包,即 db、utils 和 io,其中又包含一个 __init__.py 文件.

In the folders dbrepo, iorepo and utilsrepo there is a folder named acme, with the above mentioned __init__.py file and the the corresponding package, i.e. db, utils and io, with a __init__.py file within them again.

但是pyinstaller 只找到acme 和acme.db 包.或者它只找到路径在 pathex 变量中最先列出的包.

But pyinstaller only finds the acme and acme.db package. Or it finds only the package which path is listed first in the pathex variable.

有什么提示可以让我完成这项工作吗?

Any hints to how I can make this work?

谢谢

推荐答案

Pyinstaller 2.1 不支持命名空间包,后续版本会支持.

Namespace packages are not supported in Pyinstaller 2.1, it will be supported in later versions.

我使用的解决方案是,在我的构建脚本中,我将库临时复制到一个通用的 acme 文件夹,然后将此路径添加到 Analysis 中的 pathex.在 *nix 系统上,可以创建符号链接而不是复制存储库.感谢 Pyinstaller 团队的 Hartmut Goebel 解决了这个问题.

The solution I use is that in my build script I copy the libs to a common acme folder, temporarily, and add this path to the pathex in Analysis. On *nix systems one can create symlinks instead of copying the repos. Thanks to Hartmut Goebel of the Pyinstaller team for clearifying the issue.

这篇关于带有命名空间包的 pyinstaller的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-11 20:29