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.
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?
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.
Add Python 3 to your friends machine to execute your program.
What'is the utility to run such a small program on their computers?
The way you propose won't work.
Windows does not know about shebangs.
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.
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 :)
Related
I am new to Python. Please excuse me if my question seems stupid. I have spent a lot of time before posting this.
When I searched for shipping python interpreter with the applications, I found solutions including installing separate applications, using third party modules, etc...
I was thinking of more direct approach: I first install python interpreter on my machine (windows). Then I ship the installed python interpreter (copy and paste the folder) with the pyc file of my application. And finally I create a simple batch program that executes the interpreter and running the pyc file. In this case, the user can simply run the application by simply running the batch program. I have tried it and it worked.
Although this solution seems the most obvious and the easiest one, I am in a doubt about it because I cannot find any one mentioning it. Is there anything wrong with my solution? I usually create desktop applications for windows.
Thanks in advance.
Make a virtual environment for you application and then run run the command python filename.py --onefile --windowed while still being in the virtual env. activated,
My goal is to have a python script that I can giving to someone to run on their windows machine that does not have python installed. I do want to package it up in an exe because I want the underlying code to be easily read.
I am updating an old VBscript and I want to mirror it. I am also using a few libraries.
use pyinstaller to package it up to an exe. You can still maintain your source code. Packaging it up wont remove your source code.
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 finally got py2app to work, and my program was made. However, it won't open because it relies on the terminal and raw_input. I just found out py2app is more for GUI interfaces.
All I want, is to turn the program into an application my users can click on, and it'll open in Terminal. Without them having to either install Python, or go to the terminal and type python "filename" (also, don't they have to set up the paths and everything to do that?).
Please help; I've been pulling my hair out all day looking for the answer. If this isn't possible, I'm just going to give them the .py file and instruct them to start it with python in the terminal and hope it's already set up so they can do that.
I know that on a mac you change the extension of the file to .command and that will make it so you can just click on it and it will run through the terminal if that's what it is specified to do. However I'm not sure if it will work if they do not actually have python installed.
Using PyInstaller http://www.pyinstaller.org/ it's possible to make an executable for different platforms. I believe OSX is supported.
I'm soon to launch a beta app and this have the option to create custom integration scripts on Python.
The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present.
My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and the path is not set when use the command line options. And I fear that if Python is installed before and I upgrade to a new version this could break something else...
So, I wonder how this can be done cleanly. Is it OK if I copy the whole Python 2.6 directory, and put it in a sub-directory of my app and install everything there? Or with virtualenv is posible run diferents versions of Python (if Python is already installed in the machine?).
I also play before embedding Python with a DLL, and found it easy but I lost the ability to debug, so I switch to command-line plug-ins.
I execute the plug-ins from command line and read the STDOUT and STDERR output. The app is made with Delphi/Lazarus. I install others modules like JSON and RPC clients, Win32com, ORM, etc. I create the installer with bitrock.
UPDATE: The end-users are small business owners, and the Python scripts are made by developers. I want to avoid any additional step in the deployment, so I want a fully integrated setup.
Copy a Portable Python folder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.
You might try using py2exe. It creates a .exe file with Python already included!
Integrate the python interpreter into your Delphi app with P4D. These components actually work, and in both directions too (Delphi classes exposed to Python as binary extensions, and Python interpreter inside Delphi). I also saw a patch for Lazarus compatibility on the Google Code "issues" page, but it seems there might be some unresolved issues there.
I think there's no problem combining .EXE packaging with a tool like PyInstaller or py2exe and Python-written plugins. The created .EXE can easily detect where it's installed and the code inside can then simply import files from some pre-determined plugin directory. Don't forget that once you package a Python script into an executable, it also packages the Python interpreter inside, so there you have it - a full Python environment customized with your own code.