首页 > 解决方案 > 无法从 virtualenv 和 Django 访问 python shell

问题描述

我在 Windows 10 上。

我尝试安装通道以在 Django 中使用 websockets,但它不起作用。我收到以下错误: Twisted 构建轮子失败

我仍然没有成功安装频道。

但是现在我有一个新问题,我不能再从我用于 Django 的虚拟环境中访问Python shell 。

(myproject) D:\Django\mysite>py manage.py shell
Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\core\management\__init__.py", line 357, in execute
    django.setup()
  File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\apps\registry.py", line 89, in populate
    app_config = AppConfig.create(entry)
  File "C:\Users\kevin\Envs\myproject\lib\site-packages\django\apps\config.py", line 90, in create
    module = import_module(entry)
  File "C:\Users\kevin\Envs\myproject\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'channels'

我不知道如何解决我的问题......有人可以帮我吗?

标签: pythondjangodjango-channels

解决方案


Seems like you broke something when you tried to install channels. From the spares information I guess that easiest course of action is to simply use a new virtual environment. After all that is the point of a virtual environment, if it breaks you can just rebuild it.

Manually fixing the virtual environment usually (this is my personal experience) takes more time then just setting up a new one. For your installation trouble we need more info and you should open a new question.

So just deactivate your current environment (this might help), delete it and set up a new one.

Keep in mind that this will only bring the shell back and give you a "fresh start". Your installation problem will usually not disappear!


推荐阅读