家伙。我正在尝试使用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.
有谁知道如何解决它,谢谢你们。
点击pycharm终端上的pip list
命令,查看是否有xlwt
可用。如果不再安装它。你使用python 2.7所以,看看你正在使用的xlwt版本是否与这个python兼容。
编辑:
如果你想用开始按钮运行你的项目,那么通过点击开始旁边的下拉按钮进入`编辑配置,然后在那里设置python解释器。
除此之外,您需要分别在from .ProductService import ProductService
和from method import ProductServicePO,send_email, SaveImg, create_excel_file
中查看views.py
(尝试编写完整路径而不是仅键入.productService)和ProductService.py
导入行。
为当前项目设置项目解释器。您可能设置了常见项目