Python Forum
Can a module be executed even if the computer running it does not install it?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can a module be executed even if the computer running it does not install it?
#1
Hello, I'm French, so sorry for the spelling mistakes.
I ask myself a question about the modules:
if for example I make a game with pygame and I give the game to a friend, will he be able to make it work without having installed it in advance ? Huh

Thank you in advance for all the answers you can give me . Smile
Reply
#2
This may help: https://stackoverflow.com/questions/1436...installing
Reply
#3
The easiest way to do that is to create an exe file with PyInstaller which will bundle Python and Pygame into it so the end user does not need to do anything other than run it.

You can just copy the Pygame libs over, but that is prone to error. If you dont know what your doing it can just simply not work with odd errors. I would not suggest this method.
Recommended Tutorials:
Reply
#4
To do a test using @metulburr pong example here.
Build in a virtual environment,so all install of Pygame and Pyinstaller is new.
Full run:
# Make environment
E:\div_code
λ python -m venv pygame_env

# Cd in
E:\div_code
λ cd pygame_env\

# Activate environment
E:\div_code\pygame_env
λ E:\div_code\pygame_env\Scripts\activate

# Install
(pygame_env) E:\div_code\pygame_env
λ pip install pygame pyinstaller
Collecting pygame .....  
Successfully installed altgraph-0.17 future-0.18.2 pefile-2019.4.18 pygame-1.9.6 pyinstaller-3.6 pywin32-ctypes-0.2.0

# Build with Pyinstaller
(pygame_env) E:\div_code\pygame_env
λ pyinstaller --onefile pong.py
148 INFO: Python: 3.7.3
149 INFO: Platform: Windows-10-10.0.18362-SP0
.....
14637 INFO: Appending archive to EXE E:\div_code\pygame_env\dist\pong.exe
14679 INFO: Building EXE from EXE-00.toc completed successfully.

# Cd to dist
(pygame_env) E:\div_code\pygame_env
λ cd dist

# List files use dir for cmd
(pygame_env) E:\div_code\pygame_env\dist
λ ls
pong.exe*

# Test run and it work
(pygame_env) E:\div_code\pygame_env\dist
λ pong
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
side wall hit, time to reset ball and give points
So it works,for more advance games with a addition data file like image/sound ect... may need to add this in build process.
Pyinstaller has good documentation about this.
Example on how that would look:
pyinstaller --onefile --icon=sound.ico --add-data shoot.png;. pong.py
For more addition can also use spec file that Pyinstaller create on every run.
Reply
#5
Yes but PyInstaller is a program so I have to install it so I always have the same problem, there would be no way to execute a command in a console from a python program (to execute the installation of the desired module)?
  I suppose I have to import the os module, but I think it is present in the language?
Reply
#6
(Feb-08-2020, 01:35 PM)CFYB Wrote: Yes but PyInstaller is a program so I have to install it so I always have the same problem
Yes you have to do pip install pyinstaller,and build as i have shown over.
You said you want to share with your friend so if give him pong.exe(you can test run it) just double click in on pong.exe file and game start no installation for him.
(Feb-08-2020, 01:35 PM)CFYB Wrote: I suppose I have to import the os module, but I think it is present in the language?
No,i have no idea what you talking about here?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to not open the context menu if a mouse gesture is executed? MicheliBarcello 2 661 Aug-22-2023, 02:47 PM
Last Post: deanhystad
  return next item each time a function is executed User3000 19 2,276 Aug-06-2023, 02:29 PM
Last Post: deanhystad
  code not working when executed from flask app ThomasDC 1 876 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  can I setup another IP for my computer while running app? korenron 3 1,035 Oct-30-2022, 08:48 AM
Last Post: korenron
  Can't install nor import delorean module Tek 3 2,796 Oct-27-2021, 03:32 AM
Last Post: Tek
  How do I locate setup.py in my computer, or install the file? JaneTan 1 1,731 Aug-26-2021, 08:37 AM
Last Post: snippsat
  Unable to install module rrowhe4d 1 2,278 Oct-13-2020, 10:20 AM
Last Post: Larz60+
  trying to pip install stasm module getting error djf123 3 4,492 Jul-26-2020, 05:00 AM
Last Post: millpond
  I don't get the order of how things are executed with main() pythonrookie 5 2,560 Jul-21-2020, 01:35 PM
Last Post: pythonrookie
  Install thresding module kalvarix 2 2,182 May-04-2020, 03:25 PM
Last Post: kalvarix

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020