1

When I install the latest version of anaconda distribution, it comes with flask version 1.1.2. However, I need to install flask version 2.0. How can I install flask version 2.0 (in the base environment) while keeping other existing packages installed such as sklearn and numpy, etc.?

davidism
  • 121,510
  • 29
  • 395
  • 339

2 Answers2

3

First do conda activate base,

Then you can either do pip install flask==2.0.0 or conda install -c conda-forge flask==2.0.0. Both are okay as long as you do conda activate base first.

You should consider creating a new environment for your project and not mess with the base environment.

First do conda create -n newname, then conda activate newname.

Then you can do conda install -c conda-forge numpy pandas sklearn flask==2.0.0, you can also do pip install numpy pandas sklearn flask==2.0.0. You can install everything you need in one line.

anarchy
  • 3,709
  • 2
  • 16
  • 48
  • It worked. Thank you. However, the reason I'm not creating a new environment is that if I create a new one, all necessary packages (such as numpy, sklearn, etc.) are not automatically installed in it. Is there a way to automatically install these packages without explicitly installing them one by one? – Abdulwahab Almestekawy Aug 23 '21 at 18:49
  • There’s a quick way, I’ll update my answer, it’s better this way, so you don’t mess up the base, you just separate the package names with a space. – anarchy Aug 23 '21 at 18:49
1

In a nutshell:

conda activate base
conda remove flask
conda install -c conda-forge flask

Line 1: to activate your base virtual environment

Line 2: in order to avoid any conflict, remove flask 1.1.2

line 3: install the latest flask version via the channel conda-forge (2.0.1 as for now)

If you want the 2.0.0 you should do this: conda install -c conda-forge flask=2.0.0

Explanations:

  • Channels:

conda uses channels (like repositories where the packages are stored). By default, the channel is the anaconda channel. So, if you installed flask with conda install flask that is the same as if you did conda install -c anaconda flask. And from this page (https://anaconda.org/anaconda/flask) you can see that the actual version on this channel is 1.1.2.

  • About the update part:

In general, to update all your packages in a virtual environment, you first have to activate your virtual environment with conda activate [virtual_environment_name] and then conda update --all.

But as you can see from the previous link, on the default channel (anconda), the latest version is 1.1.2, so, strictly speaking, you can't update flask to a version greater than 1.1.2.

But, because on the conda-forge channel the latest version is -as for now- 2.0.1, if you install flask from this channel, you will get flask 2.0.1.

  • Using pip in a Conda environment:

An other option mentionned by @anarchy too is to use pip install flask=2.0.0 but you should avoid that. See: https://www.anaconda.com/blog/using-pip-in-a-conda-environment and Is that a bad idea to use conda and pip install on the same environment?.

  • About not using the base environment directly:

And in order to have a clean workspace, it's a good practice to create a virtual environment other than the base environment for your projects. You can create and then activate a new environment named for example "myenv" like this:

conda create -n myenv
conda activate myenv

And so the complete code would be:

conda create -n myenv
conda activate myenv
conda install -c conda-forge flask

And finally if you want to install the latest versions of other packages like numpy and sklearn, you should use conda-forge too:

conda install -c conda-forge scikit-learn 
conda install -c conda-forge numpy
Rivers
  • 1,783
  • 1
  • 8
  • 27