Pyinstaller - How to handle multiple python scripts - python

I have a python script that calls other python scripts using subprocess.Popen. These other python scripts are located in different directories.
My end goal is to make the program executable using pyinstaller, in an attempt to make the code more secure.
One solution would be to import the other scripts, instead of using subprocess. In this way they would be embedded in the executable file and would thus be protected.
But importing them is not an option.
For this reason, I guess I also have to make the other scripts executable using Pyinstaller and use subprocess to call each executable.
I've read the Pyinstaller's Multipackage Bundles
but I'm not sure if this is what I need.
My question is, how can I call the other python scripts using subprocess (or call their executable) and at the same time protect their source code?

Related

How to bundle together data files for converting python scripts to exe using py2exe?

I need to package all the scripts into an exe to be run on windows. The code is written in python 3.6 and has imports from xlsxwriter, win32com.client, time and tkinter. The execution of the scripts is such that starting with the main.py file, calling functions from login.py by importing the module, accessing the login_cred.db for validation, and then the generate_costing.py executes through there. DesignList is a pickled list that is critical to the program. generate_costing.py also imports design_list.py for some utility functions.
Refer to this image:
Now all of these scripts have to be packaged into an exe and/or dll files (not sure about how it exactly works), but majorly need to hide the contents of the scripts too, while being able to run the whole code through a single .exe file on windows if possible.
Totally at a loss here, newbie to py2exe and looking for whatever approach is possible.
Maybe you can try pyinstaller and use command pyinstaller --onefile main.py
The easiest way to do it is to use pyinstaller and use the --onefile argument :
pyinstaller --onefile foo.py
But if you are not comfortable with pyinstaller, you can use auto-py-2-exe that provides a graphic interface to compile your script

Run generated .py files without python installation

I am coding a PyQt5 based GUI application needs to be able to create and run arbitrary Python scripts at runtime. If I convert this application to a .exe, the main GUI Window will run properly. However, I do not know how I can run the short .py scripts that my application creates. Is it possible to runs these without a system wide Python installation?
I don't want ways to compile my python application to exe. This problem relates to generated .py scripts
No, to run a Python file you need an interpreter.
It is possible that your main application can contain a Python interpreter so that you don't need to depend on a system-wide Python installation.
No, it won't work. But you can make a small tool that will load the scripts and eval them within the context of packed executable. Look here for more details. One thing to be mindful of is that your eval executable should import all the dependencies needed by your generated .py files

How to run Python from current directory

I have written a Python script that I need to share with folks who may or may not have Python installed on their machine. As a dirty hack I figured I could copy my local Python3.6 install into the same folder as the script I made, and then create a .bat file that runs python from the copied Python source ie.
Python36\python.exe script.py %*
In this way I could just send them the folder, and all they have to do is double click the .bat file. Now this does work, but it takes about 2 - 5 mins for script.py to begin executing. How could I configure the copied python source so that it runs like it "should"?
In terms of speed that is little you can do. You could convert your Python script into a compiled extension, this increases speed of a Python script greatly. Cython can do this and once compile you then do as you have done already.
Honestly you will notice little difference if you do this, and that is about the best you will do with that method. A better method is to turn it into an executable directly.
What you are doing currantly is:
The batch command starts and executes (this is slow by itself). This starts the Python interpreter.
The Python interpreter loads the file and then starts.
You should use a tool such as Cx_Freeze or Pyinstaller to convert your script into an executable, then it could be run just like any other appliocation. You could also use Cython to achieve this.
You can use installers as well.
Are you using any libraries? A quick solution would be converting the python script to executable using py2exe. More details are also in this post.
from distutils.core import setup
import py2exe
setup(console=['sample.py'])
And then run the command
C:\Tutorial>python setup.py py2exe

Getting an executable from Python scripts + bash + data files

I am trying to get an executable file from Python script (MAC OS). But the thing is I'm not in the simplest case : I have a main Python script calling a bash script, and the bash is calling other python files. Plus those scripts need data files (pickle and csv files). Furthermore, I don't know if it's important but my code is creating other datafiles for using them afterwhat.
Is it even possible to get an executable from that? I tried with py2app and pyInstaller:
With py2app I think I understood how to pass data files and python scripts to setup.py, but what about the bash? I pu it with the python scripts in the option "py_modules" or with the data files and it's never working
With pyInstaller I didn't even find how to pass several python scripts, I tried to import them in the main file but it didn't work.
So does someone have an idea?
Thanks a lot,
Marie

Can the Python interpreter and Python app source code be embedded into a compiled program?

I want to put the Python interpreter and all the source files of a fairly large Python application with multiple .py files into an executable Linux file.
Thus when running the application, the Python interpreter will run the Python source code that is embedded into the executable.
Using Python 3.
Is such a thing possible?
Edit: in addition to the selected answer another option is to use Cython.
Sounds like you're looking for a packaging module, like py2exe or cx_Freeze (I prefer the latter). They bundle the interpreter and your files together so that a machine without an installation of Python can run your program.

Categories

Resources