简体   繁体   中英

Import error with Django Project

My Django project directory structure looks something like this:

/sparestub
//registration
//messages
//tickets
//requests
//venv

There are a bunch of other folders, but you get the idea. One of the modules installed in my virtual environment is requests. Notice that my app has a module named requests as well. The requests module is used by another module installed in my virtual environment called djrill. Whenever I try to start my server, I get the following error:

  File "/Users/me/Documents/coding/sparestub/venv/lib/python3.4/site-packages/djrill/__init__.py", line 5, in <module>
from djrill.exceptions import MandrillAPIError, NotSupportedByMandrillError
  File "/Users/me/Documents/coding/sparestub/venv/lib/python3.4/site-packages/djrill/exceptions.py", line 1, in <module>
from requests import HTTPError
ImportError: cannot import name 'HTTPError'

What I suspect is happening that the djrill is trying to import my requests module instead of the requests module in my virtual environemnt and is failing because it doesn't have an HTTPError class.

My immediate guess was that my django website made it's way into PYTHONPATH. Looking at sys.path, I don't see anything incriminating. My app is called sparestub.

Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path
['', '/Users/me/Documents/coding/sparestub/venv/lib/python34.zip',
'/Users/me/Documents/coding/sparestub/venv/lib/python3.4',
'/Users/me/Documents/coding/sparestub/venv/lib/python3.4/plat-darwin',
'/Users/me/Documents/coding/sparestub/venv/lib/python3.4/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4',
'/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/plat-darwin',
'/Users/me/Documents/coding/sparestub/venv/lib/python3.4/site-packages',
'/Users/me/Documents/coding/sparestub/venv/lib/python3.4/site-packages/newrelic-2.40.0.34']

Notice that the second to last line is for site-packages. I would expect the import requests statement to find the requests module here instead of my requests module. If you have any explanations as to why this is happening, I would love the help.

Thank you!

您可以将所有Django应用程序放入apps文件夹,以便将它们称为apps.requests ,而不再与请求库冲突。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM