Django settings — could not import unipath

删除回忆录丶 提交于 2019-12-11 16:48:01

问题


I could not figure out what I'm doing wrong. Could you please help me? I have the following directory structure:

project-repository
  \-- my-project
       \--manage.py
       \--my-project
             \--__init__.py
             \--urls.py
             \--wsgi.py
             \--settings
                    \--__init__.py
                    \--local.py
                    \--base.py

In the local.py I import base.py. In base.py I have from unipath import Path. When I try to run django-admin shell --settings=my-project.settings.local it shows me an error:

Error: Could not import settings 'my-project.settings.local' (Is it on sys.path?): No module named unipath

When I do pip freeze it shows me:

Unipath==0.2.1

and I can easily import it in python console. Also I have project-repository and my-project on PYTHONPATH.

Here is unipath.__file__ output:

/home/User/.virtualenvs/django.1.4/local/lib/python2.7/site-packages/unipath/__init__.pyc

And here is one of the lines from sys.path output:

/home/User/.virtualenvs/django.1.4/local/lib/python2.7/site-packages

Could you please point me to what I'm doind wrong?


回答1:


It seems like I figured out the problem. The think was that I did a lot of mess. I had django and other apps installed globaly (long before I started developing the project). Then I installed virtualenvwrapper and created virtualenv. Working in the virtualenv I installed the required dependencies and the django. But when I was trying to run that I ran the globally installed version of django. As a result there were some incompatibilities. After I uninstalled global packages, everithing is ok.

How I figured out it? Thanks a lot to Jeff Knup and his post Starting a Django 1.4 Project the Right Way. I walked through the described steps and when I ran

(my-virtualenv)$ which django-admin.py

it showed me the following path:

/usr/local/bin/django-admin

while it should have:

$HOME/.virtualenvs/

that was a sign that something is wrong.

Thanks a lot for everybody for trying to help me.




回答2:


add file __init__.py to settings directory



来源:https://stackoverflow.com/questions/14659855/django-settings-could-not-import-unipath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!