如何使用 Anaconda 管理具有虚拟环境的库?

How to manage libraries with virtual environment wit Anaconda?

我已经通过以下步骤安装了带有 Anaconda 的 TensorFlow(参见此处:https://docs.anaconda.com/anaconda/user-guide/tasks/tensorflow/

conda create -n tf tensorflow
conda activate tf

现在我可以在 Visual Code Studio 中打开 Jupyter Notebook,从 tf 虚拟环境中选择正确的 Python 内核并导入 tensorflow。但是,当我尝试导入其他库时,例如我安装在其他 Python 文件夹中的 pandas,它不起作用(没有名为 'pandas' 的模块)。我是否需要在此虚拟环境中重新安装所有内容?我可能错过了一半......我将不胜感激任何帮助。问候!

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]

以上都是可以的,你需要在新的虚拟环境中安装你需要的所有模块。

如果你有一些虚拟环境(或带有你需要的模块的基础 python 版本)你可以尝试创建 and use it for conda env creation 但虚拟环境的主要思想 - 你只有你的任务需要的东西.