Setup Python environment on Windows - python

How do I setup a Python environment on windows computer so I can start writing and running Python scripts, is there an install bundle? Also which database should i use?
I should of mentioned that I am using this for web based applications. Does it require apache? or does it use another http server? What is the standard setup for Python running web apps?

Download the Python 2.6 Windows installer from python.org (direct link). If you're just learning, use the included SQLite library so you don't have to fiddle with database servers.
Most web development frameworks (Django, Turbogears, etc) come with a built-in webserver command that runs on the local computer without Apache.

Bundle: go with Activestate's Python, which bundles many useful win32-related libraries. It has no version 2.6 yet, but most code you'll find online refers to 2.5 and lower anyway.
Database: any of the popular open-source DBs are simple to configure. But as John already suggested, for simple beginning stuff just use SQLite which already comes bundled with Python.
Web server: depends on the scale. You can configure Apache, yes, but for trying simple things the following is a quite complete web server in Python that will also serve CGI scripts writte in Python:
import CGIHTTPServer
import BaseHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ["/cgi"]
PORT = 9999
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "serving at port", PORT
httpd.serve_forever()

I strongly recommend ActiveState Python for python on windows development. It comes with Win32Com and various other goodies, has a mature and clean installer, a chm version of the docs and works really well. I use this all of the time.
As for a database, Activestate comes with odbc support, which plays very nicely with SQL server. I've also had it working with Sybase and DB2/400 (although the connection strings for the latter tend to be rather convoluted). For Oracle, I recommend CX_Oracle as the best interface library. Native drivers for most proprietary and open-source databases (such as MySQL and PostGreSQL) also exist. Recent versions of Python (from 2.5 onwards IIRC) come with SQLite bundled as standard.

Don't forget to install pywin32 after installing the official (command line) installer. This will define additional start menu items and the highly useful PythonWin IDE.
An installer for both is available at Activestate (no 2.6 yet). The Activestate distribution contains additional documentation.

Might I suggest taking a look at Karrigell? It's really a nice Python web framework if you don't require everything Django and Turbogears offers. It might be easier for you to work with web frameworks until you get comfortable with them.
For development, I recommend downloading the latest SPE IDE. It should provide you nearly all the tools you will need, plus it includes wxGlade for GUI development.

Django tutorial How to install Django provides a good example how a web-development Python environment may look.

Related

Questions about PostgreSQL version 12.2 and its compatibility with other operating systems

I will develop a commercial Python software with the PostgreSQL database, I will use PostgreSQL version 12.2. My first question is, to run the application database (will it be a desktop application) will I need to install something related to the database on the user's computer?
And my other question is, will I be able to run my application with this version of the database on another operating system?
I saw that on the download page of version 12.2 the database only has an installer for Mac OS X and Win 64bits, will my application be compatible with other operating systems besides those two I mentioned?
I'm new to programming, thanks in advance for the clarification. <3
The database API driver/provider (in the case of Python probably psycopg2) will have to be installed on the machine where the code runs that directly accesses the database.
In the case of a 2-tier architecture (the application is installed on the end-user machine and directly accesses the database) that driver will be installed on the end-user machine, where the Python program runs.
In the case of a 3-tier architecture (the end-user machine talks to a web server via HTTP, and the Python program that accesses the database runs in an application server on the web server machine) the driver will be installed on the application server.
There are modern architectures that are even more complicated (keyword "microservices") which few people understand well enough to use properly, but let's ignore them here for simplicity's sake. The same principle applies: whoever talks to the database directly will need to have the database driver installed.
If you install psycopg2, you will also need to install the PostgreSQL client shared library libpq on the same machine, because psycopg2 is linked with it and uses it.

How to install twistedweb python library on a web server

I have a small application written in python using TwistedWeb. It is a chat server.
Everything is configured right now as for localhost.
All I want is to run this python script on a server(shared server provided by Fatcow.com).
I mean that the script will be working all the time and some clients will connect/disconnect to it. Fatcow gives me python 2.5 without any custom libraries. Is there a way and a tutorial how to make it work with TwistedWeb?
Thanks in advice.
the easy_install/pip modes of installation are very likely to fail because of broken dependencies. You will have to download the tar and build it yourself. See the attached link for more info on installing the same on CENTOS.
http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#CanIinstallTwistedusingeasy_installorpip
I have contacted Fatcow.com support. They do not support SSH connections and do not support Python 2.7 with Twisted library, especially python socket application as server. So it is dead end.
Question resolved.

