简体   繁体   中英

Switching between Python 3.7 and 3.8 under Anaconda

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:

  1. D:\ProgramData\Anaconda3
  2. D:\ProgramData\Anaconda3\pkgs\python-3.7.6-h60c2a47_2
  3. 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:

  1. What is the rationale of having two versions under pkgs (as in 2. and 3. above) but just one default version (as in 1.)?

  2. The contents under the pkgs directory - are they complete Python installations?

  3. 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)?

  4. 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 ?

  1. What is the rationale of having two versions under pkgs (as in II and III above) but just one default version (as in I)?
  2. 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

  1. 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

  1. 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, eg 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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