Switching between Python 3.7 and 3.8 under Anaconda - python

I have an Anaconda installation on Windows 10 primarily to run Jupyter Notebook and Spyder.
I find the Python runtime (python.exe) in 3 places after installation, viz:
D:\ProgramData\Anaconda3
D:\ProgramData\Anaconda3\pkgs\python-3.7.6-h60c2a47_2
D:\ProgramData\Anaconda3\pkgs\python-3.8.2-he1778fa_13
The python.exe under 1. and 2. are identical and run Python 3.7. 3. runs Python 3.8.
Questions:
What is the rationale of having two versions under pkgs (as in 2. and 3. above) but just one default version (as in 1.)?
The contents under the pkgs directory - are they complete Python installations?
What is the best way to make Jupyter Notebook pickup Python 3.8? It currently picks up Python 3.7 because the location 1. is in PATH. (That is, are the pkgs directories full installations)?
If I want to work with Python 3.9, is there a way to upgrade the current Ananconda to that extent? Or, do I have to delete the current Ananconda3 and install the latest Anaconda provided, of course it supports Python 3.9?

What is the rationale of having two versions under pkgs (as in II and III above) but just one default version (as in I)?
The contents under the pkgs directory - are they complete Python installations?
The pkgs folder is only a type of cache where packages that conda downloads and decompresses are kept so that they can be installed more quickly into new environments, so no they are not complete python installations ready to be used. There can only be one python version in one environment, in your case D:\ProgramData\Anaconda3\python.exe is the one that belongs to the base environment
If I want to work with Python 3.9, is there a way to upgrade the current Ananconda to that extent? Or, do I have to delete the current Ananconda3 and install the latest Anaconda provided, of course it supports Python 3.9?
To install a different python version into the current environment, simply do conda install python=<version>. You can use conda search python to check the available versions, or see on the website that the default channel has 3.9 as a newest version. However upgrading your base will most likely fail. Anaconda comes with a huge list of preinstalled packages and python 3.9 is too new, so that conda will not be able to resolve dependencies with newer python versions. The newest anaconda installer comes with python 3.8. only
What is the best way to make Jupyter Notebook pickup Python 3.8?
To have multiple python installations, use virtual environments (as there can only be one python version in one environment) which is very easy to use:
conda create -n py39 python=3.9
conda create -n py38 python=3.8
conda create -n py37 python=3.7
would create three environments that you can selectively activate with
conda activate py37 #or
conda activate py38 #or
conda activate py39
To use an environment, you need to activate it and then you can also install packages for that environment, e.g. to set up jupyter for one of them, simply do
conda activate py37
conda install ipykernel jupyter
python -m ipykernel install --user --name py37 --display-name "Python 3.7"
then you can start jupyter as you are used to and select Python 3.6 as the kernel.
Note that for each environment you will need to install all packages again, there is no cross-talk between them, so doing
conda activate py37
conda install numpy
will install numpy only to the py37 env, not to base, py38 or py39

Related

Install packages with Conda for a second Python installation

I recently installed Anaconda in my Windows. I did that to use some packages from some specific channels required by an application that is using Python 3.5 as its scripting language.
I adjusted my PATH variable to use Conda, pointing to the Python environment of the particular program, but now I would like to use Conda as well for a different Python installation that I have on my Windows.
When installing Anaconda then it isn't asking for a Python version to be related to. So, how can I use Conda to install into the other Python installation. Both Python installations are 'physical' installations - not virtual in any way.
Uninstall the other python installation and create different conda environments, that is what conda is great at.
Using conda from your anaconda installation to manage packages from another, independent python installation is not possible and not very feasible.
Something like this could serve your needs:
Create one env for python 3.5 conda create -n py35 python=3.5
Create one env for some other python version you would like to use, e.g. 3.6: conda create -n py36 python=3.6
Use conda activate py35, conda deactivate, conda activate py36 to switch between your virtual environments.

How to install the specific version of Python with Anaconda?

I want to install Anaconda with Python Version 3.6.5. If I install Anaconda3-5.2.0, It install Python 3.5.1. Where to download the Anaconda with Python 3.6.5. The Big Data Scripts work only with Anaconda Python 3.6.5.
Anaconda Downloads
The Anaconda distribution with Python 3.6.5 was version 5.2.0.1 You can download this from the Anaconda distribution archive. If you do install from this, then make sure to update Conda immediately after installation:
conda update conda
However, I strongly recommend the following alternate solution as better practice.
Miniconda + Anaconda environment
Reasoning
What is installed in the base environment is relatively fixed once installed. Ultimately, you don't want to mess with your base environment, so best practice is to have the latest version there. Fortunately, you don't have to install a full Anaconda distribution, but rather can use a lightweight Miniconda (or Miniforge) distribution and create a secondary environment for the purpose of having an Anaconda Python 3.6.5 distribution. In the long run this will give you better stability.
Steps
Download and install Miniconda or a Miniforge variant. Once that is working...
Create your Anaconda env:
conda create --name my_env -c anaconda python=3.6.5 anaconda=5.2.0
Use your new isolated env:
conda activate my_env
[1] I determined this by running conda create -n foo --dry-run -c anaconda python=3.6.5 anaconda and then examining the version of the anaconda package that Conda ended up with in the solve.
Also try
conda install python=3.6.5
but you may encounter some incompatibility issues with other packages.
Alternatively, you may want to try creating a new environment. From the anaconda prompt, create a custom environment and specify the repository channel to find the version
conda create --name py365 python=3.6.5 --channel conda-forge
Activate the new environment
conda activate py365
However, the activation will not be permanent, and you will need to activate each time you start the anaconda prompt.
In your anaconda prompt, you can manually update your python to the latest version with :
conda update python
In case you are not familiar with it, anaconda prompt is installed to your computer when you install anaconda. Just make a search for it on your computer.
You can refer to this post : How do I upgrade to Python 3.6 with conda?

Looking for a cross-platform (Linux, MacOS, Windows) tool for managing Python environments

I was investigating the use of Anaconda environments for CI/CD (since, to my knowledge, it is the only platform that supports Linux, MacOS, and Windows). I tried to use Miniconda which is supposed to only install the bare minimum. However, I realised that, by default, Miniconda is not "mini" after all. For example, if I attempt to create a new Python environment (conda create -n py36 python=3.6 anaconda), it will install a bunch of not needed stuff like JupyterLab and others. So, before moving to pyenv (for Linux and MacOS) and pyenv-win (for Windows), I would like to ask:
Is there a way to setup different python environments with anaconda/miniconda without having to install a bunch of extra packages every time I create a new environment?
Is there any other tool for managing python environments that supports Linux, MacOS, and Windows?
Thank you.
Only install python and its dependencies by
conda create -n py36 python=3.6
without the anaconda package.
Detailed Explanation
conda create -n py36 python=3.6
conda create -n py36, create an environment, actually an empty folder
python=3.6, installed python 3.6 into this env
conda is a package manager, both python and anaconda are packages could be installed by it.
Unlike package python, anaconda is a meta package, which does not contain actual software and simply depends on other packages to be installed.
Download an anaconda package here and extract content from it. The actual packages to be installed is listed in info/recipe/meta.yaml.
package:
name: anaconda
version: '2019.07'
build:
ignore_run_exports:
- '*'
number: '0'
pin_depends: strict
string: py37_0
requirements:
build:
- python 3.7.3 h8c8aaf0_1
is_meta_pkg:
- true
run:
- alabaster 0.7.12 py37_0
- anaconda-client 1.7.2 py37_0
- anaconda-project 0.8.3 py_0
# ...
# about 260 packages in total
You want virtualenv: https://virtualenv.pypa.io/en/latest/
$ virtualenv env --python "[path to python version]"
This will create an environment from the python base you chose in the previous command, in a folder called 'env'. There will be no additional packages installed save pip and a few other core ones.
You then need to 'activate' the environment - this changes based on operating system. For windows;
$ env\Scripts\activate
You will then have the command prompt;
(env) $
Showing it's activated. You can then use pip install as normal to install whatever requirements you need into that environment (they will live inside the env folder). To leave the environment;
(env) $ deactivate
You can have as many as you need, and define different python versions and requirements. Just remember to activate the environment before installing packages.

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

Command line conda with 2 anaconda installation

To make easier migration, 2 Anaconda versions have been installed on Windows:
Anaconda 27 and Anaconda 34
However, on the command line conda update ....,
how can I specify the right 'conda.exe'
apart from putting the full path for conda?
Recommended Solution - Using conda Environments
Instead of installing two different Anaconda version, I would recommend
to use conda environments. Create one for Python 2.7:
conda create -n py27 python=2.7
Now, you can activate it with:
activate py27
the prompt will change to
(py27)
and:
(py27) conda install anaconda
will install all Anaconda packages.
Likewise, do it for Python 3.5:
conda create -n py35 python=3.5 anaconda
This will install all anaconda packages right away.
Solutions for Already Installed Multiple Anaconda Versions
If you already have installed two Anaconda versions these solutions might work for you.
Using two command line windows
You can set the PATH environmental variable.
In your first shell do:
set PATH=C:\path\to\conda2;$PATH$
and in your second:
set PATH=C:\path\to\conda3;$PATH$
Now conda should be the version you set with the PATH.
Using one command line window
You can a create two batch files that you put in your PATH:
conda2.cmd
C:\path\to\conda2\conda.exe
conda3.cmd
C:\path\to\conda3\conda.exe
Now conda2 should start the Python 2 and conda3 the Python 3 version.

Categories