为什么在anaconda powershell prompt中建立虚拟环境test,安装了TensorFlow,在jupyter notebook中却无法使用import TensorFlow
时间: 2024-04-30 16:18:38 浏览: 183
可能是因为 Jupyter Notebook 没有找到你所创建的虚拟环境。请按照以下步骤进行操作:
1. 在 Anaconda Powershell Prompt 中激活你创建的虚拟环境:`conda activate test`
2. 在激活的虚拟环境中安装 Jupyter Notebook:`pip install jupyter`
3. 启动 Jupyter Notebook:`jupyter notebook`
4. 在打开的 Jupyter Notebook 界面中,新建一个 Python3 的 Notebook。
5. 在新建的 Notebook 中输入以下代码并运行:
```
import tensorflow as tf
print(tf.__version__)
```
如果输出了 TensorFlow 的版本信息,则说明环境配置成功。
如果仍然无法导入 TensorFlow,可以尝试在 Jupyter Notebook 中运行以下命令,看看是否能够找到你所创建的虚拟环境:
```
import sys
print(sys.executable)
```
如果输出的路径与你所创建的虚拟环境不符,可以尝试在 Jupyter Notebook 中运行以下命令,将虚拟环境添加到 Jupyter Notebook 的内核中:
```
python -m ipykernel install --user --name=test --display-name "Python (test)"
```
其中 `--name` 参数指定了虚拟环境的名字,`--display-name` 参数指定了在 Jupyter Notebook 中显示的名称。运行成功后,重新启动 Jupyter Notebook,再次尝试导入 TensorFlow,看看是否成功。
阅读全文
相关推荐


















