How to run python script from desktop icon [duplicate] - python

What is the simplest tool to convert a python script into an executable file?
I made a python script and requirements.txt which contains necessary packages for a virtual environment with python3.6. I gave them to my client so that he can create a virtual environment and execute the file by executing the three lines below in the console.
source activate
python __main__.py
deactivate
Basically he needs to run it once a day, so that my python script scrapes a stock index data release at the end of each day and does some data transformation and saves the data in a desired directory as excel files.
However my client told me "even the three lines are difficult for people who are not familiar with CUI. Can you make it like a clickable icon?"
Is there any tool that can easily package my python script and required packages as an executable file or icon? It doesn't have to be cool. A simple and primitive tool would serve our needs. My client has Windows 10 Pro 64bit but it has to be something that I can develop in my My work environment which is Mac OS Catalina.
Thank you!

Yes, it is possible following library's help with this.
PyInstaller can be used, under Mac OS X, Windows, Linux,...
For an example i would read this medium post, it should contain everything to get you started.
py2exe can be used if you only want an executable for the Windows platform.

Related

Making executable file on OSX from a python script

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!

Run python script in Windows server 2016. Issues

I've created a project in Pycharm that is composed by 3 py scripts and requires a json file with authentication parameter to read files coming from google drive and finally a file to manipulate data in a sqlite table create on the fly.
That works super good in my computer and the server (windows server 2016 standard edition). I need to execute this program(script) whole days so I've tried with the script.py using cmdExec in SQL and Windows scheduler manager and it doesnt work. otherwise if manually in the server I perform double click that runs.
I realized that when I run the script manually the execution is
C:\path of folder where is the script> C:\whole path again\script.py
Otherwise from windows scheduler is always:
C:\windows\system32> C:\whole path again\script.py
How can I force to fix this path or probably if I can create a .exe of my project in pycharm that could work? But I've not found too much info about how follow this process.
If you want to create an exe you can use cx_Freeze or py2exe.
However, you could also try an other way (such as .bat file).
I think "pyinstaller" is the best choice. it can package a python program to an *.exe file. so you can execute this program om windows platform. And you don't need to install python on windows. office website is "http://www.pyinstaller.org/". it is easy to use.
note:pyinstaller don't support python3.6
hope to help you.
Hi guys finally after a research within our library contributions I found the follow link where another person shared the experience to create a bat file.
Finally following this post from another contributor I could figured out my issue and my bat scripts looks like:
#echo off
py -u "path\ReadFile.py"
echo %ERRORLEVEL%
Thanks everyone

Porting Python on Windows using pywin32/excel to Linux on Vagrant Machine

I have written an extensive python package that utilizes excel and pywin32.
I am now in the progress of moving this package to a linux environment on a Vagrant machine.
I know there are "emulator-esque" software packages (e.g. WINE) that can run Windows applications and look-a-likes for some Windows applications (e.g. Excel to OpenOffice).
However, I am not seeing the right path to take in order to get my pywin32/Excel dependent code written for Windows running in a Linux environment on a Vagrant machine. Ideally, I would not have to alter my code at all and just do the appropriate installs on my Vagrant machine.
Thanks
The short answer is, you can't. WINE does not expose a bottled Windows environment's COM registry out to linux—and, even if it did, pywin32 doesn't build on anything but Windows.
So, here are some options, roughly ordered from the least amount of change to your code and setup to the most:
Run both your Python script and Excel under real Windows, inside a real emulator.
Run both your Python script and Excel under WINE.
Write or find a library that does expose a bottled Windows environment's COM registry out to Linux.
Write or find a cross-platform DCOM library that presents a win32com-like API, then change your code to use that to connect to the bottled Excel remotely.
Rewrite your code to script Excel indirectly by, e.g., sshing into a Windows box and running minimal WSH scripts.
Rewrite your code to script LibreOffice or whatever you prefer instead of Excel.
Rewrite your code to process Excel files (or CSV or some other interchange format) directly instead of scripting Excel.

How to convert python .py file into an executable file for use cross platform?

I've been searching through SO for a while now trying to come up with an answer to this but due to my inexperience with programming I don't understand much of the documentation, nor am I confident enough to experiment too much.
Would anyone be able to describe in slightly simpler terms how I would use programs like Py2exe, PyInstaller, cx_freeze etc.? I just want a way for others (mainly friends) to be able to run my (simple, text only) program without having to download python themselves. If there is an easier way to do this I'd appreciate knowing that too.
Running Vista 32bit, python 2.7
There are two distinct ways of freezing python scripts to create executables:
Packing the interpreter and *.pyc files into one exe file-container. Such an approach is used by tools like PyInstaller, Py2exe, cx_freeze.
Creating native code from Python source, usually using a middle step of converting Python-source to C or C++ code. This is done by such tools as Shed-skin and Nuitka. The problem of this aproach is that such tools do not always support all the functionality of Python (e.g. they can have some typing limitations and so on)
The point where you have to start is reading the documentation. Such tools are not just push-and-run style tools, they usually have some configuration that must be implemented (that's the problem of possibly all build systems, and as the project grows, the configuration and number of hooks also grows).
You can start with Py2exe tutorial and 'hello-world' to get acquainted with that how compilation is done. As far as I know it's a simplest way to get your goal.
And the last thing, you can't create cross-platform native executables as their file formats are strongly operating system and hardware dependent.
Download py2exe
Download this msvcp90.dll
Copy your FileCode.py AND msvcp90.dll to C:\Python27\
In C:\Python27\ create new text file, then enter this code inside it:
from distutils.core import setup
import py2exe
setup(console=['Avril.py'])
Replace Avril.py with YourFileName.py
Save the file as setup.txt
Open CMD and type this:
cd C:\Python27\
python setup.txt py2exe
Now go to C:\Python27\dist\ and there's your .exe program.
Source: Manvir Singh
Python scripts can be made directly executable, like shell scripts, by putting the python environment path in the top of the script file.
#!/usr/bin/env python3.5
The Python installer automatically associates .py files with python.exe so that a double-click on a Python file will run it as a script. The extension can also be .pyw, in that case, the console window that normally appears is suppressed.
Detailed description also for linux is here.
Install pyinstaller, a program that converts .py to .exe for python 2.7 to where python is located:
cd C:\python27\scripts
pip install pyinstaller
then move whatever python file you want to compile to C:\python27\scripts, compile from there by using:
pyinstaller --onefile yourfile.py
the --onefile is optional but it packages the whole thing(in this example yourfile.py) into one .exe. Once everything is done there will be 2 new folders along with a .spec file. From C:\python27\scripts open the folder dist. Your .exe will be located there in one file which you can double tap to execute and distribute to anyone who doesn't have python. Hope it helps.

How to deploy Python to Windows users?

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.

Categories

Resources