每次加入 virtualenv 都需要重新安装 Tensorflow 吗?

Do I Need to Reinstall Tensorflow everytime I join a virtualenv?

所以我按照本教程 https://www.tensorflow.org/install/pip#windows 并在 venv 上安装了 Tensorflow(它已成功安装)然后我停用了 venv 然后再次加入以检查它是否已安装并且不再安装了?

收到这条消息

(venv) C:\Users\eddie>python -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
2020-07-20 16:33:41.151220: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-07-20 16:33:41.154540: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
2020-07-20 16:33:42.469966: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'nvcuda.dll'; dlerror: nvcuda.dll not found
2020-07-20 16:33:42.473332: E tensorflow/stream_executor/cuda/cuda_driver.cc:313] failed call to cuInit: UNKNOWN ERROR (303)
2020-07-20 16:33:42.478266: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: LAPTOP-PV67HTAL
2020-07-20 16:33:42.481952: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: LAPTOP-PV67HTAL
2020-07-20 16:33:42.483927: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-07-20 16:33:42.494211: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x29059196c40 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-20 16:33:42.499523: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
tf.Tensor(-660.95654, shape=(), dtype=float32)

我注意到他们的安装文档说在我使用完 Tensorflow 之前不要退出 venv 那么这是否意味着我每次加入同一个 venv 时都需要重新安装它?如果是这样,有没有办法让它保持安装状态?

是否有针对使用 Tensorflow 的人的常规设置?我打算用它来使用 vscode,但是这个安装让我很头疼。

不,您不需要每次都重新安装tensorflow。当您激活虚拟环境时,所有必要的变量都会被设置,您可以访问您已经安装在这个环境中的库。

关于消息:这表明 tf 已安装并且正在运行。虽然有一些关于缺少库的警告,但你在最后一行得到了结果。

查看您消息的最后一行:

tf.Tensor(-660.95654, shape=(), dtype=float32)

这是

的结果
import tensorflow as tf
print(tf.reduce_sum(tf.random.normal([1000, 1000])))

命令。

不,你不需要每次加入 virtualenv 时都重新安装 Tensor Flow