How to change python version in anaconda spyder - python

I am using 3.6 Python version in anaconda spyder on my mac. But I want to change it to 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
Tools -> Preferences
And depending on the Spyder version you can change the interpreter in the Python interpreter section (Spyder 3.x):
or in the advanced Console section (Spyder 2.x):

First, you have to run below codes in 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,
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.

If you want to keep python 3, you can follow these directions to create a python 2.7 environment, called py27.
Then you just need to activate py27:
$ conda activate py27
Then you can install spyder on this environment, e.g.:
$ 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 (e.g. C:\ProgramData\Anaconda3\envs\py27\Scripts)

You can launch the correct version of Spyder by launching from Ananconda's Navigator. From the dropdown, switch to your desired environment and then press the launch Spyder button. You should be able to check the results right away.

In Preferences, select Python Interpreter
Under Python Interpreter, change from "Default" to "Use the following Python interpreter"
The path there should be the default Python executable. Find your Python 2.7 executable and use that.

If you are using anaconda to go into python environment
you should have build up different environment for different python version
The following scripts may help you build up a new environment(running in 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
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
or you can stick to anaconda prompt using
#Dan 's answer

Set python3 as a main version in the terminal:
ln -sf python3 /usr/bin/python
Install pip3:
apt-get install python3-pip
Update 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.

Related

Python version in Jupyter Notebook (myenv: 'conda') different terminal version and I want to update

I'm having the same issue reported in this question
But I want to update it from Python 3.7 to 3.8. I don't know how to do that!
If i check in Terminal:
Python version in Terminal
But when I check in my Jupyter Notebook:
Version of python in 'conda' env. (3.7.10)
conda install -c anaconda python=3.8
conda update --all
conda create -n py38 python=3.8
now you have a new virtual environment with name py38 with python 3.8, where you can install everything again. There is no way to update python version only in some environment.
After that you can activate this env, install jupyter, and run it.
Also, try to use anaconda navigator UI to activate environment and run jupyter.

Why does not Spyder acknowledge the virtual environment?

I created a virtual environment in Conda for 2.7 named PY27 using the method of this thread:
How to run Spyder in virtual environment?
I have currently Python 3.7 installed and I wanted to emulate 2.7. However, although the environment looks as if it's working in the Anaconda Prompt switching correctly to the new PY27, in Spyder I still see 3.7.
In addition, I keep receiving this message:
"Note: you may need to restart the kernel to use updated packages."
I have tried to use the
conda init powershell command but I still receive the same message.
Thank you very much in advance for your help!
The python version in spyder's title bar is the python version of the environment in which spyder is installed. As of spyder 3.3, you can change the python kernel used by spyder without changing the python version of its environment.
First make sure you have spyder-kernels in your PY27 environment.
conda install -c conda-forge spyder-kernels
I'll recommend you install one of the spyder-kernels = 0* versions
Then execute python -c "import sys; print(sys.executable)" in your PY27 env prompt and copy the output. Open spyder and navigate to Tools -> Preferences -> Python interpreter and paste the command output there. You just told spyder to use yourPY27 env's python interpreter.
Reload spyder and you should see you're PY27 env's python kernel show up on the console.

Spyder, switching between python 2 and 3 [duplicate]

I am using 3.6 Python version in anaconda spyder on my mac. But I want to change it to 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
Tools -> Preferences
And depending on the Spyder version you can change the interpreter in the Python interpreter section (Spyder 3.x):
or in the advanced Console section (Spyder 2.x):
First, you have to run below codes in 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,
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.
If you want to keep python 3, you can follow these directions to create a python 2.7 environment, called py27.
Then you just need to activate py27:
$ conda activate py27
Then you can install spyder on this environment, e.g.:
$ 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 (e.g. C:\ProgramData\Anaconda3\envs\py27\Scripts)
You can launch the correct version of Spyder by launching from Ananconda's Navigator. From the dropdown, switch to your desired environment and then press the launch Spyder button. You should be able to check the results right away.
In Preferences, select Python Interpreter
Under Python Interpreter, change from "Default" to "Use the following Python interpreter"
The path there should be the default Python executable. Find your Python 2.7 executable and use that.
If you are using anaconda to go into python environment
you should have build up different environment for different python version
The following scripts may help you build up a new environment(running in 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
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
or you can stick to anaconda prompt using
#Dan 's answer
Set python3 as a main version in the terminal:
ln -sf python3 /usr/bin/python
Install pip3:
apt-get install python3-pip
Update 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.

Installing python 3.6 , when I am already using Anaconda Python 2.7

I am currently using Anaconda2 .
python -V gives :- Python 2.7.11 :: Anaconda 4.0.0
Now I want to use Python 3.6 and i tried to update my python version using the following command in anaconda:-
conda install python=3.6
but this did not worked , because I work in a restricted environment MNC .
Two Options are available to me and I want to know which one should I follow
1> I can install Anaconda3 .
But if do that , do i need to uninstall already existing version of Anaconda I am using i.e Anaconda2 ? If not please tell me how will I choose which version of python to use in Spyder.
2> I can install Python3.6 .
If I take this option , I have no idea of what to do afterwards.
P.S.:- I am not very good at installation so please guide me in the easiest way possible.
Also if there is some other way , please share that too
are you able to create a new environment with the command:
conda create -n py36 python=3.6
?
if so, anaconda will create a new subfolder for this environment in the anaconda/envs folder named py36. in spyder you can go to tools->preferences->python interpreter and choose the python interpreter (python.exe if on windows) in that folder. to use pip and all in the commandline for that environment write:
if on linux/mac:
source activate py36
if on windows:
activate py36
then continue to do you installations and all.
Take a look at environments, which enable you to have multiple python versions and manage them seperately. The documentation can be found here
In short, just do:
conda create -n myenv python=3.6
to create an environment with python 3.6. You can enter it doing
source myenv
and then pip install any desired packages.
If you are using Anaconda and python, you just update it with:-
Open Anaconda Prompt type:-
conda update conda
conda update python
Check your python version python --version and conda version conda --version

iPython with different env (using anaconda)

I have just created a new env with python 3.5 using anaconda (called it python35). My root env points to python 2.7.11. I cant seem to launch ipython with this new env, here is what I did
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. 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. 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). To fix the behavior, you need to install its own copy of ipython to anaconda env:
In command prompt, activate the environment: source activate python35 (or simply activate python35, depending on the OS)
While in environment, issue the command conda install ipython-notebook
An addition to Andrey Sobolev solution,you should switch to conda install ipython for higher python3.x version and log out the environment by Ctrl+D or conda deactivate then activate again
I could confirm the solution above (basically install notebook in active environment) in my case. Two updates from my side:
Since Anaconda 4.4 (?) ipython notebook is now jupyter notebook. So I had to install jupyter instead. 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.
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. 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 e.g "which jupyter"

Categories