0

First, I've read all the threads I could find that have similar titles. This is bound to be a repost, but I've looked and didn't find it.

Second, here's my setup and what I've done. I'm on Windows 7. I'm following the getting started guide for Heroku at: https://devcenter.heroku.com/articles/django. I used the guide they provided for installing Python, virtualenv, distribute, and pip (http://docs.python-guide.org/en/latest/starting/install/win/). I installed Python 2.7, with no other version present using the Windows installer. I then followed the steps laid out in the guide on Heroku exactly as they are. I had to use the alternate method for installing psycopg2, but it seemed to work fine.

The problem came up then I got to the step where I am supposed to run

django-admin.py startproject hellodjango .

I get this error when I try to run the command:

(venv) C:\Users\myname\projectdir>django-admin.py startproject hellodjango .
Traceback (most recent call last):
  File "C:\Users\myname\projectdir\venv\Scripts\django-admin.py", line 2, in <module>
    from django.core import management
ImportError: No module named django.core

I have tried manually running Python from within the virtual environment and importing django, django.core, and the line specified in the error text, and all work:

(venv) C:\Users\myname\projectdir>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> from django import core
>>> import django.core
>>> from django.core import management
>>>

I tried using pip to uninstall everything, deleting the virtual environment, deleting the project folder, then starting over. The same errors happened.

It's probably something simple, but I can't figure out what I'm missing. Any ideas?

edit - Also, I tried changing the command to :

django-admin.py startproject projectdir .

but this had the same result.

Then I tried:

python C:\Users\myname\projectdir\venv\Lib\site-packages\django\bindjango-admin.py startproject projectdir .

But I got:

python: can't open file 'C:\Users\wtodom\hdj\venv\Lib\site-packages\django\bindj
ango-admin.py': [Errno 2] No such file or directory
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Weston Odom
  • 311
  • 1
  • 6
  • 17
  • 1
    It seems like Django is not on your sys.path. Also, the last thing you tried has a typo - it should be `bin\django-admin.py` not `bindjango-admin.py`. – Dan Hoerst Jan 31 '13 at 03:00
  • @DanHoerst Yep, fixing that typo got it to work, and you're probably right about Django not being in the path. Do I add it the normal way I'd add something to my path, or is there something special i need to do since I'm using virtualenv? – Weston Odom Jan 31 '13 at 03:10
  • @DanHoerst Also, given that path above, what exactly do I need to add? I'm sorry for being so needy, but I really appreciate your help. – Weston Odom Jan 31 '13 at 03:11
  • 1
    Check out this answer for how to add things to the `PYTHONPATH` on Windows: http://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7. Since you are able to `import django` from the shell, it seems that you at least have django in your app folder `C:\Users\myname\projectdir` otherwise you would get an error. If you open a shell from a different folder in the venv, can you import django? – Dan Hoerst Jan 31 '13 at 03:24
  • @DanHoerst Adding to the `PYTHONPATH` looks like it will work but I haven't done it yet. As far as imports go, I can import from other folders within the venv. (I tried it from the project root, then i tried it from a subfolder that wasn't a part of Django's path.) – Weston Odom Jan 31 '13 at 03:41

1 Answers1

0

(Answered in a question edit and comments. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

I had typed the path wrong (left out a single \), but now it works. How can I avoid having to type the entire filepath to the django-admin.py file every time?

@DanHoerst wrote:

Check out this answer for how to add things to the PYTHONPATH on Windows: How to add to the pythonpath in windows 7?. Since you are able to import django from the shell, it seems that you at least have django in your app folder C:\Users\myname\projectdir otherwise you would get an error. If you open a shell from a different folder in the venv, can you import django?

The OP wrote:

Adding to the PYTHONPATH looks like it will work but I haven't done it yet. As far as imports go, I can import from other folders within the venv. (I tried it from the project root, then I tried it from a subfolder that wasn't a part of Django's path.)

Community
  • 1
  • 1
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129