Using Twisted on a server without installation privileges?

I have a server that I'd like to use to maintain persistent connections with a set of devices, just so that they can pass simple messages back and forth. It's a trivial task, but selecting a server-side platform has been suprrisingly difficult (especially since I have no administrative privileges - it's a dedicated commercial server).
My best idea so far is to write a TCP server in Python. The Twisted platform seems suitable for the task, and has a lot of good reviews. However, my server has Python 2.7 but not Twisted, and the admins have been reluctant to install it for me.
Is there any way that I can just upload a Twisted package to the server and reference it in my libraries without installing it as a framework?
I'm not sure what you mean by "installing it as a framework". If you are using an OS X server hosting environment, then maybe you're talking about Framework with a Capital F. However, OS X server hosting isn't a very common environment so I'm guessing that's not it.
If you just want to know how to install a Python library in your home directory, then the general answer is:
$ python setup.py install --user
This Just Works™ on Python 2.7 (assuming the package uses distutils, which Twisted does, and you unpack the source .tar.gz and change your working directory to the directory that is the root of the contents of that .tar.gz), so you should be done after that.
Use virtualenv to create your private Python libraries installation.

How to set up a windows based front-end developer for contributing to a django based application

I am working on a project where I am quite comfortable running linux, virtualenv, pip, manage.py runserver, git and so on for back-end development. I work with a front-end developer who needs to collaborate remotely, currently via a Dropbox synced copy of the codebase (also in a git branch) on Windows. A development server on my side lets the developer see their changes semi-live.
Although this has served us fairly well so far, has anyone come across a similar working arrangement with a better setup for collaboration?
I'm mindful that the source control learning curve and environmental management overhead is potentially significant and somewhat unnecessary for front-end work (as long as I commit from time to time). I'm considering a VM based setup such as BitNami's DjangoStack so that the front-end dev has their own server setup, but I thought I'd ask about other experiences.
I would recommend vagrant not only for quick development setups (which it excels at), but also for sharing VM configurations as you can publish your own vagrant file which your designer uses.
It relies on VirtualBox Sun Oracle's open source hypervisor and is available for free on all major platforms.
I have been in a very similar situation before Rog, where the backend was a Ruby on Rails setup running on *nix, and the frontend guy needed windows. We initially set up a Windows-Apache-MySql+git+RoR (using Cygwin and other tools) but eventually installing our app libraries and gems became a pain on the windows setup (anytime we would introduce a new gem (or app in django terms) the setup would break on windows). In the end we finally made the front-end guy work on *nix setup.
andLinux is extremely useful in these situations, it lets your run a seamless install of linux withing a windows 2000 setup, so the front end guy can still use windows tool. It is not like a dual boot, but here both the OS are running at the same time. Have a look into it.

Communication between Windows Client and Linux Server

I want to provide my colleagues with an interface (using Windows Forms or WPF) to control the states of virtual machines (KVM based) on a linux host. On the command line of this server, I'm using a tool, called libvirt, which provides python bindings to access its functionality.
What whould be the best pratice to remotely access several function like libvirt or reading logfiles on the server. I thought about a REST Full Webservice generated by Python. Are there other viable options to consider?
Thanks,
Henrik
I'd develop an intranet web application, using any python web framework of choice.
That way you don't have to develop/install software on your client. They just point the browser and it works.
Because you are using a server-side tool that has Python bindings, you should give a serious look at PYRO which is a Python RPC library.
http://pyro.sourceforge.net/
To use this you would also have to use Python on the client, but that shouldn't be a problem. If you haven't start writing your client, then you could do it all in IronPython. Or, if you need to add this to an already existing client, then you could still bind in either IronPython or CPython as an embedded scripting engine.
For more on PYRO and Ironpython, see this wiki page http://www.razorvine.net/python/PyroAndIronpython
Proxmox VE is a complete solution to manage KVM (and OpenVZ) based virtual machines, including a comprehensive web console, so maybe you can get a full solution without developing anything?

Categories

Resources