安装virtualenv后,我不能再运行 ipython / jupyter

After installing virtualenv, I can no longer run ipython / jupyter

我已经愉快地在 Windows 7 中使用 ipython 好几个月了,但最近决定使用 django。我正在查看的指南建议安装 virtualenv,我这样做了并且效果很好(或者看起来)。

但是,现在,当我尝试启动 ipython(或 jupyter)时,出现以下错误:

C:\Python\Scripts>jupyter notebook
Traceback (most recent call last):
  File "c:\python\lib\runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "c:\python\lib\runpy.py", line 72, in _run_code
    exec code in run_globals
  File "C:\Python\Scripts\jupyter-notebook.exe\__main__.py", line 5, in <module>
  File "c:\python\lib\site-packages\notebook\notebookapp.py", line 60, in <module>
    from .services.contents.manager import ContentsManager
  File "c:\python\lib\site-packages\notebook\services\contents\manager.py", line 16, in <module>
    from nbformat import sign, validate, ValidationError
  File "c:\python\lib\site-packages\nbformat\sign.py", line 33, in <module>
    algorithms = hashlib.algorithms
AttributeError: 'module' object has no attribute 'algorithms'

我尝试卸载并重新安装 jupyter、hashlib,甚至 python 本身,但都没有成功。我正在使用 pip 进行安装,我也安装了设置工具。我正在考虑重新格式化我的硬盘并重新开始,但这似乎有点极端。任何帮助,将不胜感激。谢谢

在评论中解决你的最后一个问题,他们在他们的文档中有一个很好的部分关于使用 virtualenv 内核作为 jupyter notebook 的后端。

http://help.pythonanywhere.com/pages/IPythonNotebookVirtualenvs

从文档中复制以防 link 失效:

您可以为 IPython 笔记本使用 virtualenv。按照以下步骤操作:

将 ipython 内核模块安装到您的 virtualenv

workon my-virtualenv-name  # activate your virtualenv, if you haven't already
pip install ipykernel

现在运行内核"self-install"脚本:

python -m ipykernel install --user --name=my-virtualenv-name

根据需要替换 --name 参数。

您现在应该能够在 IPython 笔记本菜单中看到您的内核:内核 -> 更改内核并能够切换到它(您可能需要刷新页面才能出现在列表中). IPython 将记住从那时起该笔记本使用哪个内核。