简体   繁体   English

具有不同环境的 iPython(使用 anaconda)

[英]iPython with different env (using anaconda)

I have just created a new env with python 3.5 using anaconda (called it python35).我刚刚使用 anaconda(称为 python35)使用 python 3.5 创建了一个新环境。 My root env points to python 2.7.11.我的根环境指向 python 2.7.11。 I cant seem to launch ipython with this new env, here is what I did我似乎无法使用这个新环境启动 ipython,这就是我所做的

1. in conda prompt, activate required env: activate python35
2. confirm the version: python --version
3. launch ipython: ipython notebook
4. open a notebook and do: import sys; print (sys.version)

Step #2, returns 3.5 but step #4 always gives me 2.7.11, its like ipython is picking up python version from root env.第 2 步,返回 3.5,但第 4 步总是给我 2.7.11,就像 ipython 从根环境中获取 python 版本一样。 How do I fix this.我该如何解决这个问题。 Thanks for any help!感谢您的帮助!

This question is related but I have already done what it suggests. 这个问题是相关的,但我已经按照它的建议做了。

AFAIK, different environments in anaconda (and in venv as well) are activated by prepending env path to $PATH environment variable. AFAIK,anaconda 中的不同环境(以及 venv 中)是通过将env 路径添加$PATH环境变量来激活的。 It means, that if some file (eg, ipython ) is not found in env path (the first entry of $PATH ), the system searches for it in consequent entries of $PATH and finds it in root environment (that stays in $PATH ).这意味着,如果在 env 路径( $PATH的第一个条目)中找不到某个文件(例如ipython ),系统会在$PATH后续条目中搜索它并在根环境中找到它(留在$PATH )。 To fix the behavior, you need to install its own copy of ipython to anaconda env:要修复该行为,您需要将自己的ipython副本安装到 anaconda env:

  1. In command prompt, activate the environment: source activate python35 (or simply activate python35 , depending on the OS)在命令提示符下,激活环境: source activate python35 (或简单地activate python35 ,具体取决于操作系统)
  2. While in environment, issue the command conda install ipython-notebook在环境中,发出命令conda install ipython-notebook

I could confirm the solution above (basically install notebook in active environment) in my case.在我的情况下,我可以确认上述解决方案(基本上在活动环境中安装笔记本)。 Two updates from my side:我这边的两个更新:

  1. Since Anaconda 4.4 (?) ipython notebook is now jupyter notebook .由于 Anaconda 4.4 (?) ipython notebook 现在是jupyter notebook So I had to install jupyter instead.所以我不得不安装 jupyter。 I guess, deactivate and activate was required afterwards to get the path variables in notebook updated -> checked by python -c "import sys; print(sys.path)" or corresponding command in notebook.我想,之后需要停用和激活才能更新笔记本中的路径变量-> 通过 python -c "import sys; print(sys.path)" 或笔记本中的相应命令进行检查。

  2. If you aren't using a isolated anaconda environment , you may eventual calling the notebook package from your native OS-Python installation, instead the desired from Anaconda.如果您没有使用隔离的anaconda 环境,您最终可能会从您的本机 OS-Python 安装中调用 notebook 包,而不是从 Anaconda 中调用所需的包。 Similarly, I had trouble with cmake or cxx, when I try to compile in Anaconda Environment - the diffent root folder might found in linux bash with eg "which jupyter"同样,当我尝试在 Anaconda 环境中编译时,我在使用 cmake 或 cxx 时遇到了问题 - 可能会在 linux bash 中找到不同的根文件夹,例如“which jupyter”

一个除了安德烈·索伯列夫解决方案,您应该切换到conda install ipython更高python3.x版本和注销环境Ctrl+Dconda deactivate然后重新激活

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM