What is the best way to share a python application with someone who isn't a dev [duplicate] - python

This question already has answers here:
How can I run a Python project on another computer without installing anything on it?
(6 answers)
Closed 9 months ago.
Problem:
I need to send someone (who has little to no computer knowledge) a python program, but I don't even know if he has python installed let alone all the dependencies.
Question:
Assuming he doesn't have python, how should I go about sending the application so that It is as straightforward as possible for him?
What I've tried:
Initially, I thought of using venv and sending him the whole thing, but there has got to be a better solution, as my code only uses two of the built-in libraries.
In my research, I came across Docker, but I think he would need to have that installed. I also saw pipenv but it wouldn't work without python on his PC.

You have multiple ways to do so:
Create an executable file, which is quite a long process but can be useful is you project contains a lot of files and multiple dependencies
Send them the python code (I recommend it if your project fits in one .py file). The person will need to install python and possibly a few pip libraires, but it's not extremely complicated in my opinion, with clear instructions.
Finally, you can go on repl.it and create a repl, which is simply a way to execute code on your browser. I think this is the best option for both large and small projects, except if it contains a lot of odd dependencies, and I'm not sure if repl.it supports graphical interfaces either. Anyway, you should take a look, it might be perfectly fit your needs

Related

How to package/ distribute python applications

I've spent countless hours trying to understand this and unfortunately I haven't gotten to an answer yet. Or at least I don't think I have.
First up I should say that I am a Java Developer. I've only recently started working with Python and the build-process is a bit...odd for me.
In my mind I write an application, I compile it to run and I package it into a .jar for other people to use. Either as a library or for end-users to execute and have fun with it. (ignoring stuff like maven or gradle...)
I wrote a little CLT in python that consists of ~6 files and I wanted to distribute it. From what I could find I was supposed to write a setup.py and I found some guides on how to do that but ... to be honest I'm not even sure what that did. I could get my source code bundled into a tar.gz with some other meta data or it would create some weird files that I don't know what to do with.
Then I found PyInstaller and it worked great to package everything into a binary. However I've run into some problems trying to create a Debian package and it has made me re-assess and question the fact that there doesn't seem to be something in Python (without having to use an external tool) that lets me package/ bundle/ whatever my application into a single file to be run.
And that's something I can't get my head around. I mean...before there were tools like PyInstaller and P2Exe and what not, how did people distribute their applications? Am I expected to write a C application, somehow include the python code in there and compile that? Sorry if this seems like a stupid question but I'm really asking. I've googled around so much and spent so much time on it and haven't found a satisfactory answer so I hope someone here can help me with this! Thanks.
If you package your Python code for pip, you can include some executable scripts that start your program. I don't know how the situation was 5 years ago when this question got asked, but nowadays pip is pretty much integrated with Python, to the point that there's a standard library module to bootstrap pip in case it's missing:
https://docs.python.org/3/library/ensurepip.html
The situation is different if you want to package an application for some other package manager, like Anaconda or the package managers of various Linux distributions, or as a Windows installer. Obviously, you'll have to create a separate package for each package manager or installation technique you want to support.

Python - Compiling/ securing as standalone executable [duplicate]

This question already has answers here:
How do I protect Python code from being read by users?
(29 answers)
Closed 9 years ago.
I'm rather new to Python, though hope to use it for both programming and scripting. I've written basic scripts, and did some digging for compiling. I'm currently using py2exe (With a different setup.py script someone else made) so that it becomes ONE simple .exe, without dependencies (python DLL, etc.)
You're probably wondering what my problem is. Well, I decided to check the security of the executable, and view it in Resource Hacker. I was able to view all the parts of the script I DIDN'T want people to be able to find out. (Ex: Password inputs).
Can anyone give me a simple, working method, for converting PYTHON code to a STANDALONE executable that CANNOT allow viewing of the original python script via something like Resource Hacker?
I am not thoroughly knowledgeable in the field.. I'm also not developing commercially (Yet), I just want to make things for myself, that I may also make for other people.. Though I might freelance for random people online doing things. Anyways point being, if I had a script where it prompted you for a password, and if you got it correct it continued, else, it cancelled and exited.... then once I make it a .exe, opening in Resource Hacker, and viewing the "Python Script", I scroll to the bottom, and bam! It shows the passwords. Now when I say I'm new, I mean, really REALLY new. Anyways, if you don't mind explaining, "Encryptions", "Hash's", etc... I would prefer to be enlightened towards these subjects.'
Your help is appreciated.
Here are the simple steps (with freeze)-
You will need to use a python installation which has all its modules installed as shared libraries
freeze.py usually resides under <python_install>/Tools/freeze/freeze.py
e.g: Python-2.4.2/linux/Tools/freeze/freeze.py
Now to integrate freeze a very simple program, which does not have dependency on any custom python module you will just need to call freeze in this fashion:
e.g:
cat hello.py
#!/usr/bin/env python
print "Testing"
To Freeze:
a. Python-2.4.2/linux/Tools/freeze/freeze.py hello.py
b. make
you will see there is a executable hello.
file hello
hello: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.4.0, dynamically linked (uses shared libs), not stripped
that's it:
now invoke hello will produce:
[0:22:47]% ./hello
Testing

How to package a python program for distribution on a network

I'm not sure if I'm even asking this question correctly. I just built my first real program and I want to make it available to people in my office. I'm not sure if I will have access to the shared server, but I was hoping I could simply package the program (I hope I'm using this term correctly) and upload it to a website for my coworkers to download.
I know how to zip a file, but something tells me it's a little more complicated than that :) In fact, some of the people in my office who need the program installed do not have python on their computers already, and I would rather avoid asking everyone to install python before downloading my .py files from my hosting server.
So, is there an easy way to package my program, along with python and the other dependencies, for simple distribution from a website? I tried searching for the answer but I can't find exactly what I'm looking for. Oh, and since this is the first time I have done this- are there any precautions I need to take when sharing these files so that everything runs smoothly?
PyInstaller or py2exe can package your Python program.
Both are actively maintained. PyInstaller is actively maintained. py2exe has not been updated for at least a year. I've used each with success.
Also there is cx_Freeze which I have not used.
Take a look at http://www.py2exe.org/

Best Practices in Handling Modules Prerequisites

Recently I started working on a personal project in my notebook that, all going OK, it will be placed in a server elsewhere. The problem is that I make use of modules. Some were installed from apt-get, others from easy_install and one or two of those were placed directly under a subdirectory since I changed them a bit. My question is: is there a way to move all those things together? Moreover, I don't want any of those modules being updated since it may break something. How to handle that?
Finally, I'm pretty sure that I've done things the wrong way since the beginning. How do you guys work to avoid those problems?
Have a look at virtualenv. Virtualenv is a tool to create isolated Python environments.

Gather all Python modules used into one folder? [duplicate]

This question already has answers here:
Closed 13 years ago.
Possible Duplicate:
Gather all Python modules used into one folder?
I don't think this has been asked before-I have a folder that has lots of different .py files. The script I've made only uses some-but some call others & I don't know all the ones being used. Is there a program that will get everything needed to make that script run into one folder?
Cheers!
Since Python is not statically linked language, this task would be rather a challenging one. Especially if some of your code uses eval(...) or exec(...).
If your script is not very big, I would just move it out, make sure that your python.exe does not load modules from that directory and would run the script and add missing modules until it works.
I you have multiple scripts like this, then this manual work is not really the way to go. But in this case also having lots of different .py files in a directory is not a good deployment technique and you should think about packaging them into installable modules and install into your python site-packages.
Still you may use snakefood package to find our the dependencies (has already been discussed here). Again, it just cannot be 100% accurate, but should give you an easy start.
you should be able to extract the needed information from a so called call graph
See for example
http://pycallgraph.slowchop.com/ or
http://blog.prashanthellina.com/2007/11/14/generating-call-graphs-for-understanding-and-refactoring-python-code/
Also, py2exe converts a python call into an executable and in this process it gathers all used modules. I think py2exe is cross platform
I'd try 2½ solutions, one elaborate and 1½ quick-and-dirty:
elaborate: a custom import hook, logging all imports
quick and dirty, part a: os.utime the *.py[co]? (re notation, not glob) files to having access times of yesterday, then run the program and collect all recent access times. Prerequisite: a filesystem that marks access times (by itself and by its mount options).
quick and dirty, part b: remove all *.py[co] files (same in glob and re notation), run the program, see which have been created. Prerequisite: user should have write access to the folder.

Categories

Resources