Python 3.x pyinstaller创建的可执行文件不';跑不动

Python 3.x pyinstaller创建的可执行文件不';跑不动,python-3.x,pygame,crash,pyinstaller,executable,Python 3.x,Pygame,Crash,Pyinstaller,Executable,我正在pygame上创建一个数独解算器,现在想为这个项目创建一个可执行文件,因为你不能期望用户了解编程、虚拟环境等 我在pygame的虚拟环境中安装了PyInstaller,并使用了以下命令: pyinstaller --onefile -w main.py 成功了 但是,我无法在dist文件夹中运行可执行文件:( 当我尝试单击可执行文件的粘贴时,什么也没有发生。使用终端,我得到以下错误: ./main pygame 1.9.6 Hello from the pygame community.

我正在pygame上创建一个数独解算器,现在想为这个项目创建一个可执行文件,因为你不能期望用户了解编程、虚拟环境等

我在pygame的虚拟环境中安装了PyInstaller,并使用了以下命令:

pyinstaller --onefile -w main.py
成功了

但是,我无法在dist文件夹中运行可执行文件:(

当我尝试单击可执行文件的粘贴时,什么也没有发生。使用终端,我得到以下错误:

./main
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import pygame
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "/home/lucas1809/Área de Trabalho/Projetos/sudokey/venv/lib/python3.6/site-packages/PyInstaller/loader/pyimod03_importers.py", line 623, in exec_module
    exec(bytecode, module.__dict__)
  File "PyInstaller/__init__.py", line 68, in <module>
  File "setuptools-40.8.0-py3.6.egg/pkg_resources/__init__.py", line 481, in get_distribution
  File "setuptools-40.8.0-py3.6.egg/pkg_resources/__init__.py", line 357, in get_provider
  File "setuptools-40.8.0-py3.6.egg/pkg_resources/__init__.py", line 900, in require
  File "setuptools-40.8.0-py3.6.egg/pkg_resources/__init__.py", line 786, in resolve
pkg_resources.DistributionNotFound: The 'PyInstaller' distribution was not found and is required by the application
[3920] Failed to execute script main
/main
PyGame1.9.6
大家好,来自pygame社区。https://www.pygame.org/contribute.html
回溯(最近一次呼叫最后一次):
文件“main.py”,第1行,在
导入pygame
文件“”,第971行,在_find_和_load中
文件“”,第955行,在“查找”和“加载”中解锁
文件“”,第665行,在“加载”中
exec_模块中的文件“/home/lucas1809/Área de Trabalho/Projetos/sudokey/venv/lib/python3.6/site packages/PyInstaller/loader/pyimod03_importers.py”,第623行
exec(字节码、模块、指令)
文件“PyInstaller/_init__uuu.py”,第68行,在
文件“setuptools-40.8.0-py3.6.egg/pkg_resources/_init__.py”,第481行,在get_发行版中
文件“setuptools-40.8.0-py3.6.egg/pkg_resources/__init__.py”,第357行,在get_provider中
文件“setuptools-40.8.0-py3.6.egg/pkg_resources/_init__.py”,第900行,要求
文件“setuptools-40.8.0-py3.6.egg/pkg_resources/_init__uu.py”,第786行,解析
pkg_resources.DistributionNotFound:找不到“PyInstaller”发行版,该发行版是应用程序所必需的
[3920]无法执行主脚本
我不认为main.py代码是必要的,因为它在pycharm中执行时运行良好。但是,如果我错了,我会发布代码

如果有人能帮我解决这个问题,我将不胜感激。如果你在理解上有问题,或者我不清楚。请问

提前感谢:)

编辑:以下是“main.py”代码:

