How to fix pip under Debian 6.0 (squeeze): ImportError: cannot import name parser

HowTo, Linux, Programmazione, Python, Ubuntu (EN) 1 Comment »

The pip utility distributed with Debian 6.0 has a bug once you upgrade it with pip install -U pip. You will easily get this error when you try to install a new package with it:

root@worker2:~# pip install setproctitle
Traceback (most recent call last):
File "/usr/bin/pip", line 8, in <module>
from pip.baseparser import parser
ImportError: cannot import name parser

Luckly there is a very easy workaround:

easy_install pip
rm /usr/bin/pip
ln -sv /usr/local/bin/pip-2.6 /usr/bin/pip
pip install pip --upgrade

Reference: http://blog.102web.ru/tag/virtualenvs/

Using virtualenv to manage multiple Python/Django environments in the same machine

HowTo, Linux, Programmazione, Python, Ubuntu (EN) No Comments »

Developing Python applications sometimes it's useful to be able to test the code with different environments, for example a particular version of Python or a specific Django version etc... Setting up many different virtual machines would be really too much work and even using a chroot environment is not what you need in some cases. Thanks to virtualenv is it possible to create a self contained Python environment with all the specific libraries you may need. Using virtualenv is very easy:

  • Creating the virtual environment: virtualenv myenv --no-site-packages
  • Entering the virtual environment: source myenv/bin/activate
  • Deactivating the virtual environment: deactivate

That's it! Once you're inside the virtual environment you will be using the Python libraries inside it. I suggest you to install all the Python libraries you need using pip.

Using Twitter Bootstrap with Node.js, Express and Jade

HowTo, Linux, Node.js, Programmazione, Ubuntu (EN) 1 Comment »

I've decided to write this post as a note to myself. I'm still learning Node.js and digging into Express/Jade, but I've read many people using the nice Twitter Bootstrap and I was wondering if there was a way to integrate all these technologies. The short answer is: yes, we can!

Note: once again, I'm not a Node.js expert and surely there are other ways to achieve this task (for example there is a Node.js module called twitter-bootstrap, but I haven't tried it). This tutorial is based on another tutorial I found, but it was not very updated and it had a more complicated way to install Bootstrap, so I decided to write a new one basing it on the original http://www.rs.au.com/31/how-to-install-bootstrap-v2-0-2-in-expressjs-v3-0-0

Preparing the environment

I will assume that you're running any Linux distribution (in my case I'm using Ubuntu 12.10, but feel free to use your own distribution). Be sure to have installed a recent version of nodejs and npm packages (I'm using Node.js 0.8.20 and npm 1.2.11).

Create a project folder and install the required dependencies

mkdir node-bootstrap
cd node-bootstrap
npm install express
npm install jade

Create the basic project structure with Express

andrea@andrea-Inspiron-660:~/Documents/sviluppo/nodejs/node-bootstrap$ node_modules/express/bin/express nodebootstrap

create : nodebootstrap
create : nodebootstrap/package.json
create : nodebootstrap/app.js
create : nodebootstrap/public
create : nodebootstrap/public/javascripts
create : nodebootstrap/public/images
create : nodebootstrap/public/stylesheets
create : nodebootstrap/public/stylesheets/style.css
create : nodebootstrap/routes
create : nodebootstrap/routes/index.js
create : nodebootstrap/routes/user.js
create : nodebootstrap/views
create : nodebootstrap/views/layout.jade
create : nodebootstrap/views/index.jade

install dependencies:
$ cd nodebootstrap && npm install

run the app:
$ node app

You should already have installed all the needed dependencies, even without executing npm install, anyway executing it won't hurt.

Download and install Bootstrap

Download Twitter Boostrap from the official website http://twitter.github.com/bootstrap/assets/bootstrap.zip and unzip it under the nodebootstrap/public folder.

Bootstrap integration with Jade template system

At this point you need to edit the views/layout.jade file and include the references to Bootsrap

!!!
html
  head
    title= title
    link(rel='stylesheet', href='/bootstrap/css/bootstrap.min.css')
    link(rel='stylesheet', href='/bootstrap/css/bootstrap-responsive.min.css')
    link(rel='stylesheet', href='/stylesheets/style.css')
    script(src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js')
    script(src='/bootstrap/js/bootstrap.min.js')
  body
    block content

Test the Bootstrap integration

At this point we will modify views/index.jade that is the default template used to render the index

extends layout

block content
  div.top
    form.form-horizontal(method="post", id="loginForm")
      label Username
      input.span3(id="username", type="text", name="User", placeholder="Enter your username")
      label Password
      input.span3(id="password", type="password", name="Password")
      input.btn(type="submit", value="Log In")
  div.container
    div.content
      table.table.table-striped
        thead
          tr
            th Table
            th Heading
        tbody
          tr
            td Blah
            td Test
          tr
            td Hello
            td World

  div.footer

Now go back to the terminal and execute the app:

andrea@andrea-Inspiron-660:~/Documents/sviluppo/nodejs/node-bootstrap/nodebootstrap$ node app.js
Express server listening on port 3000

Open your favourite browse and visit http://localhost:3000 to see your first Bootstrap + Node.js application app and running.

How to install latest stable Node.js on Ubuntu

HowTo, Linux, Programmazione, Ubuntu (EN) No Comments »

If you develop with Node.js and you want to be sure to have the latest stable version, luckly there is a PPA for it. All you need is to follow these instructions:

sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm

That's it!

Reference: https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager

Using QtCreator to deploy and run a Qt application to a remote Linux device

HowTo, Linux, Programmazione, Qt, Ubuntu (EN) 1 Comment »

QtCreator is a very flexible IDE and can really be adapted for a lot of things. I usually use it to develop mobile applications for Nokia N9 and BlackBerry 10, but it can be used for more generic tasks. In my case I wanted to be able to develop a Qt application using my desktop PC, deploy it and run on a remote (actually it's on the same desk) Linux machine running Xubuntu.

Doing this is quite easy and you don't need any specific plugin on QtCreator, but be sure to have at least version 2.6.x. Other than QtCreator you also need two Linux based PC (I used Ubuntu 12.10 for my development machine and Xubuntu 12.10 for the remote netbook) and an SSH account on the remote PC.

Add the remote device to QtCreator

QtCreatorDevice

To add the remote Linux device on QtCreator, use the Tools->Options menu and click on "Devices" item. At this point click on "Add" button and fill the fields using values similar to the screenshot. In particular specify a name for the device, the IP of the remote machine and a username and password that must already exist (I just created the user "andrea" on the Xubuntu machine and used the same password). I also had to set the timeout to 20 seconds, because I had some connection problems and the connection kept dropping after 10 seconds trying. To verify if everything is working fine, just click on Test button.

Add a specific Qt version

QtCreatorQtVersion

To write your application you may need a specific Qt version that is different from the one distributed by your Linux distribution. There's no problem, QtCreator let you add different Qt versions without any conflict. In my case I installed the Qt5 version distributed by Canonical Qt5 Edgers Teamhttps://launchpad.net/~canonical-qt5-edgers
Once it's installed, just click on "Add" button and select the qmake specific to the version you want to add (in my case it was in /opt/qt5/bin/qmake ).

Add a Qt Kit

QtCreatorQtKits

QtCreator permits to add new Kit (development configurations) and these kits are used during project creation to specify what you want to target. In my example I added a new kit choosing an appropriate name "Qt5 Ubuntu", the device type, the actual device previously configured and finally the Qt version that we added before. With a kit I have a complete "toolchain" that allow me to write applications for a particular device, with a specific Qt version.

Putting the pieces together

At this point you just have to create a new "Qt Quick 2" application, and select the new kit you just created instead of the "Desktop" one. Please note that there is a little problem that I haven't fixed yet (but I'm working on it): if you create, for example, a project named "QtTest1" it will be deployed to the folder /opt/QtTest1/ on the remote machine. By default your user doesn't have read+write permissions for that folder so I manualy created the folder and I gave a chmod 777 on it, just for testing. There are two possible ways to fix this: you could create a specific user that has read+write permissions on /opt/ or you could modify the deployment configuration to have the app deployed to the user /home (I will investigate on this possibility and I will write something in one of the next posts).

Final thoughts

What all of this could be useful for? Well, do 2+2 and you'll easily guess ;) In the next weeks I will post more specific informations and I will update everyone with my progresses. Any comment is welcome! If you want to contribute to this you're welcome too of course.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in

Switch to our mobile site