User Tools

Site Tools


python:development_workflow

This is an old revision of the document!


Python Project Workflow

To manage project dependencies, Node.js has npm and package.json files, PHP has composer and composer.json files. Fulfilling a similar need, Python has pip and virtual environments, but they don't work quite like npm+package.json and composer+composer.json.

Projects require virtual environments

The basic idea is that for each Python project, you define a virtual environment that harbors all the project's python dependencies.

The easiest way to go about things assuming your have pip, virtualenv and virtualenvwrapper installed on your system is as follows:

  1. Create a directory for your project:
    $ mkdir ~/Dev/MyProject
  2. Create a virtual environment for your project:
    $ mkvirtualenv MyProject

    The actual virtual environment will be in ~/.virtualenvs/.

  3. Enable the virtual environment:
    $ workon MyProject
  4. Install the packages you need:
    $ pip install <whatever>
  5. When you are done, switch your shell back to “regular” mode:
    $ deactivate

Notes

  • To see what environments are available:
    $ workon

    without an argument.

  • To set the Python version you want to use:
    $ mkvirtualenv -p /usr/bin/python3 MyProject

Getting a list of packages in the virtual environment

When you want to deploy your project on another machine, you will want to use the same versions of the packages you used while developing it (i.e., those in the virtual environment). To do this TODO.

Virtual environments and IDEs

Virtual environments present an added layer of complexity when using IDEs. To run the project within the right environment and to get accurate auto completion and the like, the IDE needs to be aware of the virtual environment it should use for the project. Note that this might be a different environment than the one under which the IDE itself is preferred to run.

Each IDE is different, so generalized help is tricky. It might work to run the IDE from a shell that has its virtual environment set as desired, but this will run the IDE itself within that environment, which may not be what you want.

python/development_workflow.1468378194.txt.gz · Last modified: 2016/07/13 02:49 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki