Forums

How to find django.utils.timezone file? (Unable to find using "Files" tab)

I'm using an unpaid account, which I'm assuming is why I can't seem to find the directory where the file django.utils.timezone would be located.

The reason I need to access it is because I'm following this tutorial (which was recommended by one of the awesome support techs here at PythonAnywhere on my previous forum thread), and once I get to the part where I'm using the IPython shell inside of a bash console and I do

from django.utils import timezone

it returns

ImportError Traceback (most recent call last)

/usr/local/lib/python2.7/dist-packages/django/core/management/commands/shell.py in <module>(

----> 1 from mysite.django.utils import timezone

ImportError: No module named django.utils

So I'm pretty sure that I have the wrong location in my "from" field, but I can't seem to find a file named "timezone" within a directory named "utils."

I can't even find a directory called "django," so I'm pretty lost. If someone could please point me in the right direction or give me a tip on where this particular file is located, I'd be really happy! At least, until I find another obstacle... (I've been finding lots of them so far... -_- I am a little new to Python and Django...) Thanks!

Please bear with my horrible syntax... I'm not used to Markdown and Codehilite... (I am experiencing a large learning curve here...) edit: Yay! I finally made it look acceptable! (though I hate the way you have to to line breaks with Markdown)

Oh, and I am using Python 3.3 and Django 1.6 (though in my error it says "Python2.7" in the traceback... so I'm thinking there is a problem there)

If your traceback says Python 2.7, then you're not using Django 1.6 or Python 3.3, you're using Python 2.7. How are you starting your shell?

I'm going into the bash console and typing this:

cd mysite

python manage.py shell

in order to access the IPython shell.

Python 2.7 is the default when you run python. To use Python 3, you need to do python3.3 manage.py shell

Oh thanks! I've been looking for that and I couldn't find it anywhere so I figured it wasn't possible! You'd think they would have that listed in the Django 1.6 tutorial pages...

You can run Django 1.6 under Python 2.7 or 3.x, I think. So I guess there's not much they can do in the docs.

One thing is that the manage.py script generated by our Django "quickstart" has a hashbang at the start to make it use Python 3, and has execute permissions. So you can let it choose its own Python version by just doing

cd mysite
./manage.py shell

Okay. Thanks for the tip!

In case you (or anyone else who comes across this thread) aren't familiar with hashbangs, it's a single line at the top of a file which specifies what it should be executed with -- it's a unixey way of specifying file associations I guess. the line starts with #! (hash-bang, or sometimes shebang) and then specifies an executable, eg:

#!/usr/bin/python3.3

# rest of code follows, eg
print("Hello, world")

More info on WikiPedia. Note the section on portability. For anyone using a virtualenv, you probably want to use the /usr/bin/env formulation, ie:

#!/usr/bin/env python3.3