SlideShare a Scribd company logo
4
Most read
8
Most read
9
Most read
Larry cai <larry.caiyu#gmail.com>
Agenda
Python Virtualenv & Pip in 90 minutes2
 What isVirtualenv & Pip ?
 Environment : InstallVirtualenv on windows (Linux is
easy)
 Exercise 1: Create own environment using virtualenv
 Exercise 2: Learn pip command
 Exercise 3: Create own Pip package
 Exercise 4: Make scripts runnable directly
 Bonus Exercise: Share your scripts outside
!!!! Exercise are created by me, and some introduction slides are
copied from http://www.slideshare.net/webdebs/virtualenv-12727213
Problem for using python
 How to install the packages ?
(download & python setup.py install)
 How to use different python versions (2.6,2.7,3.x..)?
 How to install different packages (0.2,0.3.)
 How to test some packages without ruin the system
 How to delivery your python codes to other ?
 How to verify them ?
 …
Python Virtualenv & Pip in 90 minutes3
What is Pip & PyPi & Virtualenv
 pip is a tool for installing and managing Python packages 
 It’s a replacement for easy_install.
 PyPi (Python Pakage Index) is a repository of software for
Python and currently count 33429 package
 https://pypi.python.org/pypi
 Virtualenv is a tool to isolate your python environment
Python Virtualenv & Pip in 90 minutes4
Environment
Python Virtualenv & Pip in 90 minutes5
 Python 2.7.x In Windows with Git Bash
 http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi (2.7.5
has issues with pycrypto)
 Add into Path
 Install Pip (Python package management)
 curl -O http://python-distribute.org/distribute_setup.py
 python distribute_setup.py
 easy_install pip
 InstallVirtualenv
 pip --version
 pip install virtualenv
http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows
WHY virtual environments ?
 Isolation - Python packages and even version live in their
own planet :)
 Permissions - No sudoers, the environment is mine!!!
 Organization - each project can maintain its own
requirements file of Python packages.
 No-Globalization – don’t require installing stuff globally
on the system.
Python Virtualenv & Pip in 90 minutes6
Exercise 1: Create own environment
Python Virtualenv & Pip in 90 minutes7
 Create own environment
$ pip list # if error, $ pip install --upgrade setuptools
$ cd ~
$ virtualenv venv
$ find venv
$ . venv/Scripts/activate
$ pip list
$ pip install python-jenkins xunitparser
$ pip list
$ find ~/venv | grep unit
$ deactivate
$ pip list
Exercise 2: learn pip
 Install , uninstall, upgrade packages
$ . ~/venv/Scripts/activate
$ pip install junit-xml # latest version
$ pip uninstall junit-xml
$ pip install junit-xml==1.2 # specific version
$ pip install --upgrade junit-xml
 Generate package list and restore
$ pip list
$ pip freeze > requirements.txt
$ pip uninstall junit-xml xunitparser
$ pip install -r requirements.txt
 Install local packages from mirror
$ pip install --index-url http://my.package.repo/simple/ <yourpackage>
Python Virtualenv & Pip in 90 minutes8
http://www.pip-installer.org/en/latest/usage.html
Exercise 3: Create your own package
 Write a simple hello.py under hello folder
print “hello world”
 Write a setup.py
from distutils.core import setup
setup(name=‘hello',
version=‘0.0.1',
py_modules=[‘hello'], )
 Package and install
$ python setup.py sdist
$ pip install dist/hello.0.0.1.zip
$ find ~/venv | grep hello
 Change version to “0.0.2” and do it again
Python Virtualenv & Pip in 90 minutes9
http://docs.python.org/2/distutils/introduction.html
Exercise 4: make your scripts runnable
 Make the hello.py can be runnable after installation
from distutils.core import
setup setup(name=‘hello',
version=‘0.0.3’,
scripts=[‘hello.py’],
py_modules=[‘hello'], )
 Testing it
$ python setup.py sdist
$ pip install dist/hello.0.0.3.zip
$ find ~/venv | grep hello
 Make it runnable (change hello.py ..)
$ hello.py # bingo, so simple
Python Virtualenv & Pip in 90 minutes10
Bonus: Share your scripts outside
 https://pypi.python.org/pypi register and
$ python setup.py register sdist upload # that’s all
 Simpler than your thinking ….
Python Virtualenv & Pip in 90 minutes11
Summary
 Using virtualenv to isolate your python environment
 Use pip to package
 Host in github and shared in PyPi repository
 Enjoy python programming
Python Virtualenv & Pip in 90 minutes12
Reference
 Slides
 http://www.slideshare.net/webdebs/virtualenv-12727213
 Usage link
 http://www.pip-installer.org/en/latest/usage.html
 https://pypi.python.org/pypi
 http://docs.python.org/2/distutils/introduction.html
 https://pypi.python.org/pypi/virtualenv
Python Virtualenv & Pip in 90 minutes13

More Related Content

PPTX
PPT on Data Science Using Python
PPTX
Basics of JAVA programming
PPT
SQLITE Android
PDF
Python Collections Tutorial | Edureka
PDF
Control structures functions and modules in python programming
PPTX
Map Reduce
PPT
Introduction to Web Programming - first course
PPT on Data Science Using Python
Basics of JAVA programming
SQLITE Android
Python Collections Tutorial | Edureka
Control structures functions and modules in python programming
Map Reduce
Introduction to Web Programming - first course

What's hot (20)

PDF
A Basic Django Introduction
PPTX
Laravel ppt
PDF
Introduction to NumPy (PyData SV 2013)
PDF
Hadoop YARN
PDF
Php tutorial(w3schools)
PPTX
Web Scraping Basics
PPT
PHP POWERPOINT SLIDES
PDF
Introduction to Hadoop
PPTX
Lecture 7: Server side programming
PPT
Collection Framework in java
PPSX
Java IO, Serialization
PDF
Network programming Using Python
PDF
Methods in Java
PDF
Introduction to django framework
PPTX
AWS big-data-demystified #1.1 | Big Data Architecture Lessons Learned | English
PPTX
Python Seaborn Data Visualization
PDF
The Data Science Process
PDF
DATA VISUALIZATION USING MATPLOTLIB (PYTHON)
PDF
Big Data Analytics with Spark
PPTX
Introduction of data science
A Basic Django Introduction
Laravel ppt
Introduction to NumPy (PyData SV 2013)
Hadoop YARN
Php tutorial(w3schools)
Web Scraping Basics
PHP POWERPOINT SLIDES
Introduction to Hadoop
Lecture 7: Server side programming
Collection Framework in java
Java IO, Serialization
Network programming Using Python
Methods in Java
Introduction to django framework
AWS big-data-demystified #1.1 | Big Data Architecture Lessons Learned | English
Python Seaborn Data Visualization
The Data Science Process
DATA VISUALIZATION USING MATPLOTLIB (PYTHON)
Big Data Analytics with Spark
Introduction of data science
Ad

Similar to Python virtualenv & pip in 90 minutes (20)

ODP
Virtualenv
ODP
5 minute intro to virtualenv
PDF
Princeton RSE: Building Python Packages (+binary)
PDF
Arbeiten mit distribute, pip und virtualenv
PDF
Virtualenv
PDF
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
PDF
Arbeiten mit distribute, pip und virtualenv
PPTX
First python project
PDF
Virtual environment in python on windows / linux os
PDF
Python packaging and dependency resolution
PDF
How to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdf
PPT
10 11-hart installing pythonsoftware
PDF
How to Install Odoo 17 on Ubuntu.pdf
PDF
How to install AI open source tool and environment
PDF
Share your code with the Python world by
 creating pip packages
PDF
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
PDF
Using the pip package manager for Odoo
PDF
Django district pip, virtualenv, virtualenv wrapper & more
PPTX
E D - Environmental Dependencies in Python
PDF
Python Dependency Management - PyconDE 2018
Virtualenv
5 minute intro to virtualenv
Princeton RSE: Building Python Packages (+binary)
Arbeiten mit distribute, pip und virtualenv
Virtualenv
Christian Strappazzon - Presentazione Python Milano - Codemotion Milano 2017
Arbeiten mit distribute, pip und virtualenv
First python project
Virtual environment in python on windows / linux os
Python packaging and dependency resolution
How to Install Python 2 on Ubuntu 2404 3 Quick Methods.pdf
10 11-hart installing pythonsoftware
How to Install Odoo 17 on Ubuntu.pdf
How to install AI open source tool and environment
Share your code with the Python world by
 creating pip packages
Using the "pip" package manager for Odoo/OpenERP - Opendays 2014
Using the pip package manager for Odoo
Django district pip, virtualenv, virtualenv wrapper & more
E D - Environmental Dependencies in Python
Python Dependency Management - PyconDE 2018
Ad

More from Larry Cai (20)

PPTX
Learn kubernetes in 90 minutes
PPT
Learn jobDSL for Jenkins
PPT
Learn RabbitMQ with Python in 90mins
PPT
Learn flask in 90mins
PPT
Learn ELK in docker
PPT
Software Engineer Talk
PPTX
Learn nginx in 90mins
PPT
Learn basic ansible using docker
PPT
Build service with_docker_in_90mins
PPTX
Learn docker in 90 minutes
PPT
Learn Dashing Widget in 90 minutes
PPT
Learn REST API with Python
PPT
Jenkins Scriptler in 90mins
PPT
Lead changes in software development
PPT
Python in 90mins
PDF
Practical way to experience of Specification by Example
PPT
Experience from specification_by_examples
PPT
Write book in markdown
PPT
Continuous Integration Introduction
PDF
Agile & ALM tools
Learn kubernetes in 90 minutes
Learn jobDSL for Jenkins
Learn RabbitMQ with Python in 90mins
Learn flask in 90mins
Learn ELK in docker
Software Engineer Talk
Learn nginx in 90mins
Learn basic ansible using docker
Build service with_docker_in_90mins
Learn docker in 90 minutes
Learn Dashing Widget in 90 minutes
Learn REST API with Python
Jenkins Scriptler in 90mins
Lead changes in software development
Python in 90mins
Practical way to experience of Specification by Example
Experience from specification_by_examples
Write book in markdown
Continuous Integration Introduction
Agile & ALM tools

Recently uploaded (20)

PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Pre independence Education in Inndia.pdf
PPTX
master seminar digital applications in india
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Pharma ospi slides which help in ospi learning
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Business Ethics Teaching Materials for college
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Cell Types and Its function , kingdom of life
Pre independence Education in Inndia.pdf
master seminar digital applications in india
TR - Agricultural Crops Production NC III.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Pharma ospi slides which help in ospi learning
PPH.pptx obstetrics and gynecology in nursing
Anesthesia in Laparoscopic Surgery in India
Supply Chain Operations Speaking Notes -ICLT Program
Business Ethics Teaching Materials for college
STATICS OF THE RIGID BODIES Hibbelers.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Python virtualenv & pip in 90 minutes

  • 2. Agenda Python Virtualenv & Pip in 90 minutes2  What isVirtualenv & Pip ?  Environment : InstallVirtualenv on windows (Linux is easy)  Exercise 1: Create own environment using virtualenv  Exercise 2: Learn pip command  Exercise 3: Create own Pip package  Exercise 4: Make scripts runnable directly  Bonus Exercise: Share your scripts outside !!!! Exercise are created by me, and some introduction slides are copied from http://www.slideshare.net/webdebs/virtualenv-12727213
  • 3. Problem for using python  How to install the packages ? (download & python setup.py install)  How to use different python versions (2.6,2.7,3.x..)?  How to install different packages (0.2,0.3.)  How to test some packages without ruin the system  How to delivery your python codes to other ?  How to verify them ?  … Python Virtualenv & Pip in 90 minutes3
  • 4. What is Pip & PyPi & Virtualenv  pip is a tool for installing and managing Python packages   It’s a replacement for easy_install.  PyPi (Python Pakage Index) is a repository of software for Python and currently count 33429 package  https://pypi.python.org/pypi  Virtualenv is a tool to isolate your python environment Python Virtualenv & Pip in 90 minutes4
  • 5. Environment Python Virtualenv & Pip in 90 minutes5  Python 2.7.x In Windows with Git Bash  http://www.python.org/ftp/python/2.7.3/python-2.7.3.msi (2.7.5 has issues with pycrypto)  Add into Path  Install Pip (Python package management)  curl -O http://python-distribute.org/distribute_setup.py  python distribute_setup.py  easy_install pip  InstallVirtualenv  pip --version  pip install virtualenv http://stackoverflow.com/questions/4750806/how-to-install-pip-on-windows
  • 6. WHY virtual environments ?  Isolation - Python packages and even version live in their own planet :)  Permissions - No sudoers, the environment is mine!!!  Organization - each project can maintain its own requirements file of Python packages.  No-Globalization – don’t require installing stuff globally on the system. Python Virtualenv & Pip in 90 minutes6
  • 7. Exercise 1: Create own environment Python Virtualenv & Pip in 90 minutes7  Create own environment $ pip list # if error, $ pip install --upgrade setuptools $ cd ~ $ virtualenv venv $ find venv $ . venv/Scripts/activate $ pip list $ pip install python-jenkins xunitparser $ pip list $ find ~/venv | grep unit $ deactivate $ pip list
  • 8. Exercise 2: learn pip  Install , uninstall, upgrade packages $ . ~/venv/Scripts/activate $ pip install junit-xml # latest version $ pip uninstall junit-xml $ pip install junit-xml==1.2 # specific version $ pip install --upgrade junit-xml  Generate package list and restore $ pip list $ pip freeze > requirements.txt $ pip uninstall junit-xml xunitparser $ pip install -r requirements.txt  Install local packages from mirror $ pip install --index-url http://my.package.repo/simple/ <yourpackage> Python Virtualenv & Pip in 90 minutes8 http://www.pip-installer.org/en/latest/usage.html
  • 9. Exercise 3: Create your own package  Write a simple hello.py under hello folder print “hello world”  Write a setup.py from distutils.core import setup setup(name=‘hello', version=‘0.0.1', py_modules=[‘hello'], )  Package and install $ python setup.py sdist $ pip install dist/hello.0.0.1.zip $ find ~/venv | grep hello  Change version to “0.0.2” and do it again Python Virtualenv & Pip in 90 minutes9 http://docs.python.org/2/distutils/introduction.html
  • 10. Exercise 4: make your scripts runnable  Make the hello.py can be runnable after installation from distutils.core import setup setup(name=‘hello', version=‘0.0.3’, scripts=[‘hello.py’], py_modules=[‘hello'], )  Testing it $ python setup.py sdist $ pip install dist/hello.0.0.3.zip $ find ~/venv | grep hello  Make it runnable (change hello.py ..) $ hello.py # bingo, so simple Python Virtualenv & Pip in 90 minutes10
  • 11. Bonus: Share your scripts outside  https://pypi.python.org/pypi register and $ python setup.py register sdist upload # that’s all  Simpler than your thinking …. Python Virtualenv & Pip in 90 minutes11
  • 12. Summary  Using virtualenv to isolate your python environment  Use pip to package  Host in github and shared in PyPi repository  Enjoy python programming Python Virtualenv & Pip in 90 minutes12
  • 13. Reference  Slides  http://www.slideshare.net/webdebs/virtualenv-12727213  Usage link  http://www.pip-installer.org/en/latest/usage.html  https://pypi.python.org/pypi  http://docs.python.org/2/distutils/introduction.html  https://pypi.python.org/pypi/virtualenv Python Virtualenv & Pip in 90 minutes13