【问题标题】:python django - ImportError: No module named libpython django - ImportError:没有名为lib的模块
【发布时间】:2018-01-16 00:06:38
【问题描述】:

我是这个领域的新手。我使用 django 框架使用谷歌应用引擎开发 Web 应用程序。我有一个关于 python lib dir 问题的问题... ImportError: no module named...

ROOT
├── lib
│   ├── django
│   ├── pytz
│   ├── wanttousing_lib
│   └── ...
├── mysite
│   ├── __init__.py
│   ├── settings.py
│   ├── controllers.py
│   ├── models.py
│   ├── views.py
│   ├── templates
│   │   └── like
│   │        ├── index.html
│   │        └── _likehelpers.html
│   └── ....
├── test
│   ├── like
│   │   ├── models_tests.py
│   │   └── controllers_tests.py
│   └── ....
├── static
│   ├── css
│   └── js
├── app.yaml
├── manage.py
├── appengine_config.py
└── requirements.txt

在此目录中,运行服务器失败.. 在我的测试代码 controllers_tests.py

`from wanttousing_lib import example_module`

importError wanttousing_lib.......

但如果我将我的 wanttousing_lib 移动到 ROOT 目录,它可以工作.....

ROOT
├── lib
│   ├── django
│   ├── pytz
│   
│   └── ...
├── mysite
│   ├── __init__.py
│   ├── settings.py
│   ├── controllers.py
│   ├── models.py
│   ├── views.py
│   ├── templates
│   │   └── like
│   │        ├── index.html
│   │        └── _likehelpers.html
│   └── ....
├── test
│   ├── like
│   │   ├── models_tests.py
│   │   └── controllers_tests.py
│   └── ....
├── static
│   ├── css
│   └── js
├── app.yaml
├── manage.py
├── appengine_config.py
├── requirements.txt
└── wanttousing_lib  <--- moved

我该如何解决?请帮忙...

【问题讨论】:

  • 您的wanttousing_lib 是否包含__init__.py
  • 是的。 wanttolib 是使用 pip 安装的 twilio。它包含 init.py.

标签: django python-2.7 google-app-engine


【解决方案1】:

确保您在相应的文件夹中有__init__.py..

试试这个,from lib.wanttousing_lib import example_module

因为您的wanttousing_lib 位于lib 文件夹中。如果您移出lib.,则不需要。

【讨论】:

  • wanttolib 是 twilio。
  • 在 appengine_config.py 中,add.vendor('lib')
  • 你在谈论 django 中的文件夹结构。如果不是你想要什么?
猜你喜欢
  • 2013-05-04
  • 2017-07-01
  • 2012-10-21
  • 2013-07-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-28
  • 2020-09-07
相关资源
最近更新 更多