Hi as a python newbie I have written a small python application that can convert an excel worksheet into a sqlite database table. Its not a terribly complex application but it does make use of external modules/package like xlrd (http://pypi.python.org/pypi/xlrd) which I had to download and install when writing my app.
Now that is all done I would like to distribute it amongst my friends, all windows users, while they have python on their machines, they may or may not have the xlrd modules.
I would like to package my app, make sure it includes everything that it needs to run, and share the final .zip file with my friends so they can use the application. Is there a good tutorial that covers how to package a python application, with all the necessary external modules/packages, so that another windows user, can easily run my application.
I keep hearing about disutils, can anyone point me to some good tutorials, or any other python packaging tutorials that show how to get everything into a simple easy to distribute file.
Many thanks
Note: I also want to include the sqlite database file with my application, so the end user doesn't have to worry about anything
First download Pyinstaller and save it somewhere. Then, if you're running Python 2.6 or 2.7 go and install pywin32.
Go create a directory for your output file.
Open Command prompt and enter the fallowing:
python path/to/pyinstaller/pyinstall.py file/to/be/converted.py --onefile
If you want to add an icon, add the --icon argument.
If you want it to hide the CMD window add the --windowed argument.
So if you wanted it to use an icon and hide the CMD window it would look like this:
python path/to/pyinstaller/pyinstall.py file/to/be/converted.py --onefile --icon="path/to/icon.ico" --windowed
The --onefile argument makes the saves everything into one file, without it, the output would be would be a lot of files.
The output is saved in the "dist" folder in the directory it was using.
After you convert the python script in to an .exe, put it in a .zip file along with any other files you need (in your case the squite database file) and you can give it to anyone without them needing to have Python at all.
If you want a program to do this all for you, you can download a program called PTEC.
Related
I need to make a way to install my code, and set default programs depending on file type.
I've been trying to make my python program easy for people who know nothing about python or programming to use.
As an alternative to an exe I want to make a script to do everything, including putting a shortcut to the python code on the desktop and a start menu folder.
The thing is I need to make sure that .py files automatically hey opened by python, and not the software, psychopy, which the user will install.
Is there a way to use python to change the default program for a given file type?
I've already tried:
Py2exe: I get errors (see post history)
Pyinstaller: I get different errors.
The errors with py2exe seem almost irresolvable.
I've used pyinstaller before and it worked. It won't easily work with this code because it doesn't work with an updated library/package I need. I have library b which depends on library a being up to date. So I can't revert back to a setup that I know how to make work.
A little bit of context:
I have made a password manager in python
I then packed it into a single executable using:
pyinstaller --onefile password_manager.py
Okay first I want to specify that the script works properly when I run it through the password_manager.py file, the executable version also runs properly and when I e.g. create a user and I save the data in a new json file. I'm able to access it on runtime but when I actually close the shell and the program stops running it's like the data has all been lost and or deleted. I'm looking for a way for the required data to remain on my drive like they do when I run password_manager.py on its own.
P.S.
I can view hidden files in my computer too.
P.S.S.
The link to the code is here: code
My file structure when I run it through password_manager.py
Here is the executable showing some random Data I recently added without closing and restarting the program. These information was supposed to be stored in /data/users.json and /data/password (and is stored there when I just use password_manager.py) but when I actually exit the application they are not present in any way when I rerun the executable(neither the directories that were supposed to be created nor the files).
Simple replication:
#mkdir.py
import os
os.mkdir("stack")
shell:
pyinstaller --onefile mkdir.py
I also sadly couldn't find a way to include the executable in this question but you can replicate it with the given command.
I am doing an application in Excel and I'd like to use python language. I've seen a pretty cool library called xlwings, but to run it a user need to have python installed.
Is there any possibility to prepare this kind of application that will be launch from a PC without Python?
Any suggestion are welcome!
A small workaround could be to package your application with cx_freeze or pyinstaller. Then it can run on a machine without installing python. The downside is of course that the program tend to be a bit bulky in size.
no. you must need install a python and for interpreting the python function etc.
It is possible using xlloop. This is a customized client-server approach, where the client is an excel .xll which must be installed on client's machine.
The server can be written in many languages, including python, and of course it must be launched on a server that has python installed. Currently the .xll is available only for 32 bits.
This might not be exactly what you're looking for (i.e.- "without python"), but you could ship it as a virtualenv .zip folder with all the necessary packages and respective python installation included in the folder... and also include a run.command bash executable inside the folder that the user can click on to run your program. You'll have to tell the user (inside a README.txt or something) how to enable the executable... For a particular application mine looked like...
Please complete the following steps after installation of MyApplication.zip:
Step 1: Move the MyApplication folder to your Desktop.
Step 2: Open your Terminal in Go then Applications then Utilities.
Step 3: In the Terminal, paste cd ~/Desktop/MyApplication
then press Enter.
Step 4: Then, paste chmod +x run.command
then press Enter.
From now on, clicking the “run” file in MyApplication will run the application.
If clicking the “run” file still doesn’t work, then do…
Click Ok on the popup then Open System Preferences then Security & Privacy
then Click on Open Anyway button then Click Open button on the popup.
NOTE: Please do not move or delete the MyApplication folder, or any of its files.
Then my run.command executable looked like the following:
cd ~/Desktop/MyApplication
PATH=$PATH:$HOME/Desktop/MyApplication/lib/python2.7/site-packages:$HOME/Desktop/MyApplication/lib/python2.7/site-packages/aeosa:$HOME/Desktop/MyApplication/lib/python2.7/lib-dynload:$HOME/Desktop/MyApplication/lib/python2.7/lib-old:$HOME/Desktop/MyApplication/lib/python2.7/lib-tk:$HOME/Desktop/MyApplication/Extras/lib/python:$HOME/Desktop/MyApplication/lib/python2.7/plat-mac/lib-scriptpackages:$HOME/Desktop/MyApplication/lib/python2.7/plat-mac:$HOME/Desktop/MyApplication/lib/python2.7/plat-darwin:$HOME/Desktop/MyApplication/lib/python2.7:$HOME/Desktop/MyApplication/lib/python27.zip
source bin/activate
python main.py
Three things are important here:
1) In run.command, I first change directory into the virtualenv I created for this project. I'm not trying to be dynamic here, since this is all just a quick hack of a solution, so as part of the README.txt, I simply tell the user to put the folder they downloaded onto their desktop. Otherwise, the cd command wouldn't work.
2) I set the client's PATH variable, separating entries with colons. You can see a list of the paths you'd need using a quick check on your computer...
import sys
for path in sys.path:
print path
3) I then call source bin/activate to activate the virtualenv.
4) I then execute my main.py file, which is in the top level of my virtualenv, along with run.command.
5) I only wrote this bash file for Mac OS X, so I don't know how it would translate to windows PCs. I think the only thing that'd change is that the path literals would need to use backslashes instead of forward slashes, but again, I haven't done this for windows so I'm uncertain.
Read more about setting up a virtualenv here: https://virtualenv.readthedocs.org/en/latest/index.html
Finally, note that you will not be able to send your final, working .zip folder over most email services, since they tend to prevent people from sending executables back and forth, so you'll have to use a service like Dropbox or something to send it to people.
So I created a fairly intricate python script with a tkinter GUI that creates many user-defined text files and uses them to create and run a batch script as a sub-process which in turn creates multiple XML files that I parse for data and write to a final, single excel file using xlsxwriter.
Bottom line is this script works flawlessly on my personal machine and has file paths hard-coded into it all centered around a root folder on my desktop. For the sake of my machine, this script is great and does what it needs to do. Now, I want to get this distributed to other computers using an installer that removes necessity to have all external dependencies. I see that py2exe is a useful tool for incorporating these modules (like xlsxwriter) but I'm not sure about how to go about creating an installer that gets rid of hard coded file paths.
Essentially, I want to create something that asks the user to select where a certain program is installed on their computer (this path is used to find the location of an exe written to my batch file. For the sake of distribution, assume every computer that is installing my application has this program installed in something like C:\Program Files\Blahblah) and then asks the user where they want to install my program. Since the script creates and destroys many files during its lifetime, I want this folder to basically act like the folder I have on my desktop right now as the "root directory" of my application. I want to know the best practice for implementing and creating an installer for these file paths into my python application to make the script easy to distribute to any computer running Windows. Thanks!
I have written a python script with a Tkinter GUI. I would like to create a desktop icon that will execute this script so that the end-user (not myself) will be able to double-click the icon and have the GUI load, rather than 'run' the script from the terminal or python shell and then have to F5 from there.
Is there a way to do this? I have googled many arrangements of my question but most answers seem to be normal python scripts, not ones which are Tkinter based.
I am using a Raspberry Pi with Wheezy and Python 2.7
Thanks in advance.
I create executables(icons that I click to start the programs I write) using 'py2exe'. I use windows 7 and I am not sure if it would work for you with Raspberry Pi, but a google search may clear that up for you. I will provide the link below. Basically you end up with a folder with the executable(icon) and also some files, without which the executable won't work. It's unfortunate that you get this extra 'baggage', but it's still handy and the best solution I have come across. I don't think there is a much better way, but I am not 100% on that. Interestingly, I found that you could delete most of these baggage files and the executable would still work, it was trial and error, but it didn't take long. If I want to send the folder to someone, I zip it first.
py2exe is here
If you need a 64 bit binary you can get it here, along with, actually, pretty much every other version. get py2exe here also
Besides creating executable file other option is create simple .bat file:
Open notepad
Enter "C:\ProgramData\Anaconda3\python.exe" "C:\Users\Your ID\script.py"
First part is path to python.exe, second to your python script
save file as .bat file, ex. "open_program.bat"
Now simply double click on saved .bat file icon should open your script.
I like using cx-freeze to convert python scripts to exe.
There is very easy to follow documentation to do this. In short, you create a setup.py script that specifies what libraries and packages you want to include or exclude in your application.
You can then run the build in the console and it will create a build folder, in which will be an Application File. You can create a Desktop short cut using send to and selecting desktop.
Documentation link
You can save the script as a .pyw file so the user can click on the file and the GUi would open