User Tools

Site Tools


python:development_workflow

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
python:development_workflow [2016/07/13 00:51] mithatpython:development_workflow [2017/05/07 15:09] (current) – [Getting a list of packages in the virtual environment] mithat
Line 1: Line 1:
-====== Python Development Workflow ======+====== Python Project Workflow ======
  
-Node.js has ''npm'' and ''package.json'' files, PHP has ''composer'' and ''composer.json'' files, and Python has ''pip'' and virtual environments, which don't work quite like ''npm'' and ''composer''.+For managing 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 ===== ===== 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 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 you have ''pip'', ''virtualenv'' and ''virtualenvwrapper'' installed on your system is as follows:+The easiest way to go about things assuming your have ''pip'', ''virtualenv'' and ''virtualenvwrapper'' installed on your system is as follows:
  
   - Create a directory for your project: <code bash>$ mkdir ~/Dev/MyProject</code>   - Create a directory for your project: <code bash>$ mkdir ~/Dev/MyProject</code>
-  - Create a virtual environment for you project: <code bash>$ mkvirtualenv MyProject</code> The actual virtual environment will be in ''~/.virtualenvs/''.+  - Create a virtual environment for your project: <code bash>$ mkvirtualenv MyProject</code> The actual virtual environment will be in ''~/.virtualenvs/''.
   - Enable the virtual environment: <code bash>$ workon MyProject</code>   - Enable the virtual environment: <code bash>$ workon MyProject</code>
   - Install the packages you need: <code bash>$ pip install <whatever></code>   - Install the packages you need: <code bash>$ pip install <whatever></code>
Line 17: Line 17:
   * To see what environments are available: <code bash>$ workon</code> without an argument.   * To see what environments are available: <code bash>$ workon</code> without an argument.
   * To set the Python version you want to use:<code bash>$ mkvirtualenv -p /usr/bin/python3 MyProject</code>   * To set the Python version you want to use:<code bash>$ mkvirtualenv -p /usr/bin/python3 MyProject</code>
 +
 +===== Getting a list of packages in the virtual environment =====
 +When you want to deploy your project on another machine, you will want the environment on the host to use the same versions of the packages
 +you used while developing it (i.e., those in your virtual environment). The process of generating a list of those packages and re-installing them is discussed in this [[http://blog.miguelgrinberg.com/post/the-package-dependency-blues|this post]] from Miguel Grinberg's blog and in this [[http://stackoverflow.com/questions/5172029/tools-best-practices-for-managing-application-dependencies|Stack Overflow post]].
  
 ===== Virtual environments and IDEs ===== ===== Virtual environments and IDEs =====
-What about if you want to use an IDE or other GUI tools? TODO+Virtual environments present an added layer of complexity when using IDEs. To have the project run within the right environment and to get accurate auto completion and the like, the IDE needs somehow to be aware of the virtual environment it should use. 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 as well, which may not be what you want.
python/development_workflow.1468371090.txt.gz · Last modified: 2016/07/13 00:51 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki