Monday, 16 January 2012

Flask, virtualenv and Aptana/PyDev

I've just started playing with Flask and it's good, really really good. Today I want to tell you how I got Flask + virtualenv + Aptana studio 3, which includes PyDev, to work together.

  1. Create project directory and setup virtualenv environment in it
    mkdir projectfolder
    cd projectfolder
    virtualenv env
    . env/bin/activate
    
  2. In Aptana, import project then setup a new Python Interpreter which points to the 'Python executable' in the 'env' folder created by virtualenv command earlier.
    Go under 'Preferences -> PyDev -> Interpreter - Python',  click 'New...'.
    Now browse to your [PROJECT_FOLDER] -> env -> bin and select 'python2.7'.
    Change the 'Interpreter Name' to something descriptive like '[PROJECT_FOLDER]-Python' and click 'Ok'.
    A 'Selection needed' window will pop-up. Do not touch anything, click 'Ok'.
    An 'Error: Python stdlib source files not found' window will pop-up. Click 'Proceed anyways'. Click 'Ok' on preference window.
  3. In PyDev Package Explorer window, right-click on your project folder and select 'PyDev -> Set as PyDev Project'
  4. Right-click on project folder again and select 'Properties'.
    Go under 'PyDev - Interpreter/Grammer'
    Then under 'Interpreter' select the one we setup in step 2, [PROJECT_NAME]-Python.
  5. Click on 'Ok' and you're all set.
So it all runs pretty good so far, brought to you by the good folks of the 'internets' :)

5 comments:

  1. Thanks, this helped a lot. Just started learning Python and was looking for a IDE that would work with virtualenv.

    ReplyDelete
  2. Sweeeet. You're a good man, Thomas Bhatia.

    ReplyDelete
  3. Thanks, this got me on the right path. Note: If you have problems with PyDev not recognizing python's stdlib imports, you should include (i.e. check) your python base dir in step 3. This will also avoid the error message that you mention here. For me, this solved a "missing import: unittest" problem.

    Source: http://sourceforge.net/projects/pydev/forums/forum/293649/topic/4037711/

    ReplyDelete
  4. This will work with Django too? been trying to setup Aptana Studio 3 but no luck!

    ReplyDelete