Max Ferreira
Max Ferreira

Reputation: 468

Python + Django + VirtualEnv + Windows

I had some problem on installing python + virtualenv + django and need help.

System: Windows 7, 64b

What i do? 1) Installed Python 2.7.2 (32bits) 2) Installed SetupTools (32 bits) 3) Installed VirtualEnv

E:\APPZ\Console2>C:\Python27\Scripts\easy_install.exe virtualenv

4) Created virtualenv:

E:\APPZ\Console2>virtualenv E:\CODE\wamp\www\AMBIENTES\env

5) Fine, now I created a ".bat" to use my env and put then in C:\Windows.

C:\Windows\python.bat

cmd.exe /k E:\CODE\wamp\www\AMBIENTES\env\Scripts\activate.bat

So far so good Now I executed the python.bat and installed django:

E:\APPZ\Console2>python

E:\APPZ\Console2>cmd.exe /k E:\CODE\wamp\www\AMBIENTES\env\Scripts\activate.bat
(env) E:\APPZ\Console2>cd E:\CODE\wamp\www\AMBIENTES\Django-1.2.7

(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>python setup.py install
django installed (1.2.7) successfully.

And now, the problem:

(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py --version
Traceback (most recent call last):
  File "E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py", line 2, in <module>
    from django.core import management
ImportError: No module named django.core

(env) E:\CODE\wamp\www\AMBIENTES\Django-1.2.7>

-

Does anyone know what I can do about it?

Upvotes: 18

Views: 11178

Answers (2)

ajukraine
ajukraine

Reputation: 561

I know this question is old and maybe not actual anymore for author. But as far as it appears at Google's top, I would leave the answer that helped me.

Basically the correct answer is posted for the similar question.

Strictly speaking the wrong Python installation is called when you execute django-admin.py --version. in order to check which Python you use in the case, type ftype Python.File in "command line". If it's not the virtualenv's one, then you could reassociate the default Python:

ftype Python.File="E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe" "%1" %*

Or unset the file association (from cmd.exe):

assoc .py=
ftype Python.File=

After you reassociate the .py extension program, you should specify full path to execute Python files:

E:\CODE\wamp\www\AMBIENTES\env\Scripts\python.exe E:\CODE\wamp\www\AMBIENTES\env\Scripts\django-admin.py --version

Or if you want, you could edit virtualenv's activate.bat to put specific .py association, using assoc and ftype command line utils, mentioned above.

Upvotes: 15

Chris Pratt
Chris Pratt

Reputation: 239280

I believe your problem is that using python setup.py install with the Django source is installing Django in your primary site-packages/dist-packages path instead of that of your virtual environment.

Instead, use pip or easy_install:

$ pip install Django==1.2.7  --OR -- $ easy_install Django==1.2.7

If you can't directly download from PyPi (corporate firewall, etc.) you can use the source you already have by modifying the command slightly:

$ pip install -f file:///E/CODE/wamp/www/AMBIENTES/ Django==1.2.7

(Converted Windows path may need some tweaking. I think that's right, but it's been awhile)

Upvotes: 0

Related Questions