Download - pip and virtualenv
and now, for something completely different…
pip & virtualenv
Alex Maneu !@zouave
@PyBcn 20/03/2014
what is this about?
package management
when you need something someone else has written
some examples
SciPy
lxml requests
django pymongo
jars gems eggs(wheels)
where to find them?
PyPI
pypi.python.org
Python Package Index
pipRecommended tool for
installing uninstalling upgrading
packages from PyPI
pip basic commandspip install [—-upgrade] <package> Installs a Python package or upgrades it to the latest available version. !Examples pip install pymongo=1.2 pip install /some/dir/mypackage.tgz pip install http://someserver/mypackage.zip pip install git+ssh://myserver/myrepo.git@feature#egg=MyPackage !!pip uninstall <package> Deletes an already installed package
pip basic commandspip list [—-outdated] Lists installed packages !!pip search <string> Searches for packages whose description contains the specified string
> pip list --outdated amqp (Current: 1.3.3 Latest: 1.4.4) billiard (Current: 3.3.0.8 Latest: 3.3.0.16) celery (Current: 3.1.5 Latest: 3.1.9) …
Examples > pip search cassandra cqlengine - Cassandra CQL 3 Object Mapper for Python CassandraLauncher - Command line utilities for launching Cassandra clusters in EC2 pycassa - Python client library for Apache Cassandra …
what happens if…?
> pip install pymongo !
(…) error: could not create '/Library/Python/2.7/site-packages/bson': Permission denied
virtualenvTool for creating
Python environments
i s o l a t e d
virtualenv
v1 v2 v3django
lxml +
site packages
numpy=1.8.0 pymongo
requests>=2.2.0
site packages
pyOpenSSL, pip, numpy=1.6.2
creating a virtual envvirtualenv [options] <dest_dir> Create a new virtual environment at the specified path. It will contain a copy of all system-wide packages. !
Useful options —-no-site-packages
Create a new empty virtual environment. —-python=<python path>
Use the specified Python executable.
switching to a virtual env> source <dir>/bin/activate (v1)> !
!
Exiting current virtualenv (v1)> deactivate >
cool stuff with pip + virtualenv
!
pip freeze > requirements.txt Create a description file with the packages and versions installed under the current virtualenv. !
pip install -r requirements.txt Install all packages according to the specification in requirements.txt.
summary• Packages: code someone else has written
(SciPy, Django, lxml, pymongo)
• Find packages on PyPI: pypi.python.org
• Install them using pip
• Keep your environment clean by using virtualenv
Thank you!
questions?