简体   繁体   English

如何在 anaconda spyder 中更改 python 版本

[英]How to change python version in anaconda spyder

I am using 3.6 Python version in anaconda spyder on my mac.我在 Mac 上的 anaconda spyder 中使用 3.6 Python 版本。 But I want to change it to Python 2.7.但我想将其更改为 Python 2.7。

Can any one tell me how to do that?谁能告诉我怎么做?

You can open the preferences (multiple options):您可以打开首选项(多个选项):

  • keyboard shortcut Ctrl + Alt + Shift + P键盘快捷键Ctrl + Alt + Shift + P
  • Tools -> Preferences Tools -> Preferences

And depending on the Spyder version you can change the interpreter in the Python interpreter section (Spyder 3.x):根据 Spyder 版本,您可以在Python interpreter部分 (Spyder 3.x) 中更改解释Python interpreter

在此处输入图片说明

or in the advanced Console section (Spyder 2.x):或在高级Console部分(Spyder 2.x):

在此处输入图片说明

First, you have to run below codes in Anaconda prompt ,首先,您必须在Anaconda prompt运行以下代码,

conda create -n py27 python=2.7  #for version 2.7
activate py27

conda create -n py36 python=3.6  #for version 3.6
activate py36

Then, you have to open Anaconda navigator and,然后,您必须打开Anaconda navigator然后, 在此处输入图片说明 The button might say "install" instead of Launch.该按钮可能会说“安装”而不是“启动”。 After the installation, which takes a few moments, It will be ready to launch.安装后,这需要一些时间,它将准备启动。

Thank you, @cloudscomputes and @Francisco Camargo.谢谢@cloudscomputes 和@Francisco Camargo。

If you want to keep python 3, you can follow these directions to create a python 2.7 environment, called py27.如果你想保留 python 3,你可以按照这些说明创建一个 python 2.7 环境,称为 py27。

Then you just need to activate py27:然后你只需要激活py27:

$ conda activate py27

Then you can install spyder on this environment, eg:然后你可以在这个环境中安装 spyder,例如:

$ conda install spyder

Then you can start spyder from the command line or navigate to 2.7 version of spyder.exe below the envs directory (eg C:\\ProgramData\\Anaconda3\\envs\\py27\\Scripts)然后你可以从命令行启动 spyder 或导航到 envs 目录(例如 C:\\ProgramData\\Anaconda3\\envs\\py27\\Scripts)下的 spyder.exe 2.7 版本

You can launch the correct version of Spyder by launching from Ananconda's Navigator .您可以通过从Ananconda 的 Navigator启动来启动正确版本的 Spyder。 From the dropdown, switch to your desired environment and then press the launch Spyder button.从下拉菜单中,切换到您想要的环境,然后按下启动 Spyder 按钮。 You should be able to check the results right away.您应该能够立即检查结果

In Preferences, select Python Interpreter在首选项中,选择 Python 解释器

Under Python Interpreter, change from "Default" to "Use the following Python interpreter"在 Python 解释器下,从“默认”更改为“使用以下 Python 解释器”

The path there should be the default Python executable.路径应该是默认的 Python 可执行文件。 Find your Python 2.7 executable and use that.找到您的 Python 2.7 可执行文件并使用它。

If you are using anaconda to go into python environment you should have build up different environment for different python version如果你使用 anaconda 进入 python 环境,你应该为不同的 python 版本建立不同的环境

The following scripts may help you build up a new environment(running in anaconda prompt)以下脚本可以帮助您建立一个新环境(在 anaconda 提示符下运行)

conda create -n py27 python=2.7  #for version 2.7
activate py27

conda create -n py36 python=3.6  #for version 3.6
activate py36

you may leave the environment back to your global env by typing
deactivate py27 
or 
deactivate py36 

and then you can either switch to different environment using your anaconda UI with @Francisco Camargo 's answer然后你可以使用 @Francisco Camargo 的答案使用 anaconda UI 切换到不同的环境

or you can stick to anaconda prompt using @Dan 's answer或者您可以使用 @Dan 的回答坚持使用 anaconda 提示

  1. Set python3 as a main version in the terminal: ln -sf python3 /usr/bin/python在终端中将python3设置为主版本:ln -sf python3 /usr/bin/python

  2. Install pip3: apt-get install python3-pip安装 pip3:apt-get install python3-pip

  3. Update spyder: pip install -U spyder更新 spyder:pip install -U spyder

Enjoy享受

In Anaconda, click on "Environments", scroll down to the software package(s) you need to update, and click on the update arrow.在 Anaconda 中,单击“环境”,向下滚动到您需要更新的软件包,然后单击更新箭头。

Anaconda 软件包更新

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

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