python handouts virtualenv

Upload: luke-constable

Post on 06-Jul-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/17/2019 Python Handouts Virtualenv

    1/2

    4/1/2016 python-handouts/virtualenv.md at master · s tanfordpython/python-handouts · GitHub

    https://github.com/stanfordpython/python-handouts/blob/master/virtualenv.md 1/2

    python-handouts / virtualenv.md

    1 0 3Watch Star Forkstanfordpython / python-handouts

    Code Issues 0 Pull requests 0 Pulse Graphs

    master Find le Copy path

    2 contributors

    a725818 a day agosredmond Update virtualenv.md

    46 lines (24 sloc) 2.67 KB

    Virtual Environm ents

    What is a virtual environment? A virtual environment is simply an isolated folder that contains all the executables you need to build something awesome in

    Python, including code to run the interpreter, use the standard library ( https://docs.python.org/3.4/library/ ), and install other

    3rd-party libraries that we'll touch on towards the end of the quarter.

    Why b other usi ng v irtual environments?

    Of co urse, yo u can a lso d evelop Python projects without a virtual environment, but it's a good idea to become familiar with

    this tool because you can avoid dependency conicts between your system-wide Python installations and your project-

    specic Python installations. For example, if you're using Python to build 3 separate Web apps because you're a beast,

    Project A might depend on Django version 1.2 while Project C depends on Django version 1.9 (yes, Django is the name of a

    real Web framework: https://docs.djangoproject.com/en/1.9/releases/ ). You can create a separate virtual environment for

    each project then install whichever version you need in each project. When you ship awesome projects later in your Python

    career, you'll know the exact libraries and versions that your project requires (:

    How to create virtual environment

    In class we audibled to using a piece of software called virtualenv to build virtual environments because some people had

    trouble with the virtualenvwrapper software. After you've installed Python3 and pip (see

    https://github.com/stanfordpython/python-handouts/blob/master/installing-python.md#linux if you need help with this step),

    you're almost done. Here's the rest of the commands to execute:

    Install the software (only do this once)

    $ pip install virtualenv

    this uses pip to install the software used to build your virtual environments, called virtualenv

    Creating a virtual environment

    cd to your Desktop then execute

    Raw Blame History

    Personal Open source Business Explore Pricing Blog Support This repository Search Sign upSign in

    https://docs.python.org/3.4/library/https://github.com/stanfordpython/python-handoutshttps://github.com/stanfordpython/python-handouts/issueshttps://github.com/stanfordpython/python-handouts/pullshttps://github.com/stanfordpython/python-handouts/pulsehttps://github.com/stanfordpython/python-handouts/graphshttps://github.com/personalhttps://github.com/open-sourcehttps://github.com/businesshttps://github.com/explorehttps://github.com/login?return_to=%2Fstanfordpython%2Fpython-handouts%2Fblob%2Fmaster%2Fvirtualenv.mdhttps://github.com/join?source=header-repohttps://help.github.com/https://github.com/bloghttps://github.com/pricinghttps://github.com/explorehttps://github.com/businesshttps://github.com/open-sourcehttps://github.com/personalhttps://github.com/https://mac.github.com/https://github.com/stanfordpython/python-handouts/commits/master/virtualenv.mdhttps://github.com/stanfordpython/python-handouts/blame/master/virtualenv.mdhttps://github.com/stanfordpython/python-handouts/raw/master/virtualenv.mdhttps://github.com/stanfordpython/python-handouts/blob/master/installing-python.md#linuxhttps://docs.djangoproject.com/en/1.9/releases/https://docs.python.org/3.4/library/https://github.com/stanfordpython/python-handouts/commits/master/virtualenv.md?author=sredmondhttps://github.com/stanfordpython/python-handouts/commits/master/virtualenv.md?author=csmith95https://github.com/stanfordpython/python-handouts/commit/a725818dd954a1a2e8ea6d1096ca24da2591d338https://github.com/sredmondhttps://github.com/stanfordpython/python-handouts/commit/a725818dd954a1a2e8ea6d1096ca24da2591d338https://github.com/stanfordpython/python-handouts/find/masterhttps://github.com/stanfordpython/python-handouts/graphshttps://github.com/stanfordpython/python-handouts/pulsehttps://github.com/stanfordpython/python-handouts/pullshttps://github.com/stanfordpython/python-handouts/issueshttps://github.com/stanfordpython/python-handoutshttps://github.com/stanfordpython/python-handoutshttps://github.com/stanfordpythonhttps://github.com/login?return_to=%2Fstanfordpython%2Fpython-handoutshttps://github.com/login?return_to=%2Fstanfordpython%2Fpython-handoutshttps://github.com/login?return_to=%2Fstanfordpython%2Fpython-handoutshttps://github.com/stanfordpython/python-handouts/networkhttps://github.com/stanfordpython/python-handouts/stargazershttps://github.com/stanfordpython/python-handouts/watchershttps://github.com/stanfordpython/python-handouts

  • 8/17/2019 Python Handouts Virtualenv

    2/2

    4/1/2016 python-handouts/virtualenv.md at master · s tanfordpython/python-handouts · GitHub

    https://github.com/stanfordpython/python-handouts/blob/master/virtualenv.md 2/2

    $ virtualenv cs41

    this uses virtualenv to create a new virtual environment in the working directory named cs41. you should be able to see this

    folder on your Desktop now.

    Activating and deactivating a virtual environment

    To activate, simply cd into the environment we created above then execute

    $ source bin/activate

    Now you can play with the interactive interpreter inside your isolated environment using

    $ python3

    You can also create new les, modules, whatever you need to make a beautiful Python project ready to ship! To deactivate,

    type

    $ deactivate

    All done! If you want to read more about the above steps, check out http://docs.python-guide.org/en/latest/dev/virtualenvs/

    If you want to read about the interactive interpreter, check out http://www.python-course.eu/python3_interactive.php

    Status API Training Shop Blog About© 2016 GitHub, Inc. Terms Privacy Security Contact Help

    https://help.github.com/https://github.com/contacthttps://github.com/securityhttps://github.com/site/privacyhttps://github.com/site/termshttps://github.com/abouthttps://github.com/bloghttps://shop.github.com/https://training.github.com/https://developer.github.com/https://status.github.com/http://www.python-course.eu/python3_interactive.phphttp://docs.python-guide.org/en/latest/dev/virtualenvs/