首页 > 其他分享 >这个错误可能是由于 `PyInstaller` 在打包过程中没有正确地包含 `imp` 模块。以下是一些可能的解决方案: 1. **手动添加隐藏导入**:在运行 `PyInstaller` 时,使用

这个错误可能是由于 `PyInstaller` 在打包过程中没有正确地包含 `imp` 模块。以下是一些可能的解决方案: 1. **手动添加隐藏导入**:在运行 `PyInstaller` 时,使用

时间:2024-01-17 13:35:53浏览次数:35  
标签:pyinstaller script python imp 导入 https PyInstaller com

`PyInstaller` 默认使用运行它的 Python 解释器来打包您的脚本¹。如果您想要指定一个不同的 Python 解释器,您可以使用完整路径来运行 `PyInstaller`³。例如,如果您想要使用位于 `/path/to/python3` 的 Python 3 解释器,您可以使用以下命令:

```bash

/path/to/python3 -m PyInstaller your_script.py

```

这样,`PyInstaller` 就会使用您指定的 Python 解释器来打包您的脚本³。


另外,如果您想要指定特定版本的 Python 和库,您可以使用虚拟环境²。例如,如果您使用 `conda`,您可以按照以下步骤操作:

1. 创建虚拟环境并指定 Python 版本:

```bash

conda create --name my_env_name python=3.6

```

2. 激活虚拟环境:

```bash

conda activate my_env_name

```

3. 在虚拟环境中安装您需要的库版本和 `PyInstaller`:

```bash

pip install pandas==0.23

pip install beautifulsoup4==4.9.1

pip install pyinstaller

```

4. 在虚拟环境中运行 `PyInstaller` 来打包您的脚本:

```bash

python -m PyInstaller your_script.py

```

这样,`PyInstaller` 就会使用虚拟环境中的 Python 解释器和库来打包您的脚本²。


希望这些信息对您有所帮助!如果您有其他问题,欢迎随时向我提问。¹²³


源: 与必应的对话, 2024/1/17

(1) Using PyInstaller — PyInstaller 6.3.0 documentation. https://pyinstaller.org/en/stable/usage.html.

(2) How to change python version for use with pyinstaller. https://stackoverflow.com/questions/43443088/how-to-change-python-version-for-use-with-pyinstaller.

(3) How to specify Python version and library versions for PyInstaller executable - Stack Overflow. https://stackoverflow.com/questions/63494904/how-to-specify-python-version-and-library-versions-for-pyinstaller-executable.

(4) Python打包工具 Pyinstaller使用教程(将.py以及Python解释器和相关库打包可执行文件) - CSDN博客. https://blog.csdn.net/Dontla/article/details/131474870.

(5) undefined. https://github.com/pyinstaller/pyinstaller/archive/develop.zip.



这个错误可能是由于 `PyInstaller` 在打包过程中没有正确地包含 `imp` 模块。以下是一些可能的解决方案:


1. **手动添加隐藏导入**:在运行 `PyInstaller` 时,使用 `--hidden-import` 参数手动添加 `imp` 模块³。例如,您可以尝试运行以下命令来打包脚本:

```bash

pyinstaller --hidden-import=imp your_script.py

```

这样可以手动将 `imp` 模块添加到 `PyInstaller` 的导入列表中,以确保它能够正确处理脚本中对该模块的引用³。


2. **修改 .spec 文件**:在运行 `PyInstaller` 后,会生成一个 `.spec` 文件。在该文件中,您会找到一个选项,如下:

```python

hiddenimports= []

```

您可以将其修改为:

```python

hiddenimports= ["imp"]

```

然后,像这样运行 `PyInstaller`:

```bash

pyinstaller app.spec

```

如果您的程序不仅仅是一个 "Hello World",可能还需要添加更多的模块。只需将它们全部添加到 `hiddenimports` 列表中,直到不再出现 `ModuleNotFoundError`¹²。


