1

I have a small program written with Python3 that I'd like to install on friends computers. The main issue is that not every computer has a Python3 installed on it (mostly Python2-). Do I have to install it on each computer I want my program to run?

I thought it would be possible to install Python3 inside a separate directory, as shown below.

enter image description here

Then, I would be able to use a shebang to run the right version of Python installed inside myProgram folder.

#!C:\myProgram\python3 python

# Test
a = input('Entrer un nom:')
print(a)

When I double-click on myProgram.py file, a window opens and closes immediatly...

Is this a bad idea or not? Is there a way to achieve that differetnly if so?

wiltomap
  • 3,933
  • 8
  • 37
  • 54

4 Answers4

1

You could create an executable from the python script rather than installing all of python 3 on their machine. There's a few ways you can do it, see this answer.
I'd have a look at pyinstaller.

ConorSheehan1
  • 1,640
  • 1
  • 18
  • 30
0

Add Python 3 to your friends machine to execute your program. What'is the utility to run such a small program on their computers?

Rourou Taa
  • 21
  • 2
0

The way you propose won't work.

  1. Windows does not know about shebangs.
  2. Even if it did, this one would only work if a user installed the program to C:\myProgram (which is not a really appropriate place, and the user might not have the rights to install it there).

There are ways to make a python program portable w/o having the need to have a Python runtime installed. Alas, I currently don't know their name.

Or, if that is feasible, install Python 3 on their machines, but I don't know if that might break any programs wanting to use Python 2.

glglgl
  • 89,107
  • 13
  • 149
  • 217
0

There're different tools which can pack you program to single .exe file or make an installer. Here's my solution from 2016 year - Python - create an EXE that runs code as written, not as it was when compiled

Now it will be little easier :)

Eugene Lisitsky
  • 12,113
  • 5
  • 38
  • 59