[英]Import package error even though it is properly installed
I have installed EventBrite API for my django application.我已经为我的 django 应用程序安装了EventBrite API 。 The main purpose here is to add
event
details from the site into my database.这里的主要目的是将站点中的
event
详细信息添加到我的数据库中。
Since this script will run periodically I have added this into management/commands folder.由于此脚本将定期运行,因此我已将其添加到 management/commands 文件夹中。 See the below pic, file name is
eventbrite
见下图,文件名是
eventbrite
Problem is when I execute my script using python manage.py eventbrite
, it is showing ImportError: cannot import name Eventbrite
but I have already installed this package inside my virtual environment
.问题是当我使用
python manage.py eventbrite
执行我的脚本时,它显示ImportError: cannot import name Eventbrite
但我已经在我的virtual environment
安装了这个包。
pip freeze
Django==1.9.2
eventbrite==3.3.3
requests==2.9.1
wheel==0.24.0
When I execute the same package in Django Shell
, it is not showing any error当我在
Django Shell
执行相同的包时,它没有显示任何错误
python manage.py shell
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from eventbrite import Eventbrite
>>>
Could anyone tell me why it is showing an import error
when I run the script using python manage.py eventbrite
?谁能告诉我为什么当我使用
python manage.py eventbrite
运行脚本时显示import error
?
It looks like you might have a naming conflict between the eventbrite
package loaded from pip, and the eventbrite
module in your management command.看起来您可能在从 pip 加载的
eventbrite
包和管理命令中的eventbrite
模块之间存在命名冲突。 How are you importing EventBrite
from within your script?您如何从脚本中导入
EventBrite
? If you're doing from eventbrite import Eventbrite
, then it will try to load it from your own module when using the project interpreter and not find the class.如果您正在执行
from eventbrite import Eventbrite
,那么它会在使用项目解释器时尝试从您自己的模块加载它并且找不到类。 Easy solution would be to name your command something other than eventbrite
.简单的解决方案是将您的命令命名为
eventbrite
以外的其他名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.