3. **重新安装 PyInstaller**:有时,重新安装 `PyInstaller` 也可以解决问题²。例如,您可以尝试卸载当前的 `PyInstaller`,然后重新安装:

```bash

pip uninstall pyinstaller

pip install pyinstaller

```

请注意,如果您修改了 `.spec` 文件,不要再运行 `pyinstaller` 对 `.py` 文件进行操作,因为这将创建一个新的 `.spec` 文件并覆盖它,忽略之前的修改²。


希望这些信息对您有所帮助!如果问题仍然存在,或者您有其他问题,欢迎随时向我提问。¹²³


源: 与必应的对话, 2024/1/17

(1) Python Pyinstaller “Failed to execute script pyi_rth_pkgres” 和缺少的包 - 极客教程. https://geek-docs.com/python/python-ask-answer/567_python_pyinstaller_failed_to_execute_script_pyi_rth_pkgres_and_missing_packages.html.

(2) python - Pyinstaller "Failed to execute script pyi_rth_pkgres" and missing packages - Stack Overflow. https://stackoverflow.com/questions/37815371/pyinstaller-failed-to-execute-script-pyi-rth-pkgres-and-missing-packages.

(3) Pyinstaller Failed to execute script pyi_rth_pkgres. https://stackoverflow.com/questions/62926929/pyinstaller-failed-to-execute-script-pyi-rth-pkgres.

(4) python - Pyinstaller 'failed to execute' script - Stack Overflow. https://stackoverflow.com/questions/62017437/pyinstaller-failed-to-execute-script.

(5) 亲测有效!python:Failed to execute script ‘pyi_rth_win32comgenpy‘ due to unhandled exception! - CSDN博客. https://blog.csdn.net/abcdefg5_555/article/details/128636706.

(6) undefined. https://github.com/pyinstaller/pyinstaller/archive/develop.zip.

(7) undefined. https://pypi.tuna.tsinghua.edu.cn/simple.


如果您需要在 `PyInstaller` 中隐藏导入多个库,可以使用 `--hidden-import` 参数,并为每个需要隐藏的库重复该参数¹。例如,如果您需要隐藏 `pandas` 和 `pyautogui` 这两个库,可以使用以下命令:

```bash

pyinstaller main.py --hidden-import pandas --hidden-import pyautogui

```

这样,`PyInstaller` 就会将 `pandas` 和 `pyautogui` 都添加到隐藏导入列表中¹。


另外,您也可以在 `.spec` 文件中添加多个隐藏导入。在 `.spec` 文件中,您会找到一个选项:

```python

hiddenimports= []

```

您可以将其修改为:

```python

hiddenimports= ["pandas", "pyautogui"]

```

然后,像这样运行 `PyInstaller`:

```bash

pyinstaller app.spec

```

这样,`PyInstaller` 就会将 `pandas` 和 `pyautogui` 都添加到隐藏导入列表中²。


希望这些信息对您有所帮助!如果您有其他问题,欢迎随时向我提问。¹²


源: 与必应的对话, 2024/1/17

(1) python - Multiple Hidden Imports in Pyinstaller - Stack Overflow. https://stackoverflow.com/questions/67661226/multiple-hidden-imports-in-pyinstaller.

(2) Using PyInstaller — PyInstaller 6.3.0 documentation. https://pyinstaller.org/en/stable/usage.html.

(3) python - How to properly create a pyinstaller hook, or maybe hidden import? - Stack Overflow. https://stackoverflow.com/questions/27947639/how-to-properly-create-a-pyinstaller-hook-or-maybe-hidden-import.

(4) [转]pyinstaller打包讲解 -F,-D,-w,-c,以及--hidden-import的用法 - CSDN博客. https://blog.csdn.net/qq_39621009/article/details/122308590.

(5) Hidden imports from a top-level module - Google Groups. https://groups.google.com/g/pyinstaller/c/FnwpTM9hyRI.

标签:pyinstaller,script,python,imp,导入,https,PyInstaller,com
From: https://blog.51cto.com/u_16055028/9291353

