Switch back to python 2.7 Anaconda - python

I have installed anaconda with python 3.4 for windows 7 64 bits but want to use a python 2.7 environment.
I did the following in command line
conda create -n py27 python=2.7 anaconda
and then
activate py27
now I can read
[py27] SOMEPATH\Continuum\Anaconda3>
but still typing
python --version
leads to
Python 3.4.1 :: Anaconda 2.1.0 (64-bit)
I was expecting it to be showing python 2.7 version hence my question
Any ideas for where I might get it wrong?

Try changing your directory to something other than the Anaconda directory (like cd C:\). The Windows shell always searches the current directory first, so if you are in the Anaconda directory and you type python, it will run the python.exe in that directory.

Related

Commands to run different python versions on venv at once CMD

I am currently running python 3.9 on my system. Due to the incompatibility of some of python libraries like numba on python 3.9 I will have to use previous versions. What cmd commands will I have to use to create a virtual environment so that I could run python 3.6 on cmd separate from python 3.9. I have a windows 10 64 bit system, I dont use conda or anything.
CMD Output:
C:\Users\maste>python -V
Python 3.9.1
In Windows you can utilize the Python Launcher for Windows. You can just install multiple Python versions from Python.org, and then use
py -3.6 -m venv venv
To create a virtual environment called "venv" (the last argument is the name). After that just activate your virtual environment and python will point to the Python 3.6 in your virtual environment.
Instead of the py launcher, you can also just use the full file path of the Python 3.6 (assuming Powershell, hence &):
& "C:\path\to\python 3.6\python.exe" -m venv venv
Lastly, you don't have to activate the virtual environment, if you don't want to. You can just run
<path-to-project>\venv\Scripts\python.exe myscript.py

Python version in Programs and Features is different to that in Anaconda

I have Windows 10 Home 64-bit. In the Control Panel > Programs and Features menu, I can see that I have Python 3.5.2 (Anaconda 4.1.1 64-bit) installed. As I wanted to upgrade Python 3.5 to Python 3.6, I then ran this command in Anaconda Prompt conda install python=3.6.8. After the upgrading/installing process in Anaconda Prompt was finished, I ran this command python -V and it showed Python 3.6.8 :: Anaconda 4.1.1 (64-bit). However, when I refreshed the Control Panel > Programs and Features menu, it still showed Python 3.5.2 (Anaconda 4.1.1 64-bit). I then ran this command conda info --envs and it showed I only have the base environment.
Could anyone please advise:
Why are there two different information of Python versions in this case?
Which Python version is actually installed in my laptop?
In my Jupyter Lab Launcher, under Notebook section, I can see two Python symbols: Python 3 and Python [conda env:root]*. What are the differences between these two and which one should I use to launch a new notebook?
Thankyou!
Conda creates virtual environment inside your machine. The python version is different inside conda. If you want install different python inside conda you can decide the python at the time of creation of environment.
conda create -n TestEnv python=3.6.8
If you want update the python inside conda virtual environment, activate the virtual environment using
conda activate TestEnv
Now you can see the python version of your virtual environment
Deactivate your virtual environment and check python version using python -V this is the version of your Laptop Python or base version of python.

Opening Spyder from a Python 2 Environment still runs Python 3 in Spyder

I have created a new environment, specifying the Python version as 2.7. This has worked correctly as when I activate the environment and I run on the command line:
python --version
It returns:
Python 2.7.15
However, when I then open Spyder from the command line in the same environment, Spyder is still using Python 3. I was expecting the Python version in Spyder to match the Python version in the environment. So what could be stopping it working as I expected? I am on Linux Ubuntu on a virtual machine.
Maybe you are launching it from the wrong environment.
Assuming you're using Anaconda, you should activate the py2 environment and launch spyder from it, but being sure to have installed it in there before.
Here a simple sequence as example:
1. Create a new env py2 based
>conda create -n <NAME_OF_YOUR_ENV> python=2.7
2. activate the environment
>activate <NAME_OF_YOUR_ENV>
3. install Spyder
<NAME_OF_YOUR_ENV> >conda install spyder
4. launch spyder
<NAME_OF_YOUR_ENV> >spyder
It should be enough
Do you have several python installed on your system? I guess you have 2.7.15 installed by default with your system and you installed python 3 (via Anaconda?) without adding it in your path.
Are you in spyder's directory when you launch it (and launch spyder with ./spyder)?
It seems I missed a step to install the Spyder package within the environment.
conda install spyder
It works as expected now.

When I run localserver on googleappengine error is "File "~/dev_appserver.py", line 102, in <module> assert sys.version_info[0] == 2 AssertionError"

I think that this problem is due to the python version. I used Anaconda with python 3.6 for learning django. Now I've to work on google app engine using python2.7. I uninstalled anaconda. Now when i run "python" I get:
"Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:09:58)".
Is there a way to default back to python2.7?
I'm on ubuntu 16.04
edit: problem is not due to python version
Since you are using Anaconda, you can create a new virtual environment by typing:
conda install -n yourenvname [package]
So with python2.7 installed:
conda create -n python2 python=2.7 anaconda
source activate python2
And if you want to leave the virtual environment:
source deactivate python2
If you want to list all of your virtual environment:
conda env list
This way, it will not interfere with your existing python 3.6.
Be aware of these command are used for conda, another command pip is for another case.
To change to python2.7, you can use the following command in terminal
alias python=python2.7
or
alias python=/usr/bin/python2.7
For more detail https://askubuntu.com/questions/590027/how-to-set-python-3-as-default-interpreter-in-ubuntu-14-04
For those who are using Windows and still facing the same issue, the easiest way is to remove all the other python versions except version 2.7x.

Python2.7 in Conda Env not found in Registry

I'm working on Windows 10 and I have just installed python 2.7 in a Conda Environment with the cmd command conda create -n python27 python=2.7 anaconda.
This worked fine and now I have a python 2.7 installed in C:\Anaconda3\envs\python27 which I can activate and deactivate when needed.
The problem is that I'm also trying to get a python code (for python 2.7) included in a Windows Installer which is only recognizing (i.e. finding in registry) the "principal" python version I have installed (it's a python 3.5 installed in C:\Anaconda3) and not the python 2.7 I would need.
How can I solve my problem? Is there some Conda trick I can easily use?
Thanks!

Categories