How do I install Python/Django Modules?


Question

I know absolutely nothing about Django, but I am needing to get an existing project running in OSX.

From the project's directory I run python manage.py runserver and get the error: Error: No module named cms.

Seems like the INSTALLED_APPS constant (in settings.py) defines the required modules... but how do I install the dang things?

Is there a standard way of installing dependencies in bulk (like Ruby's Bundler)?

1
14
9/16/2016 5:09:11 PM

Accepted Answer

you can install all dependencies in once, if there is a requirements.txt file! you just have to run the follow command:

pip install -r requirements.txt

otherwise you can install one by one:

pip install django-cms

Here is the PIP documentation: http://pypi.python.org/pypi/pip

if you are used to ruby, you can compared to ruby GEM

23
11/30/2011 11:45:07 PM

The entries in INSTALLED_APPS are package designations. Packages are a way of structuring Python’s module namespace.

When importing a package, Python searches through the directories on sys.path looking for the package subdirectory.

So python has some designated places to look for packages.

To install packages by name to the right location on your system, you could download some python source code and run the setup.py script (usually provided by libraries and applications).

$ cd /tmp
$ wget http://pypi.python.org/packages/source/p/pytz/pytz-2011n.tar.bz2
$ tar xvfj pytz-2011n.tar.bz2
$ cd pytz-2011n
$ python setup.py install

There are, however, shortcuts to this, namely easy_install and it's successor pip. With these tools, installation of a third-party package (or django app) boils down to:

$ pip install pytz

Or, if you use the systems default Python installation:

$ sudo pip install pytz

That's it. You can now use this library, whereever you want. To check, if it installed correctly, just try it in the console:

$ python
Python 2.7.2 (default, Aug 20 2011, 05:03:24)
...
>>> import pytz # you would get an ImportError, if pytz could not be found
>>> pytz.__version__ 
'2011n'

Now for the sake of brevity (this post is much to long already), let's assume pytz were some third party django application. You would just write:

INSTALLED_APPS = (
    'pytz',
)

And pytz would be available in your project.

Note: I you have the time, please take a look at Tools of the Modern Python Hacker: Virtualenv, Fabric and Pip blog post, which highlights some great python infrastructure tools.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon