Pycharm导入错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Pycharm导入错误相关的知识,希望对你有一定的参考价值。

家伙。我正在尝试使用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 ProductServicefrom method import ProductServicePO,send_email, SaveImg, create_excel_file中查看views.py(尝试编写完整路径而不是仅键入.productService)和ProductService.py导入行。

另一答案

为当前项目设置项目解释器。您可能设置了常见项目

以上是关于Pycharm导入错误的主要内容,如果未能解决你的问题,请参考以下文章

pycharm添加Odoo代码片段

PyCharm中第三方库导入错误解决

pycharm导入同一个包下的py文件错误

PyCharm 中未使用的错误导入语句?

带有pycharm导入错误的kivy

错误记录PyCharm 运行 Python 程序报错 ( PEP 8: E402 module level import not at top of file )