pip and virtualenv

17
and now, for something completely different…

Upload: amaneu

Post on 01-Jul-2015

2.004 views

Category:

Technology


3 download

DESCRIPTION

pip and virtualenv a lightning talk for the "Python for beginners" meetup Barcelona 20/03/2014

TRANSCRIPT

Page 1: pip and virtualenv

and now, for something completely different…

Page 2: pip and virtualenv

pip & virtualenv

Alex Maneu !@zouave

@PyBcn 20/03/2014

Page 3: pip and virtualenv

what is this about?

package management

when you need something someone else has written

Page 4: pip and virtualenv

some examples

SciPy

lxml requests

django pymongo

Page 5: pip and virtualenv

jars gems eggs(wheels)

Page 6: pip and virtualenv

where to find them?

PyPI

pypi.python.org

Python Package Index

Page 7: pip and virtualenv

pipRecommended tool for

installing uninstalling upgrading

packages from PyPI

Page 8: pip and virtualenv

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

Page 9: pip and virtualenv

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 …

Page 10: pip and virtualenv

what happens if…?

> pip install pymongo !

(…) error: could not create '/Library/Python/2.7/site-packages/bson': Permission denied

Page 11: pip and virtualenv

virtualenvTool for creating

Python environments

i s o l a t e d

Page 12: pip and virtualenv

virtualenv

v1 v2 v3django

lxml +

site packages

numpy=1.8.0 pymongo

requests>=2.2.0

site packages

pyOpenSSL, pip, numpy=1.6.2

Page 13: pip and virtualenv

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.

Page 14: pip and virtualenv

switching to a virtual env> source <dir>/bin/activate (v1)> !

!

Exiting current virtualenv (v1)> deactivate >

Page 15: pip and virtualenv

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.

Page 16: pip and virtualenv

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

Page 17: pip and virtualenv

Thank you!

questions?