打包py文件的内容有 import tztest.common.helper as helper import tztest.common.httputil as httputil,打包出来的exe报错没有common,应该怎么解决
时间: 2024-03-13 21:44:36 浏览: 13
打包出来的 exe 报错没有 common,可能是因为在打包时没有将 common 目录包含进来。可以使用 PyInstaller 的 `--add-data` 参数来将 common 目录打包到应用程序中。
假设 common 目录在应用程序的根目录下,可以使用以下命令进行打包:
```
pyinstaller --add-data "common;common" myscript.py
```
这将会将 common 目录打包到应用程序中,并将其放在应用程序的根目录下。在应用程序运行时,可以使用相对路径 `./common` 来访问该目录下的文件和子目录。
如果 common 目录不在应用程序的根目录下,可以将 `<source_path>` 参数修改为 common 目录的路径,将 `<destination_path>` 参数修改为 common 目录在应用程序中的相对路径。
需要注意的是,使用 `--add-data` 参数打包目录时,目录名后面需要加上分号 `;`,并且目录名不能以斜杠 `/` 或反斜杠 `\` 结尾,否则可能会导致打包失败。
相关问题
打包py文件的内容有 import tztest.common.helper as helper import tztest.common.httputil as httputil,打包出来的exe报错没有httputil,应该怎么解决
如果您使用的是 PyInstaller 打包程序,您可以尝试添加以下参数来解决缺少 httputil 的问题:
```
--hidden-import=tztest.common.httputil
```
此命令会将 httputil 添加到您的打包程序中,以便运行时可以正确地导入它。
另外,如果您使用的是其他的打包工具,可能需要查看其文档或者尝试添加 import httputil 语句来确保 httputil 被正确地打包并导入。