Jeremy
Jeremy

Reputation: 2536

Django installation using Virtualenv gone wrong

So i have been playing around with python (2.7.x) and django framework on my ubuntu (12.04). The way i setup django based project is by using virtualenv

Which i did it like this

** FROM TERMINAL **
1. sudo apt-get install python-setuptools
2. sudo easy_install virtualenv

Then i continue setting up my directory for my django project by using this command:

virtualenv --no-site-packages project-name

Soon after that, i activated my virtualenv:

source project-name/bin/activate

Then i continue with the Django framework installation using this:

sudo easy_install Django

and verify that Django framework is installed within my virtualenv by checking there is a file called django-admin.py under project-name/bin/ directory (which is exists).

However, the second time i tried to create another django-project (completely different one) following the same exact step as above, I don't have django-admin.py installed in the correct directory. It's get installed to /usr/lib/python...

And when i tried to run the app i get this message:

Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    from django.core.management import execute_from_command_line
ImportError: No module named django.core.management

Does anyone know why is this happening?

Thanks.

* EDITED PART *

responding to sachitad's answer

i get the following message when i executed his/her suggestion

(project-name)blah@blah:~/Documents/python/project-name$ easy_install django
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

[Errno 13] Permission denied: '/home/blah/Documents/python/project-name/lib/python2.7/site-packages/test-easy-install-3775.write-test'

The installation directory you specified (via --install-dir, --prefix, or the distutils default setting) was:

/home/blah/Documents/python/project-name/lib/python2.7/site-packages/

that's why, i initially thought i need to use the sudo command.

Upvotes: 0

Views: 2241

Answers (3)

Anshik
Anshik

Reputation: 711

./home/user/path_to_virtual_env_project_/bin/pip install Django

you call pip which not in virtual env. It seems activate not work.

Upvotes: 0

Joyfulgrind
Joyfulgrind

Reputation: 2836

Problem:

sudo easy_install Django

Even if you have activated the virtualenv, while installing packages inside virtualenv, never ever use sudo. If you use sudo, it assumes you are installing on the system path(/usr/lib/local/..).

Thus,

easy_install django

OR

pip install django

should work.

Upvotes: 3

Agate
Agate

Reputation: 3232

As an addition to sachitad answer, I suggest you have a look at virtualenvwrapper which allow you to manage easily you virutal env with commands like :

mkvirtualenv your_project_name // create a virtual environment
workon your_project_name // select this virtual environment

pip install django // will install in this virtualenv

Upvotes: 2

Related Questions