1
votes

I am basically a beginner level programmer of Python. I had 2.7 installed then decided to upgrade to 3.4, and long story short decided to go back to 2.7. I installed and uninstalled using the windows installer.

I am using windows7 64 bit and installed python 2.7 32 bit (from a bit of research it seems that shouldn't really matter). I then pip installed virtualenv as well as installed virtualenvwrapper.

So I created a test environment using mkvirtualenv test. Then I pip install django (successfully) and when I try to run the django-admin.py startproject command it's giving me the no module named django.core error. From all of the other posts it must be a path issue but none of the solutions have corrected the issue.

Info that may help:

  1. Yes I can run the interpreter and import django with no issue. Django is not installed outside of the virtual environment (I don't think)
  2. My PATH environment variables point to C:\python27; and C:\python27\scripts;
  3. My PYTHONPATH environment variables are C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;
  4. Within the django-admin.py file at the top it says, "#!C:\Users\Jim Wombles\Envs\test\Scripts\python.exe"
  5. Running import sys and print sys.path in python running within the virtual environment gives me: ['', 'C:\Users\Jim Wombles\Envs\test\lib\site-packages\setuptools-0.6c11-py2.7.egg', 'C:\Users\Jim Wombles\Envs\test\lib\site-packages\pip-1.3.1-py2.7.egg', 'C:\Python27\Lib', 'C:\Python27 \DLLs', 'C:\Python27\Lib\lib-tk', 'C:\', 'C:\Windows\system32\python27.zip', 'C:\Users\Jim Wombles\Envs\test\DLLs', 'C:\Users\Jim Wombles\Envs\test\lib', 'C:\Users\Jim Wombles\Envs\te st\lib\plat-win', 'C:\Users\Jim Wombles\Envs\test\lib\lib-tk', 'C:\Users\Jim Wombles\Envs\test\Scripts', 'C:\Users\Jim Wombles\Envs\test', 'C:\Users\Jim Wombles\Envs\test\lib\site-pa ckages']
  6. Assoc .py gives me .py=pythonfile and ftype Python.File gives me Python.file="C:\Python27\python.exe" "%1" %* ....so it would appear that it is pointing to the 2.7 version of python.

Any idea what might be going on?

1
just to be sure: after creating the virtualenv, do you activate it? - yedpodtrzitko
Yes, I'm trying to run the django-admin.py startproject command from within the activated virtual environment. - Jim Wombles

1 Answers

1
votes

I finally found an answer. Apparently when you you use virtualenv (or virtualenvwrapper) to install Django on Windows this import error is raised because Windows does not run the Python interpreter from the virtual environment unless it is invoked directly.

The solution suggested at https://docs.djangoproject.com/en/dev/faq/troubleshooting/ is to prefix all commands that use .py files with python and use the full path to the file. In my case after starting the virtualenv: python C:\Users\Jim Wombles\Envs\test\Scripts\django-admin.py startproject projectname. And it works!