相关文章

  • 文件上传超出了tomcat的限制大小:org.apache.tomcat.util.http.fileupload.impl.FileSi
    报错的原因springBoot项目自带的tomcat对上传的文件大小有默认的限制,SpringBoot官方文档中展示:每个文件的配置最大为1Mb,单次请求的文件的总数不能大于10Mb。解决方法SpringBoot2.0版本在【application】配置文件中加入如下代码:#maxFileSize单个数据大小spring.servlet......
  • uniGUI学习之UniImage1三种导入图片方式
    uniGUI学习之UniImage1三种导入图片方式参考自带DEMO,C:\ProgramFiles(x86)\FMSoft\Framework\uniGUI\Demos\Desktop\UniImage1]  FromPicture,直接加载到Picture属性 2]从磁盘文件中加载UniImage3.Picture.LoadFromFile('0.jpg');0.jpg和应用程序.exe位置要在一......
  • 初中英语优秀范文100篇-060It's Important to Read Books-读书很重要
    PDF格式公众号回复关键字:SHCZFW060记忆树1Frommypointofview,asaGradeNinestudent,readingbooksisveryimportant.翻译从我的观点来看,作为一名九年级学生,阅读书籍非常重要。简化记忆重要句子结构"Frommypointofview"是一个介词短语,作为整个句子的状......
  • EasyPOI导入数据为空
     问题:从数据内导出的数据再次导入数据库,部分或者全部数据都为空。明明全部字段都对应。 原因:在表中有表头:用户表名、字段、内容。忘记上面还有个表头,所以应该从2开始。(第一行对应的数据库字段的话就没问题) 解决:将表头与数据库字......
  • 使用shell脚本将doDBA采集到的日志会话信息导入到MySQL数据库
    【背景说明】使用doDBA工具监控的会话信息导入到MySQL数据库的表中【环境说明】doDBA工具采集会话信息(之前有脚本说明)【脚本说明】处理dodba日志信息将日志的innodb日志信息去除审计日志的名称要改为原来的dodba.log名称cd/data/backup/doDBA/log/cpdodba_20231226_09......
  • Import yaml ModuleNotFoundError No module named 'yaml
    ImportyamlModuleNotFoundError:Nomodulenamed'yaml'Python错误信息:ModuleNotFoundError异常,具体错误是找不到名为yaml的模块。这意味着在执行导入语句importyaml时,Python解释器没有在你的环境里找到这个模块。yaml是一个用于处理YAML数据格式的库,如果你在代码中需要解......
  • Oracle数据导入,导出方式
    什么是数据库导入导出?Oracle数据库的导入/导出,就是我们通常所说的Oracle数据的还原/备份。数据库导入:把.dmp格式文件从本地导入到数据库服务器中。数据库导出:把数据库服务器中的数据,导出到本地生成.dmp格式文件。Oracle数据导入导出方式与优缺点传统方式:exp(导出)和im......
  • `PyInstaller`是一个将Python程序打包成独立可执行文件的工具,它提供了许多参数来配置
    `--distpath`是`PyInstaller`的一个参数,它用于指定生成的可执行文件(及其依赖)的存放路径¹²⁴。默认情况下,这些文件会被放置在当前目录下的`dist`文件夹中²。例如,如果你想让`dist`文件夹中的内容在桌面上生成,你可以这样使用`--distpath`参数⁴:```bashpyinstaller--on......
  • gimp 如何 替换背景, 使用模糊工具。
    网上的截图:        这个模糊工具可以自由的选择选中的大小。  ......
  • Lift, Splat, Shoot_ Encoding Images From Arbitrary Camera Rigs by Implicitly Unp
    zotero-key:HP5VFNPQzt-attachments:-"413"title:"Lift,Splat,Shoot:EncodingImagesFromArbitraryCameraRigsbyImplicitlyUnprojectingto3D"citekey:philionLiftSplatShoot2020Lift,Splat,Shoot:EncodingImagesFromArbitr......