0

I wrote a basic script in python 3.7 that does what I need. However it needs to run on another person's computer. I want to run this as an exe then just change the icon logo.

I have installed py2exe (I believe). Below is the python script:

pip install py2exe
import os
os.startfile(r"\\ComputerName\c$\users\UserName\desktop\Lullaby wav.wav")

I have another file, that looks like this (basing this off this thread Can I somehow "compile" a python script to work on PC without Python installed? ):

import sys
from distutils.core import setup
import py2exe

entry_point = sys.argv[1]
sys.argv.pop()
sys.argv.append('py2exe')
sys.argv.append('-q')

opts = {
    'py2exe': {
        'compressed': 1,
        'optimize': 2,
        'bundle_files': 1
    }
}

setup(console=[entry_point], options=opts, zipfile=None)

I then open up cmd and try to use the compile.py file on myscript per the instructions but get an erro:

File "", line 1 python compile.py covid.pyw ^

3
  • As the error indicates, your clue is on line 1: pip install py2exe is not a Python statement, it is meant to run from a command line. Commented Dec 8, 2020 at 15:28
  • I took that out and still have the same error. do the files need to be in the same location? Commented Dec 8, 2020 at 15:32
  • Yes, they do. But do yourself a favor and use PyInstaller instead. It's the more modern alternative to py2exe. Commented Dec 8, 2020 at 15:34

2 Answers 2

1

You can use PyInstaller. Which is inbuilt, if not you can install it. Just very simple lines in cmd to create an exe file and also you can add icon using -i(I think so).

Visit this to learn about it from realpython which I love to read about python tutorials : https://realpython.com/pyinstaller-python/

By the way you can use python 3.8.6 or 3.9 which is the updated version of python 3.7.

Sign up to request clarification or add additional context in comments.

3 Comments

Once pyinstaller is installed I just need to put the file name I want to convert to exe and type -i after in cmd? for example in cmd, myscript.py -i to get an executable?
I'm not a regular user of PyInstaller but I have heard of this as very useful. I just wanted to help you know this library. Just search in you browser about how to use it and you will get to know about it.
I installed pyinstaller, and got an error" 'pyinstaller' is not recognized as an internal or external..." I found the path where pyinstaller is installed and added it to the system variables but am still getting the error. My path looks a little different from the documentation out there
0

Make sure your device is up to date, that could be the problem, also pyinstaller is a better, more modern alternative

2 Comments

Thanks I will try the pyinstaller route.
Good idea @IMLight

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.