3

I was suggested to conda create a new environment for installing tensorflow

First question, in general:

Why do environment exist in conda or in Python ? (Why) is it preferable to install a new library in a new environment ?

Here, in practice:

After install conda shell says $conda activate test will activate the test environment. Does it mean i can't access the lib in Spyder unless i activate test in conda shell ? Do i need to restart python shell to see the lib ? I can't access the lib (no module named tensorflow) and I assume it has to do with python not finding the path.

kiriloff
  • 25,609
  • 37
  • 148
  • 229

2 Answers2

2

After install conda shell says $conda activate test will activate the test environment. Does it mean i can't access the lib in Spyder unless i activate test in conda shell ? Do i need to restart python shell to see the lib ? I can't access the lib (no module named tensorflow) and I assume it has to do with python not finding the path.

Have you installed TF within the environment?

I haven't used Spyder in a while, but what usually happens is that you can start a program (like Spyder or Jupyter) from an environment if you have installed the application within it and the environment is active. (Some editors/IDE like VS Code lets you choose the environment for a specific project, once it is able to discover all the environments.)

And, also usually, though perhaps not always, you will not need to restart the shell to import a library, after installing it. It's best to refer to the specific library's installation instructions for details like this.

navneethc
  • 1,234
  • 8
  • 17
1

Virtual Environment is used to manage Python packages for different projects. Using virtual environment allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtual environment using pip.

For example, say you have two projects, and each requires a different version of Tensorflow. This is a real problem for Python since it can’t differentiate between versions in the “site-packages” directory. So both say V1.1 and V2.1 would reside in the same directory with the same name.

This also allows easy clean up, once you are done with the project just delete the virtual environment.

Checkout more, https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/

codeblooded
  • 320
  • 1
  • 9