Python Bottle Micro-Web Framework - python

Ok, so I've gone to the http://bottlepy.org/docs/dev/ website, and tried following their instructions for including the bottle.py framework, and do the little test web service test they have on the site.
The problem I'm having is that the python script does not recognize the "from bottle import route, run, template", so the code does not execute. I can't find anything to show HOW to properly include the bottle framework.
I've gone to YouTube, multiple posts on StackOverflow, and I'm not sure what I'm doing wrong.
Some info: I'm using Eclipse with PyDev, and I'm running on Windows 7 64 bit. Also, I write in other languages (Java, C#, Objective-C) but I'm new to Python, so maybe I'm making a newbie mistake...?

You need to install the Botte package. Citing the "Download and Install" section from the Bottle web site:
Install the latest stable release via PyPi (easy_install -U bottle) or download bottle.py (unstable) into your project directory.

If easy_install bottle didn't work, try pip install bottle.

Related

Python - Configure gevent library on Google App Engine

I'm newbie in programming and need some help in the following situation.
I want to use gevent library on Google App Engine. I'm writing in Python using webapp2.
So the question is how to configure it so that it will work with GAE SDK.
I've put gevent library files in my projects directory like other libraries which are working well in this project. But when I run my app on local server it says:
ImportError: No module named greenlet
I've installed it on my computer,
pip install greenlet -t way/to/python/lib/directory
still it doesn't work
I had similar problem with lxml library, but It was solved after I've written its name in app.yaml. But lxml is preinstalled on GAE as written here. Although it's not the case with gevent.
I would appreciate any help. Thanks!

Parallel Python install on Media Temple DV server

Plesk on the MediaTemple DV servers uses Python 2.4 for stuff, so the 2.4 install can't be replaced but someone recommended installing a separate python 2.7 install since my app runs on that. I'm new to the whole server thing, so this is new territory. My sense is that I can create a new directory for the source files and use SSH to download the files to said directory and then cd into it and install python 2.7. Then I have to figure out how to make sure Apache knows to use Python 2.7 to run the django app in question. Does this sound correct?
Unless you can make a system wide change to your python installation, you would have to run Apache, python and Django in the same virtual environment. If it is not possible, use gunicorn (instead of apache) to run the Django app in a virtualenv (in a port different from Apache's). If this app runs in a subdomain, you should consider hosting the Django app in a PAAS (Heroku, Google App Engine, etc.) which allow you to easily switch running environments.
Never mind, sorted it. the important thing seemed to be to edit the etc/ld.so.conf by adding usr/local/lib, then running sbin/ldconfig, which then makes ld.so.conf look like:
include ld.so.conf.d/*.conf
/usr/local/lib
Donwload and then compile Python
and use make && make altinstall.

Azure website use python3 with django

Officially, Azure Django Websites only support Python 2.7 and Django 1.4, but I am wondering if it is possible to set up an Azure Django website using Python 3.3 and Django 1.6 instead. This official Azure tutorial states:
Note: Windows Azure web sites now come with Python 2.7 and wfastcgi handler
pre-installed. However, web frameworks such as Django are not included. You can
still use a different Python interpreter if you prefer. You just need to include
it in the Git repository and configure the web site to use that interpreter
instead of the Python 2.7 interpreter already installed.
That sounds to me like you can set it up to use a different Python interpreter, although you may have to also provide your own wfastcgi handler and Django installation if you do this. The tutorial also tells you how to point to the location of the interpreter you want to use.
The Python website provides installers, but how would I get everything needed for the Python interpreter into one folder to put in the git repo? Is everything needed already self-contained in /Library/Frameworks/Python.framework/Versions/3.3? What about for Django and wfastcgi? Has anyone else tried this?
It is working now: put python-3.4 in runtime.txt at the root of the project.
See: https://azure.microsoft.com/en-us/documentation/articles/web-sites-python-configure/

How do I setup a local Django development environment on Ubuntu?

Finally made the switch from Windows to Linux (Ubuntu). I am teaching myself Python + Django.
GOAL: I want to setup a local development environment where I can build a django application and run it locally before deploying it live online.
SO FAR: Python comes installed with Linux. Gedit does also. Ok great. After that I am lost.
I am not sure how to proceed. I am a total Linux noob. I am guessing I need apache running, mysql running, and django to run. I don't know how to setup these things to run or how to set the proper directories or what I need to link to what... really I am not even sure what the right questions are to ask.
Quick answer:
Just install django via their documentation, and you will not even need apache running as it will run its own server. You can use sqlite as a db and you won't even have to worry about mysql. This is if your goal is to learn django and get things running asap.
Otherwise, if you want to take the full route, you'll need to start learning a lot more (which isn't a bad thing). I'd say take a look at some of the slicehost guides for setting up apache, mysql in ubuntu:
http://articles.slicehost.com/2010/5/19/installing-apache-on-ubuntu
http://articles.slicehost.com/2011/3/10/installing-mysql-server-on-ubuntu
And then pick up with just installing django and going from there. The django tutorial is awesome. There's plenty of other documentation out there on the web & tutorials for setting up dev environments.
Assuming you have python
You can install pip:
easy_install pip
From now you can use pip to install your python libraries for example to install django
pip install django
For development I would prefer pydev, it has a support for django with the power of eclipse.

Package a django project and its dependencies for a standalone "product"

I've made a small little "application" utilizing Django as a framework. This is an application that is not ment to be deployed to a server but run locally on a machine. Thus the runserver.py works just nice.
I, as an developer is comfortable with fireing up the terminal, running python manage.py runserver and using it.
But I have some Mac OS X and Windows friends wanting to use my application, and they dont have virtualenv, git or anything else.
Is there a way I can package this to be a standalone product? Of course it would depend on Python being installed on the system, but it is possbile to package the virtualenv — with django and everything, and just copy it to another system and make it work?
And maybe even run the runserver in some kind a deamon mode?
Use setuptools and easy_install.
Here's an introductory article.
Yes, you can package it. Django may not be the easiest to do this with, but the principles are the same for other frameworks. You need to make an installer that installs everything you need. And that installer needs to be different for different platforms. such as Windows, Ubuntu, OS X etc. That also means that the answer is significantly different for each platform, and only half of the answer is dependning on Django. :-(
This kinda sucks, but that's life, currently. There is no nice platform independent way to install software for end users.
I also haven't found the perfect solution for this yet.
My current approach is to provide a docker image because that's really easy to use for everyone. This includes an alpine base image because it's tiny and python + django and the app itself. You can also include a webserver like nginx and an app server like uwsgi or gunicorn and expose a port for it.
So in the end your user would just run the container and access the web app under http://localhost:9000/ or something like this.
This is really handy and also my preferred way of trying out some app I've found.
The "proper" way would be do build a package for every OS and distribution you are targeting and a simple zip bundle so people can also install the app manually.
To build the packages I suggest using fpm. It takes most of the pain of doing the packaging with their native tools away. The packages would then depend on a proper application server like uwsgi or gunicorn.
So in the end you could then install it like apt install your-package and it would depend on python-django, uwsgi etc.
For the location and where to put all the files in the package every distribution has their own way of doing it. I prefer putting everything under /usr/share/webapps/myapp/ and having the config under /etc/myapp/config.py or something like that.
For Windows and macOS there are solutions like PyInstaller. I haven't used it yet for a django app but it should do the job. You should include a app server like uwsgi in there too.
In generel you don't want to run the django dev server in a production environment. So keep that in mind when packaging.
I hope that helps a bit.
There are several ways of doing this. I think you are looking more for build tools (which includes packaging) rather than just a Python solution. Here are a couple that I've used in the past:
zc.buildout: Used to build and deploy Python modules and applications, but is also able to work with other languages with a little massaging. Easy to use (for a build tool).
make: The software build classic. Works with practically all languages but a little archaic and hard to learn for a first timer.
The new snap package manager for Linux should suit the task perfectly. It provides all the solutions that were quite a pain for Python apps so far (dependencies, interpreter etc) and at the same time avoiding the complexity of Docker.
These days Docker is probably a good answer
User needs to install Docker first, but it runs on Windows and OSX as well as Linux.
Your Dockerfile takes care of installing all the dependencies and then runs the devserver (or you could even run a proper webserver in the container)

Categories