简体   繁体   English

为什么这段代码编译后会抛出错误

[英]Why is this code throwing error after compiling

I made a script and it works perfectly but when I compile it with pyinstaller我制作了一个脚本,它运行得很好,但是当我用 pyinstaller 编译它时

pyinstaller --onefile --icon='icon.ico' dmi.py

It throws error, but if I don't compile it works它会抛出错误,但如果我不编译它就可以工作

I know Github module is throwing error.我知道 Github 模块抛出错误。 This is the code which throwing error:这是抛出错误的代码:

import PySimpleGUIQt as Sg
from github import Github
from urllib import parse

g = Github("ghp_**********************************")
img_data = (g.get_user().get_repo('python-files')).get_contents(
    parse.quote('create.ico'), ref="main").content.replace('\n', '').encode()

layout = [
    [Sg.Text('                                                     ')]
]
window = Sg.Window("Add Tags", layout, icon=img_data, resizable=False, finalize=True)
while True:
    event, values = window.read()
    if event == Sg.WINDOW_CLOSED:
        window.close()
        break

The code below works even after compiling:下面的代码即使在编译后也能正常工作:

import base64
import PySimpleGUIQt as Sg
import requests
header = {"Authorization": "token ghp_*******************************",
          "Accept": "application/vnd.github.v4.raw"}
encoded = base64.b64encode((requests.get('https://raw.githubusercontent.com/WoLvES-2x0/python-files/main/create.ico', headers=header)).content)
layout = [
    [Sg.Text('                                                     ')]
]
window = Sg.Window("Add Tags", layout, icon=encoded, resizable=False, finalize=True)
while True:
    event, values = window.read()
    if event == Sg.WINDOW_CLOSED:
        window.close()
        break

although I can do this in other way but main issue I'll face without this is虽然我可以用其他方式做到这一点,但没有这个我将面临的主要问题是

Get file name of all files in a repo

g_f_name = [str(i).replace('ContentFile(path="', '').replace('")', '') for i in (g.get_user().get_repo('node-files')).get_contents('') if i]

And commit changes to repocommit changes to repo

repo.update_file(repo.get_contents('tags.txt').path, "committing files", tags_string, repo.get_contents('tags.txt').sha, branch="main")

error Is错误是

C:\pythoncharm\pythonProject4\dist>dmi.exe
Traceback (most recent call last):
  File "dmi.py", line 2, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "github\__init__.py", line 56, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "github\MainClass.py", line 59, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "github\Event.py", line 32, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "github\NamedUser.py", line 44, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "github\Organization.py", line 50, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "github\Repository.py", line 125, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "github\PublicKey.py", line 34, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "nacl\public.py", line 17, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "nacl\bindings\__init__.py", line 17, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "PyInstaller\loader\pyimod03_importers.py", line 546, in exec_module
  File "nacl\bindings\crypto_aead.py", line 18, in <module>
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
  File "C:\Users\WoLvES\AppData\Local\Temp\embedded.rtin1sym.zip\shibokensupport\__feature__.py", line 142, in _import
ModuleNotFoundError: No module named '_cffi_backend'
[33116] Failed to execute script 'dmi' due to unhandled exception!

importing输入

import _cffi_backend

solves the issue, what I think is Pyinstaller somehow misses this module while compiling, and PyGithub need this module, Although in editor this grayed out but it works解决了这个问题,我认为 Pyinstaller 在编译时不知何故错过了这个模块,而 PyGithub 需要这个模块,虽然在编辑器中这个变灰了但是它有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM