Warm tip: This article is reproduced from serverfault.com, please click

How to manage libraries with virtual environment wit Anaconda?

发布于 2020-12-02 14:54:50

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!

Questioner
José
Viewed
0
Alex K. 2020-12-02 23:05:43

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.