Skip to content

Instantly share code, notes, and snippets.

@mheidari98
Last active February 1, 2022 04:36
Show Gist options
  • Save mheidari98/8ae29b88bd98f8f59828b0ec112811e7 to your computer and use it in GitHub Desktop.
Save mheidari98/8ae29b88bd98f8f59828b0ec112811e7 to your computer and use it in GitHub Desktop.
Install Virtual Environments & Requirements Packages
  1. Virtual Environments

    1. Install the virtualenv package

      $ pip install virtualenv
    2. Create the virtual environment

      $ virtualenv env
      —————OR—————
      $ virtualenv -p /usr/bin/python2.7  virtualenv_name
      $ virtualenv -p /usr/bin/python3   virtualenv_name
      $ virtualenv -p python3 testproject
      —————OR—————
      python -m venv env       
    3. Activate the virtual environment

      • Mac OS / Linux

        $ source env/bin/activate
      • Windows

        $ env\Scripts\activate
    4. Deactivate the virtual environment

      (env) $ deactivate
  2. Save Requirements Packages to file

    In order to keep your environment consistent, it’s a good idea to “freeze” the current state of the environment packages. To do this, run:

    $ pip freeze > requirements.txt
    
  3. Install Requirements Packages

    $ pip install -r requirements.txt
    

Related Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment