Skip to content

Instantly share code, notes, and snippets.

@petarnikolovski
Last active July 26, 2017 09:03
Show Gist options
  • Save petarnikolovski/5a5056eeb175f7c9e10307660acdbd6e to your computer and use it in GitHub Desktop.
Save petarnikolovski/5a5056eeb175f7c9e10307660acdbd6e to your computer and use it in GitHub Desktop.
Setting up and activating virtualenv (Python 3.X)

Installing virtualenv

Virtualenv can be installed using pip:

pip3 install virtualenv

If this approach fails, try:

pip3 install --user virtualenv

Setting up virtualenv inside a project

Make a project directory (for example my_project), and cd into it.

mkdir my_project
cd my_project

Create a virtual environment in a current directory using virtualenv command:

virtualenv .

If this does not work, or if it sets up virtualenv for Python 2.x, you can run virtualenv module as a script:

python3 -m virtualenv .

This should set up virtual environment in a current directory.

Working in virtual environment

To start working in virtual environment, from the root of your project directory (i.e. top level domain directory) type:

source bin/activate

That's it! Now you can install packages in this environment using pip, for example:

pip3 install django

When you're done working within virtual environment, deactivate it by typing:

deactivate

Done!

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