9

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?

Dims
  • 47,675
  • 117
  • 331
  • 600

3 Answers3

4

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

ntg
  • 12,950
  • 7
  • 74
  • 95
  • How to know, which environment is activated from window application, not command line ones? I don't see any prompt when running PyCharm for example. Is environment systemwide? What if I activate one env in one terminal and another in another? – Dims Jul 11 '17 at 17:32
  • 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. – ntg Jul 12 '17 at 07:24
  • use 'activate py2' to go into py2 environment etc. (In Linux it is source activate py2) – ntg Jul 12 '17 at 07:28
  • Sorry, just seen the pycharm part... The activate, conda info etc. are for command prompt. After that you can specify the relevant environment from pycharm bu going to config and setting interpreter, I ll add an image on my answer. – ntg Jul 12 '17 at 07:49
  • 1
    From my experience, even if you only have the base environment, you still need to activate it before calling executables. For example, I had a script in R that called `pandoc`, taking it from the Anaconda distribution, and it always crashed. Turned out `activate base` needed to be issued before calling pandoc... – pglpm Apr 04 '20 at 16:37
  • Agree, probably best practice to activate, may save you hours of not knowing what's what... Question was about finding what is going on otherwise. – ntg Apr 06 '20 at 09:25
1

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

questionto42
  • 7,175
  • 4
  • 57
  • 90
0

If you would have read through the entire document, it would have stated that the Anaconda installation is community supported, not officially supported. They want you to install TensorFlow using native pip through Python 3.5.x. That being said, from personal experience, I will tell you that if you are looking to run basic level TensorFlow Python scripts, such as training and testing an MNIST model, a Windows installation will be fine, or using a model that has already been trained for some purpose will also be fine. However, if you want to train advanced models such as Inception, which are the state-of-the-art image classifiers with less than 5% error for normal images, Windows is not suitable. You should try using Linux installation for any training purposes. I would recommend using VirtualBox, having used it in the past. As for activating the environment, as long as, in any script / in the bash, you include the line "import tensorflow as tf", you should be fine, at least for native pip installation. Good luck!

  • Why Windows is bad? I can use GPU on Windows, isn't this a key fact? – Dims Jul 11 '17 at 17:30
  • You can use it, the only problem is that it is quite buggy; you will encounter a lot of errors that may or may not make any sense. This may be different for you, but I personally had a lot of trouble. – Nikash Walia Jul 12 '17 at 03:55
  • This answer is out of date and slightly misleading. Tensorflow for windows is supported on Python versions 3.5 AND 3.6. It should also be noted that when it says the Anaconda version is community supported, that does not mean that you can't use it with Anaconda. Conda is just an environment manager. If you install Tensorflow using `pip install tensorflow` instead of the conda equivalent then you will be just fine as you are installing the latest official binary from Pypi. Regarding Windows being slow and buggy, I have not had any issues. Virtualisation is unlikely to be any better. – JCooke Jul 12 '17 at 10:34