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.
pip freeze > archivoConLibrerias.txt<br />
pip install -r archivoConLibrerias.txt<br />
For example:<br />
• pip install django<br />
• pip install -U rst2pdf<br />
However, there are a few problems:<br />
• You have to have admin/root privileges. It’s easy when you’re developing, but<br />
hardly viable in production.<br />
• You cannot install two <strong>version</strong>s of the same package.<br />
This is very important when the package isn’t backwards-compatible. Some<br />
examples are:<br />
• SQLAlchemy<br />
• django<br />
For instance, applications that work wit django 0.9.7 won’t work with django 1.2,<br />
and viceversa. Because of the way <strong>Python</strong>’s package system works, it only allows<br />
one <strong>version</strong> of any package.<br />
Therefore, one has to choose which <strong>version</strong> to use.<br />
Using virtualenv<br />
To solve these problems there is virtualenv. It takes care of creating an isolated <strong>Python</strong><br />
environment within the system. First, you have to install it:<br />
easy_install virtualenv<br />
This will create a folder environmentName in the directory we’re sitting. If you didn’t<br />
install it into the system, if you downloaded the tarball, then use<br />
python virtualenv.py environmentName<br />
The previous command created a <strong>Python</strong> environment that is separate from the system’s<br />
global configuration. Therefore, one does not have any permission problems there<br />
because one owns the tree.<br />
To tell the operating system that we want to use the environment we just created, and<br />
not the system’s, it is necessary to activate it.<br />
Linux:<br />
source environmentName/bin/activate<br />
Windows:<br />
environmentName\Scripts\activate.bat<br />
Both in windows and in linux, when you activate an environment, you’ll see the name of<br />
the activated environment between parenthesis:<br />
(environmentName)tzulberti@myhost:~<br />
When you have an active environment, you can see that the python you’re using is not<br />
the global one, but the one inside a folder virtualenv created.<br />
(environmentName)tzulberti@myhost:which python<br />
/home/tzulberti/environmentName/bin/python<br />
This is the only time you’ll need to be root/admin to install a library. All the servers that<br />
allow hosting python projects have it preinstalled.<br />
If you don’t have root/administrator privileges, you can also use it without installing it<br />
into the system. For this, you can download the tarball from:<br />
http://pypi.python.org/pypi/virtualenv<br />
Once installed, the first thing to do is to create a virtual environment:<br />
The same happens with easy_install and pip. Also, any packages installed will be<br />
installed within the virtual environment.<br />
To stop using the environment we have to do the following:<br />
Linux:<br />
deactive<br />
virtualenv environmentName<br />
Windows: