人。我正在尝试使用xlwt开发一个程序来创建excel文件。 我用过
pip install xlwt
安装它。在终端中,可以导入它而不会出错。 Django项目可以正常运行。
但在pycharm中,它在运行Django项目时显示导入错误。错误代码如下所示:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/checks/urls.py", line 10, in check_url_config
return check_resolver(resolver)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/checks/urls.py", line 19, in check_resolver
for pattern in resolver.url_patterns:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/motion/Documents/GitHub/motion-op/motion/urls.py", line 4, in <module>
from product.views import home
File "/Users/motion/Documents/GitHub/motion-op/product/views.py", line 22, in <module>
from .ProductService import ProductService
File "/Users/motion/Documents/GitHub/motion-op/product/ProductService.py", line 13, in <module>
from method import ProductServicePO,send_email, SaveImg, create_excel_file
File "/Users/motion/Documents/GitHub/motion-op/product/method/create_excel_file.py", line 2, in <module>
import xlwt
ImportError: No module named xlwt
我已经设置了项目解释器。 The project interpreter image shows here.
有谁知道如何解决它,谢谢你们。
答案 0 :(得分:0)
为当前项目设置项目解释器。您可能设置了常见项目
答案 1 :(得分:0)
点击pycharm终端上的np.int16
命令,看看pip list
是否可用。如果不再安装它。你使用python 2.7所以,看看你正在使用的xlwt版本是否与这个python兼容。
编辑:
如果你想用开始按钮运行项目,那么点击开始旁边的下拉按钮进入`编辑配置,然后在那里设置python解释器。
除此之外,您需要分别在xlwt
和from .ProductService import ProductService
中查看from method import ProductServicePO,send_email, SaveImg, create_excel_file
(尝试编写完整路径而不是仅输入.productService)和views.py
导入行。
答案 2 :(得分:0)
只是遇到了同样的问题并加以解决。
在pycharm中配置当前的解释器。 (ctrl + alt + s)
单击右侧的“ +”图标并安装xlwt。
使用pycharm的弹出窗口成功安装并修复导入问题。
答案 3 :(得分:0)
我必须直接通过 Pycharm 的 GUI 进行安装。查看以下内容:
File|Settings|Project:|Python Interpreter| add
然后搜索 xlwt
并安装。