0

I have installed TensorFlow with Anaconda with following steps (see here: https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/)

conda create -n tf tensorflow
conda activate tf

Now I am able to open a Jupyter Notebook in Visual Code Studio, choose the right Python Kernel from the tf virtual environment and import tensorflow. However, when I try to import other libraries, for example pandas, which I have installed in other Python folders, it does not work (No module named 'pandas'). Do I need to install everything again in this virtual environment? I am probably missing the half of it... I would much appreciate any help. Regards!

José
  • 533
  • 1
  • 4
  • 14

1 Answers1

2

A virtual environment is a named, isolated, working copy of Python that that maintains its own files, directories, and paths so that you can work with specific versions of libraries or Python itself without affecting other Python projects. Virtual environmets make it easy to cleanly separate different projects and avoid problems with different dependencies and version requiremetns across components. The conda command is the preferred interface for managing intstallations and virtual environments with the Anaconda Python distribution. If you have a vanilla Python installation or other Python distribution see virtualenv [1]

All above means yes, you need to install all modules you need in new virtual env.

If you have some virtual env (or base python version with modules you need) you can try create requirements file and use it for conda env creation But main idea of virtual env - you have only stuff you need for your task.

Alex K.
  • 842
  • 7
  • 17
  • 2
    Just to add to this answer. Remember when you will be installing your packages again in your virtual environment they will be installed to the latest version while your original packages may have old version installed. So this might cause you a bit of a trouble while running code in/outside the virtual environment. – glory9211 Dec 02 '20 at 15:11
  • Thanks! In this case, there are two things I don't understand. 1. Then I need to install again many libraries in this virtual environment (such as sklearn, pandas, numpy...). Can I install them in the virtualenv with conda? It makes so little sense to me... 2. Why does TensorFlow force me to install it in a virtual environment? Do they really expect I will be ONLY working with their libraries and not with others such as numpy, sklearn or pandas? – José Dec 02 '20 at 15:16
  • Feel free to install Tensorflow to your default Python via pip, no problem with this. VENV makes sense when you have different projects with conflicting versions of modules. – Alex K. Dec 02 '20 at 15:36
  • Until now I have managed the installation of the libraries with conda. Do you think I could install tensorflow with pip and that the libraries I have installed with conda and the ones I will install with pip (tensorflow) will work together? Thanks for your answers! – José Dec 02 '20 at 16:03
  • Usually it is recommended to use conda install and same [channel](https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/channels.html) But you are able to mix them and use pip – Alex K. Dec 02 '20 at 16:21