I have a made a setup.py file for my pygame executive, but it gives a HUGE list of errors when i try to run the executable after it is built. I am using python 3.3 32 bit and the corresponding pygame. My source is
import sys
from cx_Freeze import setup, Executable
setup(
name = "Pygame Module",
version = "0.1",
description = "A simple pygame program.",
executables = [Executable("pygame_module.py", base = "WIN32GUI")])
Help?
EDIT: this is the error i get: http://imgur.com/XlOpzEg
EDIT: this question is for cx-Freeze. I apologize for not mentioning that
EDIT: my source is
import pygame, sys
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((400, 300))
pygame.display.set_caption('Hello World!')
while True: # main game loop
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
this works in the shell, but not when making a module. it says pygame is not a package.
I did it! in the folder C:\Python33\include i deleted the pygame folder that was being used instead of the real folder
EDIT! i reinstalled python 3.3.3 and it worked like i said and then stopped. re-installed 3.3.2 and it now works. i dont know why
I believe I know your problem, because I had the same problem myself, but I can't be sure without the Traceback. Try manually importing both the pygame._view and the re modules into each file of your program. Eg. put the lines import pygame._view and import re into each python file. If this doesn't solve the problem could you please post an error traceback, and I'll see what I can do.
Hope this helped.
EDIT: This was not the answer to the above question. I will edit again if the correct answer is found. See comments below.
Related
I'm using python 3.7.9 and I have this code:
import kivy
from kivy.app import App
from kivy.uix.label import Label
class MyApp(App):
def build(self):
return Label(text='Hello world')
if __name__ == '__main__':
MyApp().run()
And I get this error:
Yes, I've tried reinstalling all kivy libraries multiple times, I've tried reinstalling Python but I still get this error.
My project settings:
My configurations:
I've even found it in 'External Libraries' folder:
I've tried to fix for literally 3 hours now and I'm too frustrated so I'm asking you guys. Thank you in advance.
First, forget pycharm, follow the kivy install instructions and see if you can run a kivy app via python from the command line. If you can't, debug this without the pycharm environments getting in the way.
If you can install and run kivy outside of pycharm, then your only problem is that you haven't installed it correctly within whatever python environment pycharm is using. I don't know how you configure it, but you'd need to make sure kivy and its dependencies are installed in that environment.
I am trying to play a .wav file with pygame
import pygame
pygame.mixer.init()
s = pygame.mixer.Sound('absolute path to file')
s.play()
it gives no error, but it seems like it doesn't play anything.
This is the complete output
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
installed pygame via pip in a conda python 3.6 enviroment. mac book pro 2019 with macOS Mojave
Add a line at the end :
input ('Press enter to continue.')
and you will hear it. Your script is ending before it has a chance to play the sound.
As bashBediam said the problem was that the code was ending not giving time to the audio to play. i fixed that doing like this.
import pygame
pygame.mixer.init()
s = pygame.mixer.Sound(path)
channel = s.play()
while channel.get_busy():
pygame.time.wait(100)
I want to run python code with Kivy by atom-runner or script, but when I run the simple any codes with Kivy, I got ModuleNotFoundError. I checked python path by
import sys
print(sys.prefix)
which prints ''/Library/Frameworks/Python.framework/Versions/3.7''
I guess I need to use Anaconda's python because I can run Kivy app on terminal and terminal uses python3.7 showing Anaconda.inc things.
But I can not find where to write path of python in Atom.
I tried pip install Kivy and it worked but nothing changed in Atom. And Kivy3 is in Application folder.
Just in case, my Kivy codes is this
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.button import Button
class IntroKivy(App):
def build(self):
return Button(text="Hello, World!")
if __name__ == "__main__":
IntroKivy().run()
It will be perfect if I can run this codes without using terminal as it is faster and quick.
Best
I made a timer in a Python script using an IDE (its working fine). When the timer ends, I want to open a sound file, like a .mp3 file, so that the user knows that the timer went off. I know I could use google for a timer, but knowing how to do this would help for later projects. Thanks!
First install pygame via pip. Then use:
from pygame import mixer # Load the required library
mixer.init()
mixer.music.load('e:/LOCAL/Betrayer/. Metalik Klinik1-Anak Sekolah.mp3')
mixer.music.play()
if you're on linux you can use pyglet! pure python:
import pyglet
music = pyglet.resource.media('music.mp3')
music.play()
pyglet.app.run()
if you're on windows its built in:
import winsound
winsound.PlaySound('sound.wav', winsound.SND_FILENAME)
EDIT
testing with winsound seemed to return nothing substantial so i found a work around using "playsound":
pip3 install playsound
in code:
import playsound
playsound.playsound("C:\\path\\to\\audio\\file.ext")
tested this with mp3 and wav and both worked just fine.
Let me know if this helped!
I am trying to create a .exe file using pyinstaller and execute it
it is not fetching any result from
b = TextBlob(ar)
score = b.sentiment.polarity
it returns proper value when executed on console
but return 0 when executed with .exe
def start_dmo():
print ("Importing all the required packages...")
from textblob import TextBlob
input ("press enter to continue")
print("All Necessary Packages imported")
input("press enter to continue")
ar="I cant be more happy with this"
print(ar)
b = TextBlob (ar)
score = b.sentiment.polarity
print (b.sentiment.polarity)
input("press enter to continue")
score = round (score, 2)
if score > 0.0:
senti = "Positive"
elif score < 0.0:
senti = "Negative"
else:
senti = "Neutral"
print("Score"+str(score)+"sentiment"+senti)
input("press enter to continue")
start_dmo()
this is the output when the above code is executed on console
this is the output when the above code is executed on .exe of the same code which is created using pyinstaller
Pyinstaller is not including en-sentiment.xml in the package, so the sentiment analyzer is missing a dependency and returns 0. Textblob doesn't produce an error in this case.
pyinstaller requires that you specify any data files in myscript.spec manually. However, as you've discovered, it appears that cx_Freeze honors the setup.py configuration, which specifies the data files to be included already:
package_data={
"textblob.en": ["*.txt", "*.xml"]
}
To resolve, modify the pyinstaller myscript.spec file to copy textblob/en/en-sentiment.xml, or switch to cx_Freeze as discussed.
See my post on Github as well.
Try importing textblob before of your start_dmo function so that pyinstaller is aware of it as a dependency.
from textblob import TextBlob
start_dmo():
....
Issue Solved!
Simple Solution
Changed pyinstaller to cx_Freeze
FYI cx_Freeze works perfectly fine with python 3.6
to know how to create .exe using cx_freeze follow the below link:
https://pythonprogramming.net/converting-python-scripts-exe-executables/
if u use numpy or pandas u might need to add option cz it might not import numpy to form ur exe so solve that issue follow below link:
Creating cx_Freeze exe with Numpy for Python
Good luck!
hey copy textblob from site packages to your working directory
and run below in .spec
a = Analysis(.....
datas=[( 'textblob/en/*.txt', 'textblob/en' ),
( 'textblob/en/*.xml', 'textblob/en' )],
....)
it will work