导入pygame、os、PyInstaller
从pygame.locals导入*
来自进口局
从按钮导入按钮
#初始化和屏幕表面加载
pygame.init()
screen=pygame.display.set_mode()
screenSize=pygame.display.get_surface().get_size()
宽度=屏幕大小[0]
高度=屏幕大小[1]
pygame.display.set_标题(“数独键:数独的解算器”)
#图像和音乐加载
bgMenu=pygame.image.load(“background/sudokey2Menu.png”)
bgMenu=pygame.transform.scale(bgMenu,(宽度,高度-30))
bgStart=pygame.image.load(“background/sudokeyCustom.png”)
bgStart=pygame.transform.scale(bgStart,(宽-40,高-55))
pygame.mixer.pre_init()
pygame.mixer.init()
pygame.mixer.music.load(“musica/LulllabyHostinYourPiano.mp3”)
pygame.mixer.music.play(-1)
click=pygame.mixer.Sound(“sons/click.ogg”)
#默认屏幕和游戏状态
运行=1
菜单=1
开始=0
信用=0
#鼠标逻辑来检测点击
currentSquare=(9,9)
clickedCell=无
#使用类“board”创建板
tabuleiro=董事会()
#使用类“Button”创建菜单按钮
按钮开始=按钮(40018653090)
buttonTutorial=按钮(40032553090)
按钮选项=按钮(40046453090)
按钮编辑=按钮(40060353090)
#使用类“Button”创建开始按钮
buttonSolve=按钮(898、40、380、80)
buttonReset=按钮(89815938080)
按钮返回=按钮(89827938080)
ButtonOptions开始=按钮(89839838080)
#字体加载
font=pygame.font.font(“freesansbold.ttf”,30)
#直观地更新董事会
def牵引格栅(板):
对于范围(9)内的i:
对于范围(9)内的j:
如果(董事会[i][j]):
text=font.render(str(board[i][j]),True,(0,0,0))
textRect=text.get_rect()
textRect.center=(j*90+45,i*80+45)
screen.blit(text,textRect)
#根据输入播放音乐
def自动存储塔(编号):
如果数字==0:
pygame.mixer.music.stop()
elif编号==1:
pygame.mixer.music.load(“musica/LulllabyHostinYourPiano.mp3”)
pygame.mixer.music.play(-1)
elif编号==2:
pygame.mixer.music.load(“musica/adventureGhostInYourPiano.mp3”)
pygame.mixer.music.play(-1)
elif编号==3:
pygame.mixer.music.load(“musica/liebestrau.mp3”)
pygame.mixer.music.play(-1)
elif编号==4:
pygame.mixer.music.load(“musica/Kiss\u the\u Sky.mp3”)
pygame.mixer.music.play(-1)
elif编号==5:
pygame.mixer.music.load(“musica/Lullaby.mp3”)
pygame.mixer.music.play(-1)
elif编号==6:
pygame.mixer.music.load(“musica/温柔的微风.mp3”)
pygame.mixer.music.play(-1)
elif编号==7:
pygame.mixer.music.load(“musica/external_Hope.mp3”)
pygame.mixer.music.play(-1)
elif编号==8:
pygame.mixer.music.load(“musica/Pressure.mp3”)
pygame.mixer.music.play(-1)
elif编号==9:
pygame.mixer.music.load(“musica/01到月亮-主主题.mp3”)
pygame.mixer.music.play(-1)
运行时:
while菜单:
pygame.display.flip()
屏幕显示(bgMenu,(0,0))
对于pygame.event.get()中的事件:
如果(event.type==pygame.QUIT)或(event.type==pygame.KEYDOWN和event.key==pygame.K_ESCAPE):
运行=0
菜单=0
elif event.type==pygame.KEYDOWN和event.key==pygame.K_s:
开始=1
菜单=0
如果event.type==pygame.MOUSEBUTTONUP:
x、 y=pygame.mouse.get_pos()
如果按钮启动(x,y):
#点击播放()
#单击。停止()
打印(x,y)
菜单=0
开始=1
elif buttonTutorial.isOn(x,y):
打印(x,y)
打印(“教程”)
菜单=0
开始=1
elif buttonOptions.isOn(x,y):
打印(x,y)
import pygame, os, PyInstaller
from pygame.locals import *
from board import Board
from button import Button 

# Initialization and screen surface loading
pygame.init()
screen = pygame.display.set_mode()
screenSize = pygame.display.get_surface().get_size()
width = screenSize[0]
height = screenSize[1]
pygame.display.set_caption("Sudokey: Sudoku's Solver")

# Image and music loading
bgMenu = pygame.image.load("background/sudokey2Menu.png")
bgMenu = pygame.transform.scale(bgMenu, (width, height - 30))
bgStart = pygame.image.load("background/sudokeyCustom.png")
bgStart = pygame.transform.scale(bgStart, (width - 40, height - 55))
pygame.mixer.pre_init()
pygame.mixer.init()
pygame.mixer.music.load("musica/lullabyGhostInYourPiano.mp3")
pygame.mixer.music.play(-1)
click = pygame.mixer.Sound("sons/click.ogg")

# Default screen and game state
running = 1
menu = 1
start = 0
credit = 0

# Mouse logic to detect click
currentSquare = (9, 9)
clickedCell = None

# Creating board using class "Board"
tabuleiro = Board()

# Creating menu buttons using class "Button"
buttonStart = Button(400, 186, 530, 90)
buttonTutorial = Button(400, 325, 530, 90)
buttonOptions = Button(400, 464, 530, 90)
buttonCredits = Button(400, 603, 530, 90)

# Creating start buttons using class "Button"
buttonSolve = Button(898, 40, 380, 80)
buttonReset = Button(898, 159, 380, 80)
buttonGoBack = Button(898, 279, 380, 80)
buttonOptionsStart = Button(898, 398, 380, 80)

# Font loading
font = pygame.font.Font("freesansbold.ttf", 30)


# Visually updates the board
def drawGrid(board):
    for i in range(9):
        for j in range(9):
            if (board[i][j]):
                text = font.render(str(board[i][j]), True, (0, 0, 0))
                textRect = text.get_rect()
                textRect.center = (j * 90 + 45, i * 80 + 45)
                screen.blit(text, textRect)

# Plays music based on input
def jukebox(number):
    if number == 0:
        pygame.mixer.music.stop()
    elif number == 1:
        pygame.mixer.music.load("musica/lullabyGhostInYourPiano.mp3")
        pygame.mixer.music.play(-1)
    elif number == 2:
        pygame.mixer.music.load("musica/adventureGhostInYourPiano.mp3")
        pygame.mixer.music.play(-1)
    elif number == 3:
        pygame.mixer.music.load("musica/liebestrau.mp3")
        pygame.mixer.music.play(-1)
    elif number == 4:
        pygame.mixer.music.load("musica/Kiss_the_Sky.mp3")
        pygame.mixer.music.play(-1)
    elif number == 5:
        pygame.mixer.music.load("musica/Lullaby.mp3")
        pygame.mixer.music.play(-1)
    elif number == 6:
        pygame.mixer.music.load("musica/Gentle_Breeze.mp3")
        pygame.mixer.music.play(-1)
    elif number == 7:
        pygame.mixer.music.load("musica/Eternal_Hope.mp3")
        pygame.mixer.music.play(-1)
    elif number == 8:
        pygame.mixer.music.load("musica/Pressure.mp3")
        pygame.mixer.music.play(-1)
    elif number == 9:
        pygame.mixer.music.load("musica/01 To the Moon - Main Theme.mp3")
        pygame.mixer.music.play(-1)


while running:
    while menu:
        pygame.display.flip()
        screen.blit(bgMenu, (0, 0))
        for event in pygame.event.get():
            if (event.type == pygame.QUIT) or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
                running = 0
                menu = 0
            elif event.type == pygame.KEYDOWN and event.key == pygame.K_s:
                start = 1
                menu = 0
            if event.type == pygame.MOUSEBUTTONUP:
                x, y = pygame.mouse.get_pos()

                if buttonStart.isOn(x, y):
                    #click.play()
                    #click.stop()

                    print(x, y)
                    menu = 0
                    start = 1

                elif buttonTutorial.isOn(x, y):
                    print(x, y)
                    print('tutorial')
                    menu = 0
                    start = 1

                elif buttonOptions.isOn(x, y):
                    print(x, y)
                    print('Options')
                    menu = 0
                    start = 1

                elif buttonCredits.isOn(x, y):
                    print(x, y)
                    print('Credits')
                    menu = 0
                    start = 1

            if (event.type == pygame.KEYDOWN):
                if (pygame.K_0 <= event.key <= pygame.K_9):
                    number = int(event.unicode)
                    jukebox(number)

    while start:
        pygame.display.flip()
        screen.blit(bgStart, (0, 0))
        drawGrid(tabuleiro.tabuleiro)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                print('stopping')
                running = 0
                start = 0

            elif event.type == pygame.KEYDOWN and (event.key == pygame.K_m or event.key == pygame.K_ESCAPE):
                start = 0
                menu = 1

            if (event.type == pygame.MOUSEBUTTONUP):
                coords = pygame.mouse.get_pos()
                col = coords[1] // 80
                line = coords[0] // 90
                clickedCell = (line, col)

            if (event.type == pygame.KEYDOWN):
                if (clickedCell != None):
                    if (pygame.K_0 <= event.key <= pygame.K_9):
                        line = clickedCell[1]
                        col = clickedCell[0]
                        number = int(event.unicode)
                        if 0 <= line <= 8 and 0 <= col <= 8:
                            tabuleiro.setCell(line, col, number)
                            clickedCell = None

            if (event.type == pygame.KEYDOWN):
                if event.key == pygame.K_s:
                    tabuleiro.findFirst()
                    tabuleiro.solve()
                elif event.key == pygame.K_r:
                    tabuleiro.reset()


            if event.type == pygame.MOUSEBUTTONUP:
                x, y = pygame.mouse.get_pos()
                print(x, y)

                if buttonSolve.isOn(x, y):
                    print('solving')
                    tabuleiro.solve()

                elif buttonReset.isOn(x, y):
                    tabuleiro.reset()
                    tabuleiro.show()

                elif buttonGoBack.isOn(x, y):
                    start = 0
                    menu = 1

                elif buttonOptionsStart.isOn(x, y):
                    start = 0
                    menu = 1

pygame.quit()

./main
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "main.py", line 51, in <module>
    font = pygame.font.Font("freesansbold.ttf", 30)
  File "pygame/pkgdata.py", line 50, in getResource
  File "setuptools-40.8.0-py3.6.egg/pkg_resources/__init__.py", line 1134, in resource_exists
  File "setuptools-40.8.0-py3.6.egg/pkg_resources/__init__.py", line 1404, in has_resource
  File "setuptools-40.8.0-py3.6.egg/pkg_resources/__init__.py", line 1457, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
[3816] Failed to execute script main

pygame.font.Font('./freesansbold.ttf')