Reputation:
Im working on a python project of mine and i wanted it to be able to run like a application. so i made a gui for it and i want to distribute it for other people to use. but i used packages like requests and tkinter. how would i make the program more portable? so people could just click on the .py file and my gui would just come up.
#!/usr/bin/env python3
# imports
import requests
import time
from tkinter import *
import random
# variables
test = 'https://api.nicehash.com/api?method=stats.provider.ex&addr=37sCnRwMW7w8V7Y4zyVZD5uCmc9N1kZ2Q8&callback=jQuery111304118770088094035_1506738346881&_=1506738346882'
url = 'https://api.coinbase.com/v2/prices/USD/spot?'
# def function to update
def update_bitcoin_ui():
# update the data sourced form the website
req = requests.get(url)
data = req.json()
bit = (data['data'][0]['amount'])
# update the gui to reflect new value
thelabel.config(text = "1 BTC = %s USD" % bit)
# verify the Ui is updating
#thelabel.config(text=str(random.random()))
root.after(1000, update_bitcoin_ui)
# gui workspace
root = Tk()
thelabel = Label(root, text = "")
# set more of the gui and launch the ui
thelabel.pack()
root.after(1000, update_bitcoin_ui)
root.mainloop()
EDIT: i found what i was looking for. i was looking for something to the effects of pyinstaller
Upvotes: 2
Views: 463
Reputation: 724
You could do this in a few ways.
Use something like GitHub. Register then create a repository. Users can the go to your repository (https://GitHub.com/username/repo_name
) and download it through their browsers. Alternatively, *nix users can do git clone https://GitHub.con/username/repo_name
.
Or, upload your script to PyPi. You can then do pip install [package name]
on Windows/*nix, and dependencies will automatically be installed. Read how to do so here.
If you're simply looking for an easy way to install dependencies:
You could use requirements.txt, which is a text file with all of your dependencies. The user can then do pip install -r requirements.txt
, and all of your dependencies will be installed.
Or, you could create a setup.py
. It would have information such as your dependencies, author ect. The user can then install it with python setup.py install
.
Finally, you could simply make a try/except statement like this:
import pip
try:
import module
except:
pip.main(['install', 'module'])
BUT WAIT! Maybe your user doesn't have Python. Nobody wants to install all that just for a few uses. In that case, you can check out Py2Exe.
Upvotes: 1