Spyder 中的 virtualenv IPython 不工作

virtualenv IPython in Spyder not working

我已经在 Linux(确切地说是 Mint 17)上安装了 Spyder,并使用 ipython、numpy 等创建了一个科学的 virtualenv (sci)。我的想法是改变我的虚拟环境python 2 / python 3 并且比安装整个 Anaconda / python(x,y) 更灵活。我现在无法 ipython 在 Spyder 中工作。

我去了

Tools->Preferences->Console->Advanced settings

使用下面的Python解释器

 /home/mike/envs/sci/bin/ipython

但这并没有开始ipython。它响应

...
Execute the given command[TerminalIPythonApp] CRITICAL | Bad config     encountered during initialization:
[TerminalIPythonApp] CRITICAL | Unrecognized flag: '-u'
...

它也不会在控制台下显示 "Open an IPython console"。

知道我遗漏了什么吗?

干杯,迈克

在您的 virtualenv 中正确输入 Python 解释器的路径后(即 /home/mike/envs/sci/bin/python,而不是 /home/mike/envs/sci/bin/ipython),您只需要转到菜单

Consoles > Open an IPython console

并且,只要您在 virtualenv 中安装了 IPython 和 PyQt/PySide,就会使用您的 IPython 版本为您打开一个 IPython 控制台虚拟环境。

过程描述如下link:

https://github.com/spyder-ide/spyder/wiki/Working-with-packages-and-environments-in-Spyder

建议使用spyder-kernels安装模块化方式:

  1. 激活您想工作的环境(例如:source env/bin/activate
  2. 通过键入以下命令在环境中安装内核:pip install spyder-kernels==0.*
  3. 通过键入获取要使用的解释器路径:python -c "import sys; print(sys.executable)"
  4. 复制此路径
  5. 在菜单中输入Spyder中的路径

Preferences > Python Interpreter > Use the following interpreter

应该可以,编码愉快!

以上解决方案对我不起作用。对我有用的是遵循文档中的本指南: https://docs.spyder-ide.org/ipythonconsole.html#connect-to-an-external-kernel

1) 打开终端并激活你的 virtualenv 2) 仍然在终端中,运行 命令:python -m spyder_kernels.console,您将收到如下消息:

To connect another client to this kernel, use:
--existing kernel-28340.json

3) 找到这个 json 文件位置,运行 这个在 spyder:

from jupyter_core import paths
paths.jupyter_runtime_dir()

对我来说是 c:\Users[myuser]\AppData\Roaming\jupyter\runtime\

4) 在 jupyter 中,从菜单中单击 "Consoles => Connect to an existing kernel"