How to distribute python software to users of low technical ability? - python

I have a python application (3.5) that I’m trying to distribute. It:
Uses no GUI libraries (it runs in the browser)
Uses several external packages (Flask, SocketIO, httplib2)
maintains saved config and data files inside the main source directory
The target users:
Use Mac or Windows
Do not understand the concept of the terminal/command line (testing has shown that it can take hours to teach users how to cd into the source directory to run a .py file).
Generally have little difficulty installing the python interpreter from python.org (but have great trouble starting and exiting the python console).
Are generally of very low technical ability.
Preferably, the app should:
be “click and play”, as I have found that typically the cd navigation is the biggest hurdle preventing users from running my application.
not require manually modifying any system settings
I am developing from Ubuntu Linux. I have access to a Windows VM, but not a Mac computer. How do I distribute my application?

There are a couple of applications that can help you to distribute a Python Application, for this case you want to take a look on Python freezing tools like py2exe (windows only) or py2app (MacOs).
This two will help you distribute your code without all the hassle of making the user to install the dependencies and run anything from the command line.
However if your application runs on the browser, you probably want to just put that into a server (take a look of openshift, it's free) it will make your life a lot easier.

Related

Cross Platform Python Executable - Mac & Windows?

I used pyinstaller to create an executable file (Desktop GUI). I am on Windows, and the person I am sending it to is on Mac.
I was under the impression that pyinstaller was cross platform, but the Mac user gets an error when trying to run the app. What are my options for distributing my GUI for both Windows and Mac?
I have not been able to find a straightforward answer and do not have a Mac to test with. I saw Inno Setup, but haven't found anything saying whether or not it's cross platform.
I need to create a script that can run both Windows and Mac. I am also looking for an easy way to send it electronically.
I have no knowledge of Python but after a quick serach on the internet came up with this which might help you.
A few months ago I went through this process (rather painstakingly I might add) to deploy a simple Xamarin Cross Platform App. In my own experience I have learned that the macOS has very strict rules about how software is to be packaged for deployment on a computer.
If you are using Visual Studio for Mac it will automatically build a packaged installer for you. But, you do have to purchase (at an yearly cost) a Developer ID.
Then, you create specific provision profiles for your application and these are used along with your developer ID to sign your packaged installer. I found it somewhat complicated!
Finally, you follow a procedure via the console on the mac to submit your package for an automatic scan. This is referred to as getting your package notarized (link to a SO question about that process).They provide you a result that then gets stapled to the package.
It is like a double signing. Once this is done then the package can be installed by users using the macOS.
An alternative is that the user run a instance of Windows by using a software package called Parallels. I have to say it is very good and I did enjoy my trial of the software, You can fire up Windows from inside the macOS (no need to reboot) and since it is Windows you can simply run your stahdard installers.
In summary, for the macOS, if you do not correctly sign your package with a developer and application ID, and don't get it notarized and stapled the operating system will throw it back out at you and not run it.

Creating mac os x software bundle with java processing and python

I have writing a program using Java Processing.org programming language and it uses some python scripts. Circumstances exist that I cannot change or re write these python scripts in processing.
My problem is I need to bundle this all together and create software bundle for Mac OS X for easy installation. I know there is option in Processing IDE to create software bundles but that will ignores the python files, even so client's machine could not have python installed.
I thought about creating python executable and putting it in to the bundle. Could anyone suggest me better options or software tools to do this.
Regards,
Waruna
Python is shipped with Mac OS X, so your clients should be able to run the scripts.
You do not need to create a "Python executable" as the Python interpreter can just run the .py files.
A Mac OS X application bundle (essentially being a folder) contains a folder Contents which in turn contains the binary application files, resources, etc. You can place your .py files within the .app bundle and call them from within your Java code.
The bundle documentation is available here http://developer.apple.com/library/mac/#documentation/CoreFoundation/Conceptual/CFBundles/Introduction/Introduction.html
It sounds like you're trying to deliver some Python modules in a user friendly manner (i.e., without the end users having to know about easy_install or whatever).
I am no expert in this area, but it seems to me like you're trying to solve a similar problem that the Mercurial people solved, you may want to have a look at what they did. This is how Mercurial is delivered on the Mac - http://mercurial.berkwood.com/.

How to run a Python program on a Windows server without having Python installed?

So I wrote a Python script which does some simple stuff. It was originally going to run on a Unix server but due to crappy network security settings which TPTB refuse to change, we need to run it on a Windows server instead. However, the administrators of said Windows server refuse to do anything helpful like install Python.
What are my options for running a Python script on Windows without Python?
Consideration 1:
Something like Py2Exe - I found this after a quick Google search and it seems promising. From what I can tell, it'll generate a bunch of files but we can just xcopy that directory to our Windows machine and it will be completely isolated and not have any external dependencies. Does anyone have any insight on how well this works? Obviously, it depends on my Python script but fortunately this script is quite simple and only uses built in Python libraries such as urllib2 and urlparse.
Consideration 2:
We can assume the Windows server has at least some version of the .NET Framework installed too, which brings IronPython to mind. I've never used this before, but I've always wanted to. From what I can tell, it will compile Python code into CLS compliant IL code which can be run natively under the .NET runtime. However, does this require additional .NET libraries to be installed on the server? Can I just bundle those DLLs with my program? Or, does it require I rewrite my Python script to call into .NET Framework specific classes instead of using things like urllib2 or urlparse?
Thanks!
PS - The ironic part: I actually barely know Python and I'm a .NET expert, but I wrote the script in Python because I was told it would run on a Unix server. Had I known we'd end up running this on a Windows server, I'd have written the thing in C# to begin with in about 1/10th of the time. Fail.
Will they let you copy executables onto the server at all? If so then you should be able to do a non-admin installation of Python or use Portable Python which can just be copied into a folder without any installation at all.
Nothing wrong with Py2exe, but it does mean you then have to build the script into a fresh executable each time you update it. Also Py2exe has a slightly longer startup time than a Python interpreter because it has to extract the Python dlls into a temporary folder each time it runs; that only matters of course if you run your script a lot.

Python on IIS: how?

I've got a background in PHP, dotNet and am charmed by Python. I want to transpose functionality from PHP to Python step by step, running bits and pieces side-by-side. During this transition, which could take 2 years since the app is enormous, I am bound to IIS. I've got 15 years background of web-programming, including some C work in an ISAPI module on IIS which is the kind of work I don't want to dive into any more.
It seems Python just doesn't run well on IIS. I've struggled with FastCGI (not supported, just for PHP) and PyIsapie (badly documented, couldn't get it up and running). In the end I got it up and running with a HeliconZoo dll BUT:
My next problem is: how to debug/develop a site? In PHP you install a debugger and whenever you have a problem in your website, you just debug it, set a breakpoint, step through code, inspect watches and such. It seems to me this is the most rudimentary type of work for a developer or troubleshooter. I've bought WingIDE which is an excellent tool and debugger but it can't hook into the Python instance in the IIS process for some reason so no debugging. I noticed Helicon starts Python with -O so I even recompiled Python to ignore this flag altogether but my debugger (WingIDE) just won't come up.
I can set up a PHP 'hello world' website on IIS in half an hour including download time. I think I've spent about 120 hours or more getting this to work for Python to no avail. I've bought Programming Python and Learning Python which is about 3000 pages. And I've googled until I dropped.
I think Python is a great language but I'm on the verge of aborting my attempts. Is there anyone who can give me a step-by-step instruction on how to set this up on IIS7?
I just did this in 5 minutes.
Ensure you have IIS. run: %windir%\system32\OptionalFeatures.exe. Or, via pointy-clicky: Start...Control Panel...Programs and Features... (and then on the left hand side) Turn Windows Features on or Off. Make sure CGI is installed, under the IIS node.
Download Python for Windows, from python.org . I grabbed Python2.7. Make sure you get the x64 version if you have an x64 version of Windows.
Unpack and install that python MSI. Choose the default, which puts python into c:\Python27
Create a directory to hold your "development" python scripts. Eg, c:\dev\python
Set the permissions on the files in the directory c:\dev\python to allow IIS to read and execute. Do this by running these two icacls.exe commands from the command line:
cd \dev\python
icacls . /grant "NT AUTHORITY\IUSR:(OI)(CI)(RX)"
icacls . /grant "Builtin\IIS_IUSRS:(OI)(CI)(RX)"
Open IIS manager. Run %windir%\system32\inetsrv\iis.msc, or do this via the control panel: Start...Control Panel...Administrative Tools...Internet Information Services (IIS) Manager. Create a new application. Specify the virtual path as /py and the physical path as c:\dev\python.
Within that IIS application, add a script map for *.py, and map it to c:\python27\python.exe %s %s
create a "HelloWorld.py" file in c:\dev\python with this as the content:
print('Content-Type: text/plain')
print('')
print('Hello, world!')
invoke http://localhost/py/helloworld.py
just make sure the path to the directory holding the cgi scripts doesn't have spaces or &.
i tried lots of things for many days and nothing worked then i changed the path and it worked
UPDATE:
If it has spaces, put quotes around the path, but not the %s %s
like this:
"C:\Program Files\Python36\python.exe" %s %s
Since this is quite an old question with some old answers (no accepted answer), here is a more up to date approach. The Microsoft doc below has a step-by-step guide to host Python apps through IIS (seems like it could work for Azure App Services as well - although MS suggests using Linux) making use of FastCGI (better approach post 2021 than the CGI approach).
The TL;DR is:
Install Python for Windows
Install wfastcgi package per https://pypi.org/project/wfastcgi/
Configure your web.config file to point to whichever framework your Python service is wrapped in (eg. Bottle, Flask, Django)
https://learn.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2022
When you are developing a web application with Python, you don't use IIS/Apache/etc. Those web servers are only for deployment. Frameworks like Pyramid/Pylons/Django all come with built-in web servers. Pyramid, in particular, has excellent documentation which should help you to get started: http://docs.pylonsproject.org/docs/pyramid.html
When you get to the point of deployment, Linux + Apache would be a much saner choice than Windows + IIS. If you absolutely must use Windows + IIS, don't use isapi-wsgi, as it has phantom performance problem: http://groups.google.com/group/isapi_wsgi-dev/browse_thread/thread/9fade6efca6c5b89
PyISAPIe has worked well enough for me, but I had to compile my own PyISAPIe.dll for Python 2.7.

Why Python gets installed in Frameworks directory?

I've been wondering why python gets installed in directory named Frameworks? (though it's not Framework)
$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
Somebody please explain! Thanks!
That's the way it is in OS X.
The Mac/README file in the Python source tree goes into some more details of the advantages of a framework build versus a traditional UNIX shared-library build, which will also work on OS X. The main points:
"The main reason is because you want
to create GUI programs in Python.
With the exception of
X11/XDarwin-based GUI toolkits all
GUI programs need to be run from a
fullblown MacOSX application (a
".app" bundle).
While it is technically possible to
create a .app without using
frameworks you will have to do the
work yourself if you really want
this.
A second reason for using frameworks
is that they put Python-related items
in only two places:
"/Library/Framework/Python.framework"
and "/Applications/MacPython 2.6".
This simplifies matters for users
installing Python from a binary
distribution if they want to get rid
of it again. Moreover, due to the way
frameworks work a user without admin
privileges can install a binary
distribution in his or her home
directory without recompilation."

Categories

Resources