问题
I'm trying to use pytz in my web app to apply a timezone to a datetime object. First I tried importing pytz like this
from pytz import timezone
Then it raised an ImportError saying that the module "pytz" didn't exist. I tried the same line of code in IDLE and it worked fine. Then I saw something online about gae-pytz. So I changed my code to look like this:
from pytz.gae import pytz
from pytz import timezone
Just like the webpage said. It still has the ImportError. It says:
ImportError: No module named pytz.gae
I think the problem may be that I'm using the gae version for python 2.5. Anybody know what's wrong? Or maybe somebody knows an alternative to pytz.
回答1:
I use gae-pytz and it works great. Looks like you might have a path problem. Is the pytz dir in the root of your app engine project? That is where it should be.
回答2:
Neither pytz or pytz.gae are included with the default App Engine SDK.
If you want to use the pytz.gae module, you will need to download it and copy it to your application folder.
Your import line below assumes that you have the gae.py file in a 'pytz' folder under the root folder of your appengine application source.
You can download the pytz.gae module from here: https://code.google.com/p/gae-pytz/
I use it with a Python 2.7 GAE app and it works fine.
来源:https://stackoverflow.com/questions/10843148/importerror-using-pytz-in-google-app-engine