Background Image
Table of Contents Table of Contents
Previous Page  171 / 478 Next Page
Information
Show Menu
Previous Page 171 / 478 Next Page
Page Background

$

which python3

/usr/bin/python3

$

source ../virtualenv/bin/activate

$

which python

# note switch to virtualenv Python

/workspace/virtualenv/bin/python

(virtualenv)$

python3 manage.py test lists

[...]

ImportError: No module named 'django'

It’s not required, but you might want to look into a tool called

vir

tualenvwrapper

for managing virtualenvs on your own PC.

Virtualenvs on Windows

On Windows, things are slightly different. There are two main things to watch out for:

• The

virtualenv/bin

folder is called

virtualenv/Scripts

, so you should substitute that

in as appropriate.

• When using Git-Bash, do not try and run

activate.bat

—it is written for the DOS

shell. Use

source ..\virtualenv\Scripts\activate

. The

source

is important.

We’re seeing that

ImportError: No module named django

because Django isn’t in‐

stalled inside the virtualenv. So, we can install it, and see that it ends up inside the

virtualenv’s

site-packages

folder:

(virtualenv)$

pip install django==1.7

[...]

Successfully installed django

Cleaning up...

(virtualenv)$

python3 manage.py test lists

[...]

OK

$

ls ../virtualenv/lib/python3.4/site-packages/

django pip setuptools

Django-1.7-py3.4.egg-info pip-1.4.1-py3.4.egg-info setuptools-0.9.8-py3.4.egg-info

easy_install.py pkg_resources.py

_markerlib __pycache__

To “save” the list of packages we need in our virtualenv, and be able to re-create it later,

we create a

requirements.txt

file, using

pip freeze

, and add that to our repository:

(virtualenv)$

pip freeze > requirements.txt

(virtualenv)$

deactivate

$

cat requirements.txt

Django==1.7

Deploying Our Code Manually

|

143