问题
I'm working on a Django-nonrel project using Django-rest-framework and I've run into the following error after following the instructions in the Token Authorization section of their Authorization API Guide:
ImportError: No module named rest_framework.authtoken
Normally I would just assume that this is something to do with my PYTHONPATH but I don't think that's exactly what the problem is because I can import this framework from both IDLE and the project's shell run using manage.py, the latter both with and without a virtual environment. Within the virtual environment I have installed django and djangorestframework, which should be the only requiremnets for the project thus far.
I had thought that it might have been a Python versioning problem but given that I can import the package directly from the project's shell (running under the virtual env) I'm kind of at a loss since theoretically running manage.py from the same virtual environment should result in the same context for locating libraries.
I've spent a long time searching around trying to fix this issue but to no avail. Any suggestions? I'm happy to provide any additional information as needed!
回答1:
A few things to check:
- Are you sure you are using the directory one level above rest_framework in your PYTHONPATH?
- Did you restart your shell after installation?
- Take a look at VirtualEnv PYTHONPATH setup. Did you try setting the PYTHONPATH for virtualenv explicitly?
来源:https://stackoverflow.com/questions/16861819/import-error-using-djangorestframework-with-django-nonrel