Pyinstaller“无法执行"脚本 [英] Pyinstaller 'failed to execute' script

查看:56
本文介绍了Pyinstaller“无法执行"脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是编程新手.我制作了一个python脚本.它在 pycharm 中运行没有错误.使用 pyinstaller 我试图制作一个 exe.当我在 build 或 dist 文件夹或什至通过命令提示符运行 exe 时,它​​给我错误无法执行脚本主"

我附上警告文件链接:

  • 然后您需要设置运行配置.
  • 脚本名称:python 脚本的路径

    工作路径:项目所在地

    保留图像中的解释器选项.

    1. 运行pyinstaller.您可以在 dist 目录中找到您的 .exe.

    2. 如果找不到模块"错误仍然存​​在.您可以添加一个隐藏的导入钩子并指定缺失模块的名称.导航到 Project Path\venv\Lib\site-packages\PyInstaller\hooks 并创建一个新的hook-pandas.py"(hook-modulename.py) 脚本并制作一个隐藏导入模块的列表,如下所示:

    hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']

    1. 再次运行 pyinstaller,它现在应该可以工作了.

    I am new to programming. I have made a python script. It runs without errors in pycharm. Using pyinstaller i tried to make an exe. When i run the exe in build or dist folder or even through command prompt, it gives me the error 'Failed to execute Script Main'

    I am attaching the warnings file link:

    https://drive.google.com/open?id=1cDQ2KGId0B8K9Qi1bWPIhL55hQO0dM-z

    Kindly help!

    解决方案

    There is one pip script for each virtual environment. So when you install a python module it get installed into the projectname\venv\Lib\site-packages directory.

    When you run pyinstaller from terminal to make the executable, pyinstaller checks for dependencies in Sys.path . But that path does not include the projectname\venv\Lib\site-packages directory. Therefore pyinstaller cannot find those particular dependencies. In such cases it gives you warnings.Those warning can be found in 'warnname.txt' near your executable file.

    How to Configure pycharm to run pyinstaller

    1. First you need to add pyinstaller into project interpreter.
    2. Then you need to setup running configurations.

    Script name: path to your python script

    working path: Project location

    Leave interpreter options as it is in the image.

    1. Run pyinstaller. You can find your .exe in dist directory.

    2. If the "Module not found" error still persists. You can add a hidden import hook and specify the names of the missing modules.Navigate to Project Path\venv\Lib\site-packages\PyInstaller\hooks and create a new "hook-pandas.py"(hook-modulename.py) script and make a list of hidden import modules like this:

    hiddenimports = ['pandas._libs.tslibs.np_datetime','pandas._libs.tslibs.nattype','pandas._libs.skiplist']
    

    1. And run pyinstaller again, and it should work now.

    这篇关于Pyinstaller“无法执行"脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