I used to be developing a Django
app using a stable version (1.6) of Django I got installed on Ubuntu using sudo apt-get install python-django
, and I also used the Django packages sorl-thumbnail
and tastypie
.
I have since wanted to switch to using Django
's development version, and so I installed it with the instructions in their documentation:
git clone git://github.com/django/django.git django-trunk
sudo pip install -e django-trunk/
On my machine, Django
is now located in ~/git/django-trunk
.
However, when I go back to my Django
project directory and run python manage.py syncdb
I seem to get:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/$USER/git/django-trunk/django/core/management/__init__.py", line 427, in execute_from_command_line
utility.execute()
File "/home/$USER/git/django-trunk/django/core/management/__init__.py", line 391, in execute
django.setup()
File "/home/$USER/git/django-trunk/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/$USER/git/django-trunk/django/apps/registry.py", line 84, in populate
app_config = AppConfig.create(entry)
File "/home/$USER/git/django-trunk/django/apps/base.py", line 86, in create
"cannot import name '%s' from '%s'" % (cls_name, mod_path))
ImportError: cannot import name 'thumbnail' from 'sorl'
Is this because Django
no longer knows where my installed Django
apps are?
I think they are in /usr/local/lib/python2.7/dist-packages
if that helps...
How do I fix this error and get all my Django
apps to work with the development version? Did I simply need to git clone
the Django
development version into /usr/local/lib/python2.7/dist-packages
, or something else?
Any help would be greatly appreciated, thank you so much in advance!
You need to use a virtual environment, and install the dependencies for your project in each virtual environment.
This way, the Python interpreter will have access to the required libraries at all times. To get started:
sudo apt-get install -y python-virtualenv
This will install any required libraries to make virtualenv
work; then for each project you start by creating a fresh virtual environment. All these commands are run as your normal user (without sudo
):
$ virtualenv django_env
$ source django_env/bin/activate
(django_env) $ pip install django tastypie solr-thumbnail
Typing activate
will activate the enviornment, so your shell will point to the correct versions of Python. You'll note the (django_env)
which indicates the environment is currently active.
From this point on, anything you install will be installed only in this virtual environment. Once you are finished working, typing deactivate
will return you back to the system Python environment:
(django_env) $ deactivate
$