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
Related
stack overflow has been a great source since I first started learning Python, so wanted to thank the community... anyways first time poster.
I'm new to python so excuse me as my terminology may be a bit off.
I have a script that uses pandas read excel. I give it a xlsx doc name and it finds the file in the same folder as the script.
I can run my script fine from my terminal.
Using pyinstaller, I can run the script fine from a windows pc as an exe.
When I try to run the pyinstaller's unix executable, on mac, the read excel function fails to find the doc and cwd function returns (user/myname), rather then using the same directory as the executable.
Am I doing something wrong here or should I be adding something to help the executable find the file? Any help would be greatly appreciated!
Script works fine if I move the file to my user/myname folder, but I would assume since the pandas function isn't given a specific directory to check, it should just be checking the folder I run the executable from?
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?
I need to make executable file on OSX/Mac. I have python3 script that uses excel file. Executable file also should be able to work just by double clicking the icon and also have python packages. I mainly work with Ubuntu18 but have access to Mac for few days.
What I've tried so far:
I've written a short bash script that activates python environment (with "source activate" command) and runs python script. Appified the script with this: https://gist.github.com/anmoljagetia/d37da67b9d408b35ac753ce51e420132
I know that terminal commands work but double-clicking the app in Mac does nothing.
With pyinstaller converted bash+python script to exe, then with wine tried converting that to executable program but that double-clicked program does nothing.
Tried py2app, but in the mac terminal it says "cannot execute binary file".
Does someone have any recommendations for my problem? As I've mentioned there are few main requirements:
works by double-clicking
works on mac
has all python packages
is able to read specific excel file (I will know the name of it, but just path may be confusing in some versions, because I would like to use relative path or something like [pwd]/file.xlsx)
Anyway, I'm having most problems with the first two points but don't want to forget the last two.
Thank You for help!
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
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.