ModuleNotFoundError pycharm

时间:2018-05-17 23:38:29

标签: django pycharm interpreter

每当我尝试导入我之前安装的任何软件包时,都会出现以下错误。我无法弄清楚我做错了什么。

C:\Users\David\Documents\Django_directory\usws15\eRoutes>python manage.py runserver 8002
Performing system checks...

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x000001FF0416A6A8>
Traceback (most recent call last):
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\autoreload.py", line 225, in wrapper
    fn(*args, **kwargs)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\runserver.py", line 120, in inner_run
    self.check(display_num_errors=True)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 364, in check
    include_deployment_checks=include_deployment_checks,
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 351, in _run_checks
    return checks.run_checks(**kwargs)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\registry.py", line 73, in run_checks
    new_errors = check(app_configs=app_configs)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 13, in check_url_config
    return check_resolver(resolver)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\checks\urls.py", line 23, in check_resolver
    return check_method()
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 397, in check
    for pattern in self.url_patterns:
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 536, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\utils\functional.py", line 36, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\site-packages\django\urls\resolvers.py", line 529, in urlconf_module
    return import_module(self.urlconf_name)
  File "C:\Users\David\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
......
"C:\Users\David\Documents\Django_directory\usws15\eRoutes\routing\urls.py", line 2, in <module>
    from . import views
  File "C:\Users\David\Documents\Django_directory\usws15\eRoutes\routing\views.py", line 2, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'

Project interpreter

1 个答案:

答案 0 :(得分:1)

确保您的virtualenv已激活。

您可以通过查看堆栈跟踪中的路径来判断您是否已将其激活。所有的django都应该来自你的virtualenv目录。

在运行任何django命令之前,您需要运行venv\Scripts\activate.bat。它激活你的虚拟python环境。

完成此操作后,您应该会发现您的runserver命令开始工作。

看到你正在使用pycharm - 使用其中的终端(而不是假定的cmd会话)应该自动为你激活它。