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.

Dependencies

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

python (http://www.python.org/)
pip (https://pypi.python.org/pypi)

Install

Note: If you get a "permission denied" error when using pip or setup.py, you may add the --user flag to install to a location in your home directory, which should resolve any permissions issues. Doing this, you may need to add this location to your PATH and PYTHONPATH. Alternatively, you can run this with 'sudo'.

User instructions:

If you want Pyjs only for your apps use it, simply do this:

pip install git+https://github.com/pyjs/pyjs.git#egg=pyjs

This will install Pjs, Pyjs-Tools and all dependencies.

Developer instructions:

Get the source from the git:

git clone https://github.com/pyjs/pyjs.git

Change into the pyjs root directory:

cd <pyjs root>

Install Pyjs, Pyjs-Tools, and all dependencies:

python setup.py install

Post-install:

You are now ready to use Pyjs. Once it is installed, you can import Pyjs to your python script using:

import pyjs

Scripts for compiling python code to Javascript as well as compiling applications will be installed into the system default location. The most important ones are:

pyjscompile
pyjsbuild
pyjampiler

Running examples

Checkout and build the helloworld example (it is in repository folder):

cd examples/helloworld
pyjsbuild hello.py

This will generate a plain JavaScript application: pyjs creates an ./output folder containing all files you need to move to your webspace later. Of course you can test locally, too.

For test locally, just look /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)

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

Alias /examples "REPLACE THIS/pyjs/examples/"
<Directory "REPLACE THIS/pyjs/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/

Play with other examples on your local machine, use pyjsbuild <ModuleName> to compile your python code to HTML and JavaScript, and 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