Python django can';t导入已安装的应用程序,并且可以';t输入函数

Python django can';t导入已安装的应用程序,并且可以';t输入函数,python,django,Python,Django,在Django,我有一个“fbsurvey”项目,带有一个“canvas”应用程序 我有另一个“cblib”项目,有一个“调查”应用程序和一个“图表”应用程序 在“调查”应用程序中,有模型和一些功能。 在“graphs”应用程序中,只有一个包含2.py文件的“utils”文件夹——一个包含函数“get\u chart\u info”的文件“get\u chart\u info”,以及一个包含一些组合函数的文件“chart\u utils” graphs应用程序在每个级别上都有一个init.py

在Django,我有一个“fbsurvey”项目,带有一个“canvas”应用程序

我有另一个“cblib”项目,有一个“调查”应用程序和一个“图表”应用程序

在“调查”应用程序中,有模型和一些功能。 在“graphs”应用程序中,只有一个包含2.py文件的“utils”文件夹——一个包含函数“get\u chart\u info”的文件“get\u chart\u info”,以及一个包含一些组合函数的文件“chart\u utils”

graphs应用程序在每个级别上都有一个init.py “调查”工作中的所有模型

但是“获取图表信息”(文件)拒绝导入

如果我试图将“cblib.graphs”放在我安装的应用程序中,当我尝试运行服务器时,它会中断,并说“错误:没有名为graphs的模块”

如果我将其从已安装的应用程序中删除,我会得到: 导入/画布/图表/ 没有名为graphs.utils.get\u chart\u info的模块 (顺便说一句,我不明白为什么这里说没有名为graphs.utils的模块而不是cblib.graphs.utils的模块)

带有对import语句的行引用

请注意,所有导入都在shell中工作。即当我跑步时: /manage.py shell 导入cblib 导入cblib.survey 导入cblib.graphs 导入cblib.graphs.get_chart_info 从cblib.graphs.get_chart_info导入get_chart_info

没有失败的

有人知道为什么会这样吗?我觉得我已经检查过了

有人提到,查看我的项目的ascii树可能很有用(为相关性而编辑)

cblib看起来像:

.
├── graphs
│   ├── admin.py
│   ├── __init__.py
│   ├── __init__.pyc
│   └── utils
│       ├── get_chart_info.py
│       ├── get_chart_info.pyc
│       ├── graph_utils.py
│       ├── graph_utils.pyc
│       ├── __init__.py
│       └── __init__.pyc
├── __init__.py
├── __init__.pyc
└── survey
    ├── admin.py
    ├── fixtures
    │   ├── badges.json
    │   ├── q1-174.json
    │   ├── q175-271.json
    │   ├── q272-302.json
    │   └── responseoptions_767-1594.json
    ├── __init__.py
    ├── __init__.pyc
    ├── management
    │   ├── commands
    │   │   ├── create_fake_users.py
    │   │   ├── import_fake_user_data.py
    │   │   ├── import_questions.py
    │   │   └── __init__.py
    │   └── __init__.py
    ├── migrations
    │   ├── 0001_initial.py
    │   ├── 0002_auto__del_field_votelog_direction.py
    │   ├── 0003_auto__chg_field_pointlog_action_type.py
    │   ├── 0004_auto__add_opengraphverb__add_field_question_school_specific_opengraph_.py
    │   └── __init__.py
    └── models
        ├── badge.py
        ├── badge.pyc
        ├── __init__.py
        ├── __init__.pyc
        ├── opengraphverb.py
        ├── opengraphverb.pyc
        ├── pointlog.py
        ├── pointlog.pyc
        ├── question.py
        ├── question.pyc
        ├── responseoption.py
        ├── responseoption.pyc
调查结果如下:

.
├── canvas
│   ├── admin.py
│   ├── admin.pyc
│   ├── brainys.json
│   ├── data.csv
│   ├── decorators.py
│   ├── decorators.pyc
│   ├── DefaultInfoObject.py
│   ├── DefaultInfoObject.pyc
│   ├── DefaultJsonResponse.py
│   ├── DefaultJsonResponse.pyc
│   ├── fixtures
│   │   └── test-fixture.json
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── level.py
│   ├── level.pyc
│   ├── management
│   │   ├── commands
│   │   │   ├── convert_fbuser_to_cbuser.pyc
│   │   │   ├── credit_inviters.py
│   │   │   ├── __init__.py
│   │   │   ├── __init__.pyc
│   │   │   ├── reminder_wallposts.py
│   │   │   ├── reminder_wallposts.pyc
│   │   │   └── update_user_colleges.py
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── migrations
│   │   ├── 0001_initial.py
│   │   ├── 0001_initial.pyc
│   │   ├── __init__.py
│   │   └── __init__.pyc
│   ├── models.py
│   ├── models.pyc
│   ├── static
│   │   ├── css
│   │   ├── img
│   │   └── js
│   ├── templates
│   │   ├── answers.html
│   │   ├── answers-mobile.html
│   │   ├── answertest.html
│   │   ├── badge-explanation.html
│   │   ├── badges.html
│   │   ├── baduser.html
│   │   ├── bottombar.html
│   │   ├── bottombar-mobile.html
│   │   ├── browse-stories.html
│   │   ├── end.html
│   │   ├── friends.html
│   ├── tests.py
│   ├── tests.pyc
│   ├── urls.py
│   ├── urls.pyc
│   ├── views
│   │   ├── answers.py
│   │   ├── answers.pyc
│   │   ├── badge_explanation.py
│   │   ├── badge_explanation.pyc
│   │   ├── badges.py
│   │   ├── badges.pyc
│   │   ├── browse_stories.py
│   │   ├── browse_stories.pyc
│   │   ├── explanation.pyc
│   │   ├── format_for_graph.py
│   └── views.pyc
├── __init__.py
├── __init__.pyc
├── local_settings.py
├── local_settings.pyc
├── local_settings.py.example
├── logclient
│   └── __init__.py
├── manage.py
├── maps.py
├── maps.pyc
├── patch.py
├── pokesite
├── python.exe.stackdump
├── README
├── requirements.txt
├── settings.py
├── settings.pyc
├── survey
│   ├── admin.pyc
│   ├── data
│   │   ├── CBI Questions with percentages v3.csv
│   │   ├── data.csv
│   │   ├── List of School Nicknames.txt
│   │   ├── pquestions.csv
│   │   ├── question_pks_and_categories.csv
│   │   ├── questions.csv
│   │   └── questions.json
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── localsetting.py
│   ├── models.pyc
│   ├── tests.py
│   └── views.py
├── surveydump.json
├── sync_badges.py
├── templates
│   ├── 404.html
│   ├── 500.html
│   ├── base.html
│   └── base-mobile.html
├── testdump.json
├── tree.txt
├── urls.py
└── urls.pyc

答案与我的.pyc文件有关。。。我不知道怎么做或者为什么,但是跑步

找到-名称“*.pyc”-删除

(这可能会重新生成我的pyc文件)
在我的两个项目目录中修复了该问题。

您的settings.py是什么样子的?你添加了所有内容吗?我的fbsurvey settings.py与添加graphs应用程序之前没有任何变化(所有内容都正常工作)。Cblib没有设置,因为它是一个库。我想你可能需要在设置中注册应用。否则,您的项目如何知道从何处开始?您可能想了解项目的总体架构。也许这会有帮助:正如我所说,“如果我试图在我安装的应用程序中放入”cblib.graphs“,当我尝试运行服务器时,它会中断,并说“错误:没有模块命名的图形”,所以当你说您放入”cblib.graphs““,cblib是它自己的项目,但您希望通过fbsurvey访问应用程序,对吗?您必须将应用程序从cblib复制到fbsurvey,并在fbsurvey的settings.py中注册该应用程序,或者使用上述链接中提到的PYTHONPATH hack在settings中注册该应用程序。您可以在shell中随时检查类似的内容(“项目中的python manage.py shell”)此命令只删除错误位置的旧的未使用的.pyc文件,不会生成新文件,但在运行应用程序时会生成新文件。