21.01.2015 Views

color version - PET: Python Entre Todos - Python Argentina

color version - PET: Python Entre Todos - Python Argentina

color version - PET: Python Entre Todos - Python Argentina

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

• Though python knows how to read text and binary files, it’s easier if it simply<br />

converts certain file formats to python structures.<br />

Where to look for third-party libraries<br />

http://pypi.python.org/pypi<br />

There are around 11.000 libraries ready to use. As we saw in Roberto Alsina’s lecture<br />

(import antigravity), there are libraries to do mostly anything:<br />

• Colored console output<br />

• Alternative interactive python consoles (bpython, ipython)<br />

• Working with weird file formats<br />

• Downloading files from cuevana<br />

• Downloading videos from youtube<br />

• Parsing xml using jQuery-like syntax<br />

• AND LOTS MORE<br />

How do we install packages from PyPi<br />

First, you need to install python-setuptools.<br />

This depends on the operating system:<br />

• Ubuntu:<br />

apt-get install python-setuptools<br />

easy_install libraryName<br />

For example:<br />

• easy_install django<br />

• easy_install yaml<br />

• easy_install pylons==1.0<br />

• easy_install -U rst2pdf<br />

Something important to note is that the easy_install command also installs all the<br />

dependencies. For instance, rst2pdf depends on Pygments and reportlab. If you run:<br />

easy_install rst2pdf<br />

Then reportlab and Pygments will also be installed. For those using Ubuntu, easy_install<br />

works like apt-get.<br />

There is an alternative to easy_install called pip. I’d recommend using that option.<br />

easy_install pip<br />

Pip can do all that easy_install did, and some more:<br />

• Searching in pypi<br />

pip search rst2pdf<br />

• Windows: you have to download an .exe from here:<br />

http://pypi.python.org/pypi/setuptools/0.6c11#windows<br />

<strong>Python</strong> packages are generally distributed in an .egg file. These files are a kind of zip<br />

(with a different extension) that:<br />

• Have the source code<br />

• Have other common files (images, sounds, documentation, etc…)<br />

• Have an all too important metadata files: setup.py<br />

• To install .egg files you need to install first a module called setuptools.<br />

• Uninstalling packages<br />

pip uninstall rst2pdf<br />

• Listing installed libraries<br />

pip freeze<br />

• Install all the packages in a file<br />

Once setuptools has been installed, you’ll have the easy_install command made<br />

available.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!