Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

virtualenv setup

77 views
Skip to first unread message

Phil

unread,
Dec 29, 2012, 5:01:24 PM12/29/12
to django...@googlegroups.com
Hi,

I have python/django working system wide. But am currently looking into using Heroku for a new project so am trying to get virtualenv setup for the first time. When I run "django-admin.py startproject whatever" it creates the project ok, but then when I run "python manage.py runserver 8080" from the project folder I get the following error...

ImportError: No module named django.core.management

Is it because at the top of my "manage.py" it is pointing to my system wide python(#!/usr/bin/env python) instead of my virtualenv one? If so how do I fix this? I tried changing the path at the top of the manage.py file but didn't seem to do anything.

Victor Manuel Quiñones Victor

unread,
Dec 29, 2012, 5:16:45 PM12/29/12
to django...@googlegroups.com
Hi Phil

sorry for the question, but, did you activate your virtualenv source?
$ source bin/activate (?)

Anyway, I'd try to install django via pip once you I have my virtualenv created and activated.

Cheers

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/n4-fu8ioveIJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Quiñones Victor Manuel
Tel: +54 0362 15 4 880839
Resistencia - 3500
Argentina

Phil

unread,
Dec 29, 2012, 5:23:53 PM12/29/12
to django...@googlegroups.com
Hi,

Thanks for reply. Yeah I activated the source(terminal has "venv" beside my username). I followed instructions here(so I pip installed django etc after getting virtualenv up and running)...


If I runserver thats when I get the error. If I runserver without activating source it works fine but that would be using my system wide python. Just need to figure out how to get it to recognise the virtualenv python.

Sam Lai

unread,
Dec 29, 2012, 11:57:31 PM12/29/12
to django-users
It looks like you haven't installed Django in your virtualenv. In your virtualenv directory, look in lib/python2.x/site-packages and see if there is a Django directory in there.

You can also try sourcing your venv, then running Python, and entering in the following statement to see if Python can find Django -

import django

If it can't, try the following statements in the Python shell and see if your venv's site-packages directory is in the system path -

import sys
sys.path

Finally, try the following command in your usual shell and make sure it is referring to the right Python executable (it should be referring to the one in your venv/bin directory) -

which python


To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/Gb4JYmpcK-0J.

Vibhu Rishi

unread,
Jan 4, 2013, 11:58:23 PM1/4/13
to django...@googlegroups.com
Hi Phil,

What OS are you running on ? for ubuntu, you need to have an extra parameter while creating the venv like : 
$ virtualenv venv --distribute --no-site-packages

After that source the environment and pip install the packages 
pip install Django psycopg2 dj-database-url

I would suggest you try the setup first on a blank directory. 

Another thing you may want to check is where the manage.py file is . e.g. I copied over the project that I was working on in a directory called 'website'. the manage.py is inside this directory instead of the root directory (from where your do source). So, in this case I run the server as : 
$ python website/manage.py runserver

Vibhu
Simplicity is the ultimate sophistication. - Leonardo da Vinci
Life is really simple, but we insist on making it complicated. - Confucius

Tom Evans

unread,
Jan 9, 2013, 6:51:17 AM1/9/13
to django...@googlegroups.com
On Sat, Dec 29, 2012 at 10:01 PM, Phil <phi...@gmail.com> wrote:
> Is it because at the top of my "manage.py" it is pointing to my system wide
> python(#!/usr/bin/env python) instead of my virtualenv one? If so how do I
> fix this? I tried changing the path at the top of the manage.py file but
> didn't seem to do anything.

Just to answer this particular point, the way virtualenv works is by
specifying a different lib location for python libraries.

It does that by using a different python interpreter (the one in
<environ>/bin/python) - python looks relative to the binary location
for it's library files.

And it chooses a different python interpreter by putting the directory
that python interpreter is loaded from first in your $PATH environment
variable, so that it is chosen instead of your system python package
by your shell. This happens when you activate your virtualenv.

So, by activating your virtualenv, and running "python manage.py", you
are using the shell's PATH resolution to choose which 'python' binary
will be run, and it will be the one in your virtualenv.

However, even if you had run './manage.py', then the shell would look
at the shebang line, the shebang in this case points at "/usr/bin/env
python". What the env command does is to walk your $PATH environment
variable, looking for the supplied argument as a program - just like a
shell when you run a command - and so that too would have used your
virtualenv.

If you have the virtualenv activated, you can run "pip freeze" to list
all the packages that pip thinks are installed in the virtualenv. This
should give you some more information about whether django is
installed or not. You could also try uninstalling and reinstalling it,
which may fix issues if the original installation was damaged or
interrupted for some reason.

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages