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

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.

Related

How to pick python 3.11 as a conda environment in vs code

I am just start using vscode to write python code. And I am normally using conda as my package and environment tool.
I am trying to create a conda environment for python 3.11 in my project directory based on the instruction in the vscode official document https://code.visualstudio.com/docs/python/environments.
However, it only list python 3.7 - 3.10 as the python version I could choose.
I am wondering how could I pick python 3.11 in the conda environment?
I am using an Intel 2019 macbook pro. I already installed python3.11 through homebrew from command line.
And I have also installed miniconda and created a python 3.11 environment through command line.
However, when I tried to create .conda environment in vscode
Screenshot to create python environment
Screenshot to select python interpreter version for conda environment
It only show python 3.7 - 3.10
This problem is related to conda, but it's not a vscode problem. You can create a conda environment with the following command,
conda create --name myenv -c conda-forge python=3.11
Then select the created conda interpreter in the Select Interpreter panel.
More information on conda commands.
Right now, python 3.11 is still quite new so it's not yet available through the "standard" channels. You should still be able to install it with conda from the command line:
conda create -c conda-forge -p ./.venv python=3.11
-c: Adds the "conda-forge" channel: https://anaconda.org/conda-forge/python
-p: Creates the virtial environment to the given path

Python version not changing in Vscode

I was creating a virtual environment in python 3.7.9 but vscode is creating an environment in python 3.9.12 (I have anaconda installed with that version). I used the command ctrl+shift+p to change the environment to 3.7.9 but it's created in 3.9.12. I had to uninstall anaconda to create an environment. How to fix this?
Steps to change the Python version in VS Code:
change to your project path (e.g. using cd)
create a new virtual environment (venv) using your Python binary in the given version (e.g. python3.7):
`which python3.7` -m venv .venv
change your VS Code interpreter by clicking in the status-bar (see red rectangle below)
There is a corresponding relationship between Python version and CONDA version.
A simple modification of interpreter cannot change the python version. You must install the CONDA environment of the corresponding version of Python.
Here is the download page of conda

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.

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.

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