Wednesday, 18 November 2015

A Way to Deploy Python Programs

[...]we will use Java, because a jar file is easier to deploy.
This sentence occurs sometimes where I work. In this multi-environment place, a easy way to deploy your software is a fundamental requirement.

Wednesday, 3 December 2014

Why a Build System in IDEs Era?

Some friends of mine criticized my old post «Build your C/C++ programs everywhere with SCons», arguing a build system is useless in modern world.

Tuesday, 17 June 2014

What I miss in Python Game Development

As I said before (and I repeated), if I start a new project, I prefer to work with Python, 'cause I like its huge standard library, its portability and its syntax and this is true for every new project I do for work: such as "building netcdf files", "analize meteorological datas", "manage databases". But I had a big problem for a personal project, a long dreamed chimera never really realized: a videogame. I thought to build a simple shooter, something like the old "galaga" or "space impact", using hardware accelerated graphics for great effects, such as particles and flashes. There are many schools of thought on game development under Python: there's PyGame ones, Pyglet, Pandas, ecc. I would like to talk with you about actual game development in python and reflect about my needs

Actual Situation

Let's take a look on Python libraries for gaming.
  1. PyGame is a simple 2D library based on SDL. Good for 2D graphics and integrable with PyOpenGL for 3D. It's still the library with biggest community for Python game development.
  2. Pyglet is a 2D library built upon OpenGL. It's fast, "pythonic" and very pleasant. But it stand still since 2010. No news, few words from devs and, back in 2010, no support on windows 2000. Very bad. I don't ask a lot, just a simple «we are here» from Pyglet developers, some guidelines, a vision for next releases and ports.
  3. Panda3D is simply great. A full featured 3D framework written in C++ and strictly binded to Python to realize 3D games. Great. A bit heavy and maybe a bit much for a 2D engine, but still good.
  4. Cocos2D: yeah! You know Cocos2D as a iOS (and probably its multiplatform C++ 'sister' project, Cocos2D-x), but it started as a Python library based on Pyglet. It's still developed, but being based on Pyglet I am a bit hesitant to suggest it
I found this scenario quite sad: Pygame isn't accelerated and is quite big; Panda is oriented to 3D; Pyglet and Cocos2D could be the best option, but they appear less supported than they're new, shining side-project based on C++/Objective-C.

So, what I miss?

When I started using Lua Löve I feel confortable, even if I don't like Lua very much. With Löve I realized a simple interactive program in few lines of code. Easy and fast, both in writing time and in effective speed. It was also small, 'cause Löve executable is less then a megabyte and it's easy to deploy: just bundle Löve executable and your program zipped and you can give it to every desktop OS.
More frustrating is thinking Python games could do this too. If you try to realize a Visual Novel, with Python you can use Ren'py. Ren'py it's great because it's not just a library, but a full framework where you can manage your projects, add sounds and images, use Ren'py Domain Language to write your visual novel. It cames even with an embedded text-editor (JTextEdit) and offers you many usefull features (take a look here for more info). So, what I really miss for Python game development is a environment, with
  1. a text editor
  2. a packaging system to deploy my programs, without thinking if my users have Python installed or how to bundle all files
  3. a easily way to manage animations
  4. easy to use accelerated 2D graphics. Something like Löve's
    myImage=love.image.newimage('test.png'),x, y, r, sx, sy, ox, oy, kx, ky )
  5. A consequenting animation class whom works with image functions just seen
  6. Managing projects as entities (something like eclipse)
  7. Have a "main" file such as
    import TheFramework as tf
    class Game(tf):
        def __init__(self):
        def Update(self):
        def Render(self):
  8. a way to export such games to mobile platforms
  9. Reduce final program only to really used modules
  10. Game configuration as python dictionary
  11. Save/Load system


These features are realistic, 'cause Ren'py already does. JMonkeyEngine works in a similiar way using Netbeans as base. If you're looking for a new project, this could be a good idea.

Thursday, 17 October 2013

Mac OS X, Python, PySide and Matplotlib

In these days I'm working on Python application for manage some metereological datas. It uses PySide for the GUI and Matplotlib to plot some useful charts. Unluckily, I had some troubles to add this last library. After some work, I found a solution. This post is a brief guide to my little oddity on using PySide and Matplotlib on a Mac OS X environment.

Install homebrew

Follow homebrew installation instruction from its official site. Basically just type in your terminal
ruby -e "$(curl -fsSL"

Install python

It's easy with homebrew. Just type
brew install python


Set your Python Path. Write on your .bash_profile
export PATH=/usr/local/share/python:$PATH
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH

Install virtualenv

I know, probably you don't want to do 'cause you want just ONE python. I am with you, but it seems quite hard to do on Mac OS X. So, be patient!
pip install virtualenv

Create a virtualenv

I put my virtualenv in the same directory of my project. Probably it's redundant, but it's specific for this project.
cd fooproject
virtualenv py27 --distribute
A new directory called py27 will be created. It will contain all python libraries. Now, let's activate our new virtualenv
source py27/bin/activate
Your shell will become something like this:
(py27)darkstar: fooproject username$

Install PySide and PySide Tools

For some unclear reasons, pip can't install pyside: it can't find . I resolved using brew again and installing also pyside-tools to use it in with QT Designer. I did it staying in virtualenv
brew install pyside pyside-tools

Install GFortran

NumPy require GFortran. So add it with brew
brew install gfortran

Install matplotlib

Always in virtualenv, I installed matplotlib and numpy
pip install numpy matplotlib


Program and install your packages always from your virtualenv. When you're tired of it, just type
And you'll exit. Good luck: I had many problems with this stuff!