Search code examples
pythoncx-freeze

How include modules - cx_Freeze


I have a file that uses the random modules how do I include that module in my setup.py file?

Here is my code:

import sys
from cx_Freeze import setup, Executable

build_exe_options = {'packages': ['sys'], 'excludes': ['tkinter'],
                      'includes': ['random']}

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

setup(name = 'name',
      verison = '0.1',
      description = 'description',
      options = {'build_exe': build_exe_options},
      executables = [Executable('fileName.py', base = base)])

My Script

import random
choices = ['rock', 'paper', 'scissors']
i = randome.randint(0, 2)
title = input('Rock, Paper, Scissor\nPress Enter to continue...')
instructions = input('Please read the instructions carefully...')
end = input('Please type \'done\' to end the game...')
enjoy = input('Enjoy!')
done = False
while not done:
    You = input('\nRock, paper, or scissors? \n')
    Computer = choices[i]
    if You == Computer:
        print('Tie')
    if You == 'rock' and Computer == 'paper':
        print('Computer wins!')
    if You == 'paper' and Computer == 'scissors':
        print('Computer wins!')
    if You == 'scissors' and Computer == 'rock':
        print('Computer wins!')
    if Computer == 'rock' and You == 'paper':
        print('You win')
    if Computer == 'paper' and You == 'scissors':
        print('You win')
    if Computer == 'scissors' and You = 'rock':
        print('You win')
    if You == 'done':
        exit()

Solution

  • I have gone through both scripts you provided and there are a number of errors that I found they may be typing errors/ genuine mistakes I don't know but they would stop your script from working correctly.

    • if Computer == 'scissors' and You = 'rock': should be and You == 'rock': (two equals signs)

    • i = randome.randint(0, 2) should be i = random.randint(0, 2) (no e at the end of random)

    Now for the setup script.

    verison = '0.1', should be version = '0.1', (version not verison)

    The error you are getting occurs because you are attempting to hide the console when no GUI is present.

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

    base = None would mean that the console appears. base = 'Win32GUI' means that the console is hidden. You cannot do this because there is no GUI (such as Tkinter) to work with it.

    To fix this problem just remove:

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

    from your script.

    If you do this you do not need import sys either.