0
import shutil
import time
from pygame import mixer

mixer.init()
mixer.music.load('1.mp3')
mixer.music.play()

cols, rows =shutil.get_terminal_size()
print (("YOU SHOULD NOT OPEN THIS FILE").center(cols))
print (("SLEEP PEACEFULLY").center(cols))
time.sleep(3)

os.system("shutdown /h")

input ()

This is my code which actually turns the client computer in hibernate mode, with an amazing horror sound. So I want to complie the code so that no one can open the source code and the music.

i have tried to make exe and pyc of this code but it need the music file separately . it is not combined in one file . To make exe i have used cmd (pyinstaller --onefile {filename}) and to make pyc i have used python itself (py_compile.compile({filename})

1 Answers1

1

You can add your audio files into binary file generated by pyinstaller by using spec file to config pyinstaller

For example:

...
a = Analysis(['Main.py'],
             pathex=['F:\\My\\Python\\Projects\\Demo'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
# Put all your audio files into folder ./audios
a.datas += Tree('./audios', 'audios')
...

Your project structure should same as bellow:

.\Demo\
    Main.py
    audios\
        audio1.mp3
        audio2.mp3

Refer here for more detail.

mtdot
  • 312
  • 2
  • 10