Sunday 25 November 2012

How to make Windows executable from a Python script

Recently I faced a problem that I always wanted to stay away from. My brother asked me to write a simple GUI app, which isn't a big deal, but it has to be run in Windows. Holy shit. I develop all the staff in Linux and suddenly I have to prepare a Windows-compatible app. As Python is a language of my choice, I picked it also this time. I wrote an app under Linux and then I made a research on how to port it to Windows without a need to install Python on the target machine. I found cx_Freeze which seemed to be suitable. Having read a really good cx_Freeze tutorial I wrote a setup.py script which looked like this:
#!/usr/bin/env python
from cx_Freeze import setup, Executable

exe = Executable(
    script="google_check.pyw",
    base="Win32GUI",
    )

setup(
    name = "googleCheck",
    version = "0.1",
    description = "google check app",
    executables = [exe]
    )
then run
pawel@pawel-asus:/media/5841-E712/seba$ python ./setup.py build
running build
running build_exe
Traceback (most recent call last):
  File "./setup.py", line 13, in 
    executables = [exe]
  File "/usr/lib/pymodules/python2.7/cx_Freeze/dist.py", line 278, in setup
    distutils.core.setup(**attrs)
...
  File "/usr/lib/pymodules/python2.7/cx_Freeze/freezer.py", line 186, in _GetBaseFileName
    raise ConfigError("no base named %s", name)
cx_Freeze.freezer.ConfigError: no base named Win32GUI
Uhhh.. I can't freeze an app for Windows under Linux. My bad. There is no way to "cross-compile" an app on Linux without having a Python installation on Windows partition that would be visible from Linux. If you have one, you can use PyInstaller. I had no Python on my Windows so I had to install it first.. which is a pain in the ass. Here is what to do:
  1. Go to Python for Windows download page, download an installation file and install it.
  2. Add your Python/scripts path to the PATH variable (go to My computer/properties/Advanced/Environmental Variables/Path/Edit then paste the path with an extra semicolon as the last entry.
  3. Get Easy install installer and install it.
  4. Open command line and type easy_install cx_Freeze
Now you are ready to go. Change the working directory to where you placed your application and setup.py, type cxfreeze ./setupy.py and look if there are some modules missing. If it is so, install them with easy_install. It may happen, that you won't be able to get some module in this way. Well, cross your fingers, in the end they maybe unnecessary at all to run your project. Now go to a newly-created dist folder. There is your double-clickable python application. Bon apetit.

Friday 23 November 2012

Machine learning at Twitter

Recently we had a discussion on paper about machine learning at Twitter. You won't find there discoveries that would move the horizon of science. It presents a model of computation for big data which I found particularly useful, though. There are only two authors listed, but one can easily notice contribution of countless engineers.

You do not appear to be using the NVIDIA X driver. Please edit your X configuration file (just run `nvidia-xconfig` as root), and restart the X server.

This message kept poping up when I tried to run nvidia-settings. This happened by the way when my maximal resolution was 640x480 and number of colours was dramatically limited. I was unable to run my second screen either (xrandr was constantly crashing because of lack of randr extension). I found a solution and modified it according to my needs.
sudo apt-get install linux-headers-$(uname -r)
sudo ldconfig
sudo update-initramfs -u
sudo nvidia-xconfig
sudo reboot
Welcome back, nVidia.

How to upgrade your Ubuntu distribution from terminal

Recently I encountered a major Xfce crash. There was no windows decorations nor menus in the graphical environment. I was unable to move windows, as well as close them. It made me realize when I updated my system for the last time. Enough to say that I don't remember this fact. I left the computer for the night to download all packages from 11.04 (Natty Narwhal) and install them (there was surprisingly no option to go directly for 12.04). In the morning my computer was unable to boot with WM and I was left with recovery console... My next easy-to-do option was to try to update to 12.04. Here is what to do (supposing we go from 10.04 (Lucid Lynx) to 12.04 (Precise Pangolin):
sudo sed -i.bak -e s/lucid/precise/g /etc/apt/sources.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade
This will not install packages that were earlier not installed. You may have to install for instance kernel image and headers by hand.