Skip to content
David Ragazzi edited this page Jun 17, 2014 · 26 revisions

Getting Started

Pyjs is slightly different from traditional Web development: it's more like Desktop application development. This guide should help you to get started quickly in developing your first application. You'll find references to API documentation, more tutorials and other guides in the Resources section below.

Installing dependencies

Before you continue, be sure that you have these tools installed on your machine:

  1. python
  2. virtualenv - a python toolset that allows multiple python sandox installations
  3. pip - an alternative to the standard python installation tools

Downloading and installing

  1. Get the source either the git (preferred) or snapshot:

    git clone https://github.com/pyjs/pyjs.git
    
  2. Change into the pyjs root directory

    cd <pyjs dir>

  3. Optional step to create your own virtual python sandbox for development purposes

    virtualenv mypython

    This will create a mypython directory and install sandboxed virtual python installation at

    <pyjs root>/mypython

  4. Install Pyjs-Tools, Pyjs-Pyjamas and all dependencies

    <pyjs root>/mypython/bin/pip install <pyjs root>

OR the following if you want to develop and modify Pyjs-Compiler or Pyjs-Widgets themselves

<pyjs root>/mypython/bin/pip install -e <pyjs root>
You are now ready to use Pyjs. Scripts for compiling python code to Javascript as well as compiling applications will be installed into the mypython sandbox
<pyjs root>/mypython/bin/pyjscompile <pyjs root>/mypython/bin/pyjsbuild <pyjs root>/mypython/bin/pyjampiler
  1. Go to the examples:

    cd examples
    

Set examples modules:

python .

(or python __main__.py if you have python 2.5 or earlier)

If you've got apache running, add this to your default site config:

Alias /examples "REPLACE THIS/pyjamas/examples/"
<Directory "REPLACE THIS/pyjamas/examples/">
    Options Indexes MultiViews FollowSymLinks +ExecCGI
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
    AddHandler cgi-script .py
</Directory>

and point your browser to http://localhost/examples/

Checkout the /examples/helloworld/ helloworld example

Look at it /examples/helloworld/output/Hello.html in the browser

Look at the source code:

from pyjamas import Window
from pyjamas.ui import RootPanel, Button

def greet(sender):
    Window.alert("Hello, AJAX!")

class Hello:
    def onModuleLoad(self):
        b = Button("Click me", greet)
        RootPanel().add(b)

Play with the code on your local machine, use the build.sh script (or ../../bin/pyjsbuild <ModuleName>) to compile your python code to HTML and JavaScript, see what happens.

  • Look at some more examples, in the /examples/ directory
  • Look at some more examples
  • Did I say 'Look at some more examples'?
  • Build your own from a copy from helloworld

Troubleshooting

If you run into problems installing Pyjs (read: if you can't get the example applications running due to import errors) see the following articles:

Learning Resources

!tag howto tutorial

Clone this wiki locally