2017-08-01 90 views
1

這裏是我的python manage.py runserver錯誤跟蹤我使用的Django 1.10.7蟒蛇2.7Django的 - 導入錯誤:沒有模塊名爲djangochat.settings

(faavenv) [email protected]:~/Documents/faa-backend$ python manage.py runserver 
Traceback (most recent call last): 
    File "manage.py", line 14, in <module> 
    execute_from_command_line(sys.argv) 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line 
    utility.execute() 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 316, in execute 
    settings.INSTALLED_APPS 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__ 
    self._setup(name) 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup 
    self._wrapped = Settings(settings_module) 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__ 
    mod = importlib.import_module(self.SETTINGS_MODULE) 
    File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module 
    __import__(name) 
ImportError: No module named djangochat.settings 

這裏是我的requirements.txt

amqp==2.2.1 
anyjson==0.3.3 
asn1crypto==0.22.0 
Babel==2.4.0 
backports-abc==0.5 
bcrypt==3.1.3 
BeautifulSoup==3.2.1 
beautifulsoup4==4.6.0 
billiard==3.5.0.3 
bleach==2.0.0 
boto==2.48.0 
boto3==1.4.4 
botocore==1.5.80 
celery==4.1.0 
certifi==2017.4.17 
cffi==1.10.0 
chardet==3.0.4 
cryptography==1.9 
Django==1.10.7 
django-celery-beat==1.0.1 
django-contrib-comments==1.8.0 
django-debug-toolbar==1.8 
django-environ==0.4.3 
django-nocaptcha-recaptcha==0.0.19 
django-storages-redux==1.3.3 
docutils==0.13.1 
enum34==1.1.6 
Fabric==1.13.2 
feedparser==5.2.1 
filebrowser-safe==0.4.7 
flower==0.9.2 
future==0.16.0 
futures==3.1.1 
grappelli-safe==0.4.6 
html5lib==0.999999999 
idna==2.5 
ipaddress==1.0.18 
jmespath==0.9.3 
kombu==4.1.0 
Mezzanine==4.2.3 
nltk==3.2.4 
numpy==1.13.0 
oauthlib==2.0.2 
olefile==0.44 
pandas==0.20.2 
paramiko==2.2.1 
Pillow==4.1.1 
psycopg2==2.7.1 
pyasn1==0.2.3 
pycparser==2.17 
pycryptodomex==3.4.6 
pyjwkest==1.3.6 
PyJWT==1.5.2 
PyNaCl==1.1.2 
python-dateutil==2.6.0 
python-openid==2.2.5 
pytz==2017.2 
requests==2.18.1 
requests-oauthlib==0.8.0 
s3transfer==0.1.10 
scikit-learn==0.18.2 
scipy==0.19.1 
singledispatch==3.4.0.3 
six==1.10.0 
sklearn==0.0 
social-auth-app-django==1.2.0 
social-auth-core==1.4.0 
sqlparse==0.2.3 
tornado==4.5.1 
tzlocal==1.4 
urllib3==1.21.1 
vine==1.1.4 
webencodings==0.5.1 

問題是我沒有在我的環境中安裝Django聊天。不過,它顯示出上述錯誤。不僅這個項目,而且在所有項目中,我都收到了這個錯誤。

我試圖重新安裝所有庫,但沒有幫助。

任何建議,將不勝感激。

(faavenv) [email protected]:~/Documents/faa-backend$ python manage.py shell 
Traceback (most recent call last): 
    File "manage.py", line 14, in <module> 
    execute_from_command_line(sys.argv) 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line 
    utility.execute() 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 316, in execute 
    settings.INSTALLED_APPS 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__ 
    self._setup(name) 
    File "/home/user/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup 
    self._wrapped = Settings(settings_module) 
    File "/home/soham/Documents/faa-backend/faavenv/local/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__ 
    mod = importlib.import_module(self.SETTINGS_MODULE) 
    File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module 
    __import__(name) 
ImportError: No module named djangochat.settings 


(faavenv) [email protected]:~/Documents/faa-backend$ python 
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2 
Type "help", "copyright", "credits" or "license" for more information. 
>>> import djangoChat 
Traceback (most recent call last): 
    File "<stdin>", line 1, in <module> 
ImportError: No module named djangoChat 
>>> 
+0

如果您運行'manage.py shell'並嘗試'import djangoChat',你會得到什麼? – Haranadh

+0

@Haranadh我已經用你建議的命令的輸出更新了我的問題。 –

+0

是你在djangochat目錄下的設置文件嗎?目錄是否存在? –

回答

0

and where your settings.py file location?您可以編輯您manage.py和更換djangochat上有效值

if __name__ == "__main__": 
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "djangochat.settings") 
    #            ^^^^^^^ 
0

這個錯誤通常是因爲你有一個使用Django和Django是不導入的文件。

您的項目中可能有一個腳本導入並具有可執行功能,但不包含if __name__ == "__main__":部分。所以runserver導入這個腳本,嘗試執行並失敗,因爲django沒有被導入。所以,如果你有這樣的事情,確保運行函數在上面的if語句中,所以runserver在導入時不會嘗試運行腳本。因此,如果你想運行一個使用django的腳本(並且它不在模型,視圖,窗體中),你需要首先設置django。你需要找到有問題的文件,並添加頂部以下內容:

import django 
sys.path.append("path/to/django/settingsapp") 
os.environ["DJANGO_SETTINGS_MODULE"] = "djangochat.settings" 
django.setup()  

如果您發現有問題的文件,並添加上面,它可能會解決它。

希望這會有所幫助。

0

謝謝你所有的答案,我只是移動我的項目位置,並重新設置它,它的工作原理。仍然,我不知道是什麼問題,但移動項目目錄和環境後它正在工作。

相關問題