Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening an EXE of my Pygame program gives me import errors

I made an MP3 player with pygame code:

from Tkinter import *
import pygame
import glob
import tkFont
songs=[]
for x in glob.glob('C:\WhaleTunes\Downloaded/*mp3'):

    songs.append(x)
Admin=Tk()
num=0
plpa=-1
songas=Label(Admin,text='',bg='red')
songas.place(relx=0.0,rely=0.7)
def play(number):

    pygame.mixer.music.unpause()
    pygame.mixer.music.load(songs[number])
    pygame.mixer.music.play()

    songas.configure(text=songs[number])


def pause():
     pygame.mixer.music.pause()
def Pre():
    global num
    if num == 0:
        z = len(songs)
        num=z
        num+=1
    num-=1
    play(num)
def Next():
    global num
    num+=1
    play(num)
#init pygame mixer
pygame.mixer.init()
#atach all buttons & labels
fons=tkFont.Font(family="bold", size=40)
fon=tkFont.Font(family="Helvetica", size=20)
tit=Label(Admin,text='Mp3 Player',font=fons,fg='grey',bg='red')
tit.place(relx=0.2,rely=0.0)
playnpause=Button(Admin,text='Play',command=lambda:play(num),fg='yellow',bg='red',font=fon)
playnpause.place(relx=0.0,rely=0.4)
last=Button(Admin,text='Previous',command=Pre,fg='yellow',bg='red',font=fon)
last.place(relx=0.2,rely=0.4)
first=Button(Admin,text='Next',command=Next,fg='yellow',bg='red',font=fon)
first.place(relx=0.5,rely=0.4)
pauses=Button(Admin,text='Pause',command=pause,fg='yellow',bg='red',font=fon)
pauses.place(relx=0.7,rely=0.4)
Admin.minsize(width=500, height=200)
Admin.maxsize(width=500, height=200)
Admin.configure(bg='red')
Admin.mainloop()

And I tried to put it into an exe with this code:

from distutils.core import setup
import py2exe

setup(console=['mp3player.py'])

When I run the mp3player.exe I get a bunch of import errors:

C:\Users\P'sao\Downloads\dist\mp3player.exe:2: RuntimeWarning: import display: N
o module named _view
(ImportError: No module named _view)
C:\Users\P'sao\Downloads\dist\mp3player.exe:2: RuntimeWarning: import draw: No m
odule named _view
(ImportError: No module named _view)
C:\Users\P'sao\Downloads\dist\mp3player.exe:2: RuntimeWarning: import image: No
module named _view
(ImportError: No module named _view)
C:\Users\P'sao\Downloads\dist\mp3player.exe:2: RuntimeWarning: import pixelcopy:
 No module named _view
(ImportError: No module named _view)
C:\Users\P'sao\Downloads\dist\mp3player.exe:2: RuntimeWarning: import transform:
 No module named _view
(ImportError: No module named _view)

Anyone know how to fix this?

And when I compile everything I get this error:

The following modules appear to be missing
['AppKit', 'Foundation', 'Numeric', 'OpenGL.GL', '_scproxy', 'copyreg', 'dummy.P
rocess', 'numpy', 'pkg_resources', 'queue', 'winreg', 'pygame.sdlmain_osx']
like image 912
P'sao Avatar asked Dec 28 '22 18:12

P'sao


1 Answers

The solution is to add import pygame._view to the top of your main source file. Any of the packagers should work after that. I encountered this problem using cx_Freeze, py2exe, and pyInstaller. This is a serious bug affecting many of the exe packagers when attempting to package pygame programs.

like image 200
odie5533 Avatar answered Jan 03 '23 05:01

odie5533