color version - PET: Python Entre Todos - Python Argentina
color version - PET: Python Entre Todos - Python Argentina
color version - PET: Python Entre Todos - Python Argentina
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
environmentName\Scripts\deactivate.bat<br />
How does virtualenv work<br />
When one creates an environment, inside it three folders are created:<br />
• bin: when one has the environment active, and executes a command like python,<br />
pip or easy_install, one of the binaries in this folder is ran, instead of the system’s.<br />
• include: it’s simply a link to the files installed with <strong>Python</strong>.<br />
• lib: this is another important folder. Just like include it has a folder named python,<br />
but in contrast to include, this one isn’t a link to the files installed with <strong>Python</strong>.<br />
Instead, the folder has two important things:<br />
• A link to some <strong>Python</strong> files. In this case, the .py<br />
• A folder, site-packages, which is where packages are installed when one<br />
uses pip or easy_install<br />
Q & A session (Part 1)<br />
Before I commented that one of the problems we had was that we couldn’t install two<br />
<strong>version</strong>s of the same library. What I never did is comment how this problem is solved.<br />
The solution is easy. You create a virtual environment to use with django 0.97, and<br />
another for 1.2. You can create as many virtual environments as you wish, and they’re<br />
isolated from each other.<br />
For production servers, there are configurations that can be set up in apache for it to use<br />
some specific virtual environment.<br />
Q & A session (Part 2)<br />
I create a virtualenv, activate it, and do pip freeze, and lots of things that I never<br />
installed appear in the environment.<br />
The default behavior of virtualenv when one creates an environment is to also create it<br />
with the packages one has installed in the system. For it not to do this, when you create<br />
the environment, you can do:<br />
virtualenv --no-site-packages environmentName<br />
This makes it create a completely empty environment. Lastly, another option to note is<br />
—python, which makes the virtual environment use that <strong>version</strong> of python (it is<br />
necessary to have installed that <strong>version</strong> for this to work). For instance, in my machine I<br />
have both <strong>Python</strong> 2.7 and 3.1, being 2.7 the default one.<br />
Thus, when I create an environment, it will be created with <strong>Python</strong> 2.7. For it to use<br />
<strong>Python</strong> 3.1, I have to do the following:<br />
virtualenv --python=python3.1 environmentName<br />
Q & A session (Part 3)<br />
There are some packages that have code written in C. What happens with those<br />
Well, in those cases pip or easy_install will try to build the C code when the package is<br />
installed. In distros like Ubuntu, I recommend installing:<br />
• build-essential<br />
• python-dev<br />
Those two packages make it much easier to build.<br />
However, in Windows it is not so easy. Several packages that have C code are distributed<br />
as an .exe too. However, those installers do not allow us to select where to install them.<br />
Here<br />
http://www.developerzen.com/2010/09/23/the-complete-guide-to-setting-up-python-develo<br />
is a very good guide on how to make it build packages as it downloads it.<br />
Q & A session (Part 4)<br />
Do you recommend installing system packages or is it better to use easy_install<br />
There are various distros that come with various python packages that can be installed in<br />
the system. For example:<br />
apt-get python-numpy python-reportlab python-pil<br />
But the <strong>version</strong>s that can be installed with apt-get are old. Here we’ll see some<br />
comparative examples:<br />
Package name Ubuntu 10.10 <strong>version</strong> PyPi <strong>version</strong><br />
rst2pdf 0.14.2 0.16<br />
reportlab 2.4.3 2.5<br />
django 1.2.3 1.2.3<br />
Thus, it depends on what one wants to do. For instance, if one wants to make a program<br />
work with Ubuntu, then one can create a virtual environment and install the same