Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why using Anaconda environments to install tensorflow on Windows?

In tensorflow installation guide it is said, that I should use "environment" to install tensorflow: https://www.tensorflow.org/install/install_windows#installing_with_anaconda

Why? Can't I just install with pip?

If installed with environment, should I "activate" it each time I use tensorflow?

If I use tensorflow from within other thing like keras and/or PyCharm, then how can I activate environment?

like image 779
Dims Avatar asked Jul 11 '17 16:07

Dims


People also ask

Is Anaconda necessary for TensorFlow?

Anaconda Python 3.8 (Optional) Although having Anaconda is not a requirement in order to install and use TensorFlow, I suggest doing so, due to it's intuitive way of managing packages and setting up new virtual environments.

Why does TensorFlow need a virtual environment?

Because it gives you some more isolated environments to experiment with, without 'damaging' the rest of your system, if you experiment a lot there is chance the some dependencies could go in conflict and it also allows you to switch between different versions.

Can TensorFlow be install in base environment Anaconda?

Install TensorFlow 2.0 along with all packages on Anaconda for Windows 10 and Ubuntu. Anaconda makes it easy to install TensorFlow, enabling your data science, machine learning, and artificial intelligence workflows.

What is the use of Anaconda environment?

With conda, you can create, export, list, remove, and update environments that have different versions of Python and/or packages installed in them. Switching or moving between environments is called activating the environment. You can also share an environment file.


2 Answers

The question is about Windows. I assume you installed python using anaconda. Then you have a default environment, called root. You can create as many environments as you want, think of each as a separate installation of python. Using conda or pip installs stuff at your current installation. Conda stuff is kind of pre-compiled to work with your machine/anaconda environment, while pip stuff is usually compiled on the spot. I assume compiling tensorflow might not be completely trivial...

'Activate' changes from one environment to the other, so unless you have multiple environments you shouldn't need it. You run all these on command prompt.

Bottom line is, unless you have multiple environments (I highly recommend it so you can try different things) I cannot see you using activate. Install tensorflow and keras on the same one and only root environment you have. You should be able to access both (it is also possible just installing keras would install tensorflow, if its a dependancy)

If you see no prompt, it is the default, root environment. You can see all your environments with: conda info --envs But unless you create some environment (using e.g. conda create --name py Python=2) you probably only have root. One of the nice things with environments is you can have one with Python=2 (latest python 2), one with Python=3, another with Python=2.7 etc

On your follow-up, If you have multiple environments, you can switch between them on Pycharm by changing the interpreter. On the image you see me selecting e.g. py2_olv enter image description here

like image 71
ntg Avatar answered Nov 11 '22 18:11

ntg


Professional answer:

Quote from https://machinelearningspace.com/installing-tensorflow-2-0-in-anaconda-environment/:

What is Anaconda and why I recommend it?

... [dropped intro to Anaconda] ...

For a Python developer or a data science researcher, using Anaconda has a lot of advantages, such as independently installing/updating packages without ruining the system. So, we no need to worry about the system library or anything like that. This can save time and energy for other things.

Anaconda can be used across different platforms, Windows, macOS, and Linux. If we want to use a different Python version or package libraries, just create a different environment and play around without any risk of crashing the system library.

#### Unprofessional research:

Now in addition my own research. I am not a professional, I have little knowledge of the seemingly chaotic world of different install methods. This refers to some first research at https://superuser.com/questions/1572640/do-i-need-to-install-cuda-separately-after-installing-the-nvidia-display-driver/1572762#1572762. Mind that I am guessing a lot here. Please comment if I am wrong.

We see that at the moment, Pytorch supports version 10.2, Tensorflow supports 10.1, and it is not just the version that differs: mind that "CUDA Toolkit" (standalone) and cudatoolkit (conda binary install) are different! One is a a standalone / executable install, the other is a binary install. And tensorflow needs tensorflow-gpu to reach the standalone cuda install.

Therefore you should consider a separate environment for both Tensorflow and Pytorch, since any update of the conda cudatoolkit to version 11.0 could harm the dependency condition of Pytorch (Though this is not completely right. Pytorch uses a cuda that is installed inside Pytorch. It is still the approach to understand the recommended different envs). For tensorflow, you have to install version CUDA Toolkit 10.1 although 11.0 is already available, so that your whole card must run on a lower version than possible only to support Tensorflow - even if some games would like to have version 11.0.

Unprofessional answer:

If all of the dependencies are so important and so easily wrong when updated separately, like you could do with pip, any install that you do by yourself using pip might crash your sensitive tensorflow install. Therefore it is recommended to keep to a full service approach which Anaconda offers, where all dependencies are kept right, even if you enter conda install --all. That is why you better search for an Anaconda guide, for example https://machinelearningspace.com/installing-tensorflow-2-0-in-anaconda-environment/.

like image 28
questionto42standswithUkraine Avatar answered Nov 11 '22 19:11

questionto42standswithUkraine