Session 3: Python packages and installs

Using virtualenv

To create a virtual environment:

python -m virtualenv ~/env

To activate it as your default Python environment:

. ~/env/bin/activate

Now, even without root, you can do pip install of whatever packages you like.

To deactivate it,


Building a ‘’

In the sqer directory,

  1. grab the latest from

    curl -O
  2. Put the following in

    import ez_setup
    from setuptools import setup
          install_requires=["screed >= 0.7"],
          setup_requires=["nose >= 1.0",],
          test_suite = 'nose.collector',
  3. Put the following in setup.cfg:

    verbosity = 2

Now you can do:

python test

to run the tests, and:

python install

This will install ‘sqer’ so that (a) it’s importable from anywhere,

python -c "import sqer"

and (b) the script(s) are in your path so that: data/test-reads.fa

should work from anywhere.

Remember to add and commit to git:

git add setup.cfg
git commit -am "added install configuration"

Note that if you create a .tar.gz,

cd ..
tar czf /tmp/sqer.tar.gz sqer
cd sqer

you can now do:

pip install /tmp/sqer.tar.gz

and this will also work with URLs to the .tar.gz as well as github files & release links...

One final comments: ‘git status’ will show you that the directory is getting messy. Add:


to .gitignore, and then commit:

git commit -am "updated gitignore with detritus"

It’s probably time to do a ‘git push origin master’ too!

Building a default/basic ‘Makefile’

Put the following in ‘Makefile’ in the seqr/ directory:

     python build

     python install

     python clean
     rm -fr build

     python test


‘make’ is picky about tabs vs spaces – the lines after the ‘:’ need to be indented with tabs to work properly.

This will now let us do ‘make’ (which will execute the first target, ‘all’); ‘make install’; ‘make clean’; and ‘make test’. These will do the obvious things.

The important thing here is that all of these are standard make commands. If I see a Makefile in a repository, then I assume that it’s got the commands above. Convention, convention, convention!

Remember to:

git add Makefile
git commit -am "added Makefile"


We’re going to build some docs using Sphinx and reStructuredText.


mkdir doc
cd doc

Use default values for everything; specify project name, author, and version.

Now, in the ‘doc’ directory, do:

make html

and look at _build/html/index.html

Let’s flesh this out a bit – edit ‘index.rst’ and add an indented ‘details’ under Contents, e.g.:


.. toctree::
   :maxdepth: 2


Now create ‘details.rst’ to contain:

Project Details

sqer is awesome.

Important details

This where all my documentation goes.

...and run ‘make html’ again. Look at _build/html/index.html.

Be sure to do:

rm -fr _build
git add *
git commit -am "added docs"

And also add a rule to the top-level Makefile:

     cd doc && make html

(and git add/commit the Makefile changes.)

Now, push this all to github:

git push origin master

and let’s go configure it at

Reminder: under your github project, settings, service hooks, enable the ‘readthedocs’ service hook.