Reputation: 6525
I am working in ubuntu. I have installed the django==1.3 in root earlier. Now I created local virtual environment name as local_env using virtualenv
. Then I activated the local_env using source command.But I didn't install the django in this local_env environment. When I try to create the django sample project using
django-admin.py startproject sampleproject
it is working perfectly. My question is,It didn't prevent the local_env from the root environment ?. I mean it didn't raise the error like django-admin.py command didn't found
. Please put the comments if any doubts.
Upvotes: 1
Views: 367
Reputation: 2406
According to the docs, the django-admin.py command is installed on your system path, so if the virtualenv doesn't find this command, it will probably look in the global sys path and find a match.
If you want to use a different version of django to the one installed on your sys path, you will need to install it in your vritualenv using a package manager like pip and this will then take precedent over the global django-admin.py
To make sure you're doing this right, load your the virtualenv using
dhanna@dhanna:~$ source local_env/bin/actviate
If successful, your prompt should have the virtualenv name at the beginning - eg
(local_env)dhanna@dhanna:~$
Note that if you activate the virtualenv in one shell, but run the python interpreter inside a separate shell, you will be using the global interpreter and therefore have the global django-admin.py module available.
Next you'll want to install the django module
(local_env)dhanna@dhanna:~$ pip install django
To check if django is installed inside your virtual env, you can use the package management tool pip and pass the freeze argument
(local_env)dhanna@dhanna:~$ pip freeze
Now you can use the virtualenv's version of django-admin.py
(local_env)dhanna@dhanna:~$ django-admin.py startproject sampleproject
Upvotes: 0
Reputation: 2598
django-admin.py
is in the OS path. When you try executing it inside your virtual environment, the python will look into it's VE's sys.path
and if not found it will search through the OS path, found it from the root environment and so there were no errors shown.
Upvotes: 1