如何在虚拟环境中运行Jupyter Notebook?

问题描述 投票:0回答:1

我是 jupyter 笔记本的新手。我想使用虚拟环境运行我的笔记本。我在我的环境中安装了tensorflow,但是当我使用环境内核运行它时,它找不到tensorflow。

我正在做一个使用张量流的项目。所以我使用 python 3.9 创建了一个名为“tensorflow_env”的虚拟环境。因此,为了使用此环境运行代码,我使用

ipython kernel install --user --name=tensorflow_env
添加了此环境内核。我已经在我的环境中安装了tensorflow。但是在尝试从笔记本 .ipynb 文件导入张量流时,它显示错误。

ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 1
----> 1 import tensorflow as tf
      3 print(tf.__version__)

ModuleNotFoundError: No module named 'tensorflow'

我尝试在激活环境后运行服务器。起初我在cmd中尝试过,然后也在笔记本终端中尝试过。我的 jupyter 笔记本作为 anaconda 的一部分安装。我从命令提示符打开它,无论是具有管理员权限还是不具有管理员权限。我也尝试过直接启动该应用程序。

之前我遇到错误,显示无法在环境中找到 pip.exe 文件。现在强行重装就可以找到了。我检查它已经安装了tensorflow。

我检查了各种问题,但找不到我的具体问题的答案。

好像我没有安装

ipykernel
。运行
pip install ipykernel
python -m ipykernel install --user --name tensorflow_env
后,现在我可以找到张量流了。但现在显示类型错误。

TypeError                                 Traceback (most recent 
call last)
Cell In[1], line 1
----> 1 import tensorflow as tf
      3 print(tf.__version__)

在此错误的最后显示,

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out 
of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other 
possible workarounds are:
1. Downgrade the protobuf package to 3.20.x or lower.
2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this 
will use pure-Python parsing and will be much slower).
python-3.x tensorflow jupyter-notebook virtualenv
1个回答
0
投票

我刚刚发现这个封闭的问题https://github.com/protocolbuffers/protobuf/issues/10051。随着 python 的新更新,它给

protobuf
和其他一些谷歌云软件包带来了一些问题。为了避免这种情况,只需安装旧版本即可。我安装了
protobuf=3.20
,它解决了问题。感谢您的关注。

© www.soinside.com 2019 - 2024. All rights reserved.