Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Ground Controller Lvl 1
Message 1 of 3

Python .py to .exe using cx_Freeze

Í uses cx_Freeze to build .exe but it won't run
EOF Error when í try to run the .exe file

Tracebace (most recent call last):
File
"C:\Python2.7.2\lib\sit-packages\cx_Freeze\initscripts\__startup__.py",
line 12, in <module>
__import__(name + "__init__")
File
"C:\Python2.7.2\lib\sit-packages\cx_Freeze\initscripts\Console.py",
line 24, in <module>
exec(code, m.__dict__)
File"projectile3.py", line 19, in <module>
File"projectile3.py", line 13, in main
File"projectile3.py", line 6, in getInputs
EOFError: EOF when reading a line

NB:
The setup.py scrip:
import sys
from cx_Freeze import setup, Executable

base = 'Console'
if sys.platform == 'win32':
base = 'Win32GUI'

options = {
'build_exe': {
'packages': ["os","sys","ctypes","win32con"],
'include_files': ['projectile2.py'],
'include_msvcr': True,
# Sometimes a little fine-tuning is needed
# exclude all backends except wx
'excludes': ['gtk', 'PyQt4', 'PyQt5', 'Tkinter']
}
}

executables = [
Executable('projectile3.py', base=base)]

setup(name='Projectile',
author = 'Fous',
version='1.0.0',
description='Simple Projectile script',
executables=executables,
options=options
)

The projectile3.py scrip:

from projectile2 import Projectile

def getInputs():
a = input("Enter the launch angle (in degrees): ")
v = input("Enter the initial velocity (in meters/sec): ")
h = input("Enter the initial height (in meters): ")
t = input("Enter the time interval between position calculations: ")
return float(a),float(v),float(h),float(t)

def main():
angle, vel, h0, time = getInputs()
cball = Projectile(angle, vel, h0)
while cball.getY() >= 0:
cball.update(time)
print ("\nDistance traveled: %0.1f meters." % (cball.getX()))

if __name__ == '__main__': main()

The projectile2.py Script:

# projectile.py
"""projectile.py
Provides a simple class for modeling the flight of projectiles."""
import os
import sys
from math import pi, sin, cos
class Projectile:
#The below is a __doc__ string; its like a comment which can be
#calling Projectile.__doc__
"""Simulates the flight of simple projectiles near the earth's
surface, ignoring wind resistance. Tracking is done in two
dimensions, height (y) and distance (x).
"""

def __init__(self, angle, velocity, height):
"""Create a projectile with given launch angle, initial
velocity and height."""
self.xpos = 0.0
self.ypos = height
theta = pi * angle / 180.0
self.xvel = velocity * cos(theta)
self.yvel = velocity * sin(theta)

def update(self, time):
"""Update the state of this projectile to move it time seconds
farther into its flight"""
self.xpos = self.xpos + time * self.xvel
yvel1 = self.yvel - 9.8 * time
self.ypos = self.ypos + time * (self.yvel + yvel1) / 2.0
self.yvel = yvel1

def getY(self):
"Returns the y position (height) of this projectile."
return self.ypos

def getX(self):
"Returns the x position (distance) of this projectile."
return self.xpos

Any help please
2 Replies
Commander Lvl 2
Message 2 of 3

Re: Python .py to .exe using cx_Freeze

You need to post your code in a code block, or point us to a gist or repository, as your post has lost the (very important!) formatting.

 

Googling "cx_freeze input" gets me some hits which show that others have problems with input() and cx_freeze. input() requires a console window and that could be difficult to get using cx_freeze. E.g. one post mentions that using "base = Win32GUI", just like you do, hides the console, so no input.

 

You need to either rework your cx_freeze config so that you get a console, or rework your app to take input via a GUI dialog or something.

 

Please follow-up to let us know how you made out. For good karma, mark a reply as the answer if it helped!

Ground Controller Lvl 1
Message 3 of 3

Re: Python .py to .exe using cx_Freeze

I had the same issue with converting it to .exe and when i make the base = none instead of Win32GUI it works. 

Is there a way to make it work without having to open up the console?