WebFaction
Community site: login faq

Hello,

Warning!!! Noob questions are below! :D

I followed these instructions to upgrade my Django 1.3 to l.4.

When starting a new project I got this error:

[mhulse@xxx mydjango]$ django-admin.py startproject baz
Traceback (most recent call last):
  File "/home/mhulse/webapps/mydjango/bin/django-admin.py", line 2, in <module>
    from django.core import management
ImportError: No module named django.core

When I opened django-admin.py, and changed #!/usr/bin/env python to #!/usr/local/bin/python2.7 and re-ran startproject above, everything worked great.

Just wondering if this is normal procedure? Did I miss a step when upgrading my Django install?

Using #!/usr/bin/env python looks more portable (no python version number)... Is there a way I can get this line to work?

Many thanks in advance, I really appreciate it!!!

asked 23 Mar '12, 22:31

mhulse
411617
accept rate: 0%


It is easier to just use manage.py, they are identical.

permanent link

answered 23 Mar '12, 22:35

johns
5.4k312
accept rate: 23%

edited 23 Mar '12, 22:37

Thanks for the pro help John, I really appreciate it. Great tip on using manage.py; I did not realize that they were the same thing. Let's say I did not have manage.py to use though... I'm trying to start a new project vs. start an app. In this case, I do have manage.py available (my main project is there) but typically, don't you need to run startprojet before you have access to manage.py? On the other hand, I suppose I could find manage.py in the django source code and run it from there. Thanks again for the help! :)

(24 Mar '12, 12:54) mhulse
1

If you don't have manage.py (ie, you haven't created a project), then you can use python2.7 bin/django-admin.py from your app directory instead.

(24 Mar '12, 13:29) seanf

Thanks John and Sean! I owe you guys several delicious Oregon brews! I can't thank ya'll enough for the tips and for being so helpful. :)

Just as a quick update, I added this to my .bashrc:

export PYTHONPATH=$HOME/webapps/mydjango:$HOME/webapps/mydjango/lib:$HOME/webapps/mydjango/lib/python2.7:$HOME/webapps/mydjango/lib/python2.7/django:$PYTHONPATH

From the shell:

$ source /home/mhulse/.bashrc

Next, I moved to "mydjango" WebFaction application folder and ran:

$ django-admin.py startproject billy

That did the trick!

Does this seem like a legit fix? Are there any issues with me adding all of those paths to my PYTHONPATH?

Sorry in advance if these are noob questions. :(

permanent link

answered 24 Mar '12, 13:43

mhulse
411617
accept rate: 0%

1

Glad that's working for you!

We generally don't recommend using PYTHONPATH in your .bashrc or .bash_profile, because if you create a second Django app from the control panel, your Python search path will cause you to pick up libraries from the first app (since you've put that on your PYTHONPATH).

Instead, you should be able to change to your app directory and run your Django commands from there - as long as your current working directory is at or below your app directory, the app's lib/python2.7 directory will always be on your Python search path. For example, this doesn't work:

[user@web330 ~]$ python2.7 -c "import django; print django"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named django

This does work:

[user@web330 ~]$ cd webapps/mydjango/
[user@web330 mydjango]$ python2.7 -c "import django; print django"
<module 'django' from '/home/user/webapps/mydjango/lib/python2.7/django/__init__.pyc'>

Hope that helps!

(24 Mar '12, 14:00) seanf

Ahhh, thank you Sean for the details. I just removed the paths from my PYTHONPATH and reloaded my .bashrc file. Thanks for tip!

Now, I'm back to not being able to run startproject via django-admin.py.

$ django-admin.py startproject zzzz

The above gives me ImportError: No module named django.core.

Just double checking things here:

$ which django-admin.py
~/webapps/mydjango/bin/django-admin.py

(I ran the above whilst in my Webfaction's Django app directory.)

Seems fine to me... Now I am back to square one.

With all that said, based on what you folks have been saying, I did run this command:

$ python bin/django-admin.py startproject zzzzz

... and that worked without error (I have "python" aliased to python2.7)!

I suppose that's not a bad way to run django-admin when I need to (which isn't that often anyway); and, now that I know manage.py can do all the same heavy lifting, I plan on using manage.py whenever possible.

Thanks so much for you time Sean and John, you guys ROCK!!!!!

WebFaction ROCKS!

Cheers, Micky

(24 Mar '12, 14:58) mhulse
1

The ImportError happens because your django-admin.py uses #!/usr/bin/env python when run on its own. env ignores aliases, and the default system Python is Python 2.6, so it doesn't recognize your lib/python2.7 libraries.

If you really want to run django-admin.pyas a standalone script, then you can edit its first line to change it to #!/usr/local/bin/python2.7.

(24 Mar '12, 15:14) seanf

I see now. Thanks Sean!

Also, just FYI (for my own future reference), I had some extra path information in my .bash_profile that was pointing to my Django projects's bin folder. I removed this cruft, and now:

which django-admin.py
/usr/bin/which: no django-admin.py in (/home/mhulse/bin:/home/mhulse/bin:/home/mhulse/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/pgsql-9.1/bin/:/usr/pgsql-9.1/bin/)

... which is a better result because of the reason you state above (i.e having multiple Django apps).

Thank you again Sean and John!!!! Have a great weekend.

(24 Mar '12, 15:22) mhulse

Just as an update, I installed a fresh copy of Django 1.4 (mod_wsgi 3.3/Python 2.7) via the WF control panel.

All of the files in the webapps/mydjangoapp/bin all have #!/usr/local/bin/python2.7 at the top.

Not that this means anything special... I just thought it was good to know, and share with others, that the WF out-of-the-box installation changes the first line of those files.

permanent link

answered 26 Mar '12, 18:25

mhulse
411617
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×909
×19
×15
×1
×1

question asked: 23 Mar '12, 22:31

question was seen: 8,366 times

last updated: 26 Mar '12, 18:25

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM