您在终端中启动 Jupyter 笔记本时,它运行在什么环境中?

huangapple go评论89阅读模式
英文:

What environment is my jupyter notebook runninng on when I launch it from my terminal?

问题

当我启动jupyter notebook时,我正在使用一个conda环境,我的环境中安装了Python 3.8。

然而,当我启动笔记本并尝试导入包时,我遇到了(请注意最后一行):

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-7-2b...8b8> in <module>
----> 1 from blah import reference

~/work/blah/blah/__init__.py in <module>
     66 from ._internals.api import configure as _configure
     67 from ._internals.api.utils.warnings import PatchWarning as _PatchWarning
     68

~/work/blah/blah/_internals/api/configure.py in <module>
     12 from blah._internals.rest import user
     13 from blah._internals.api.utils.authentication import get_token
     14 from blah._internals.api.utils.exceptions import BmllError

~/work/blah/blah/_internals/rest.py in <module>
     15 from typing import Dict, Optional, TypedDict
     16

ImportError: cannot import name 'TypedDict' from 'typing' (/home/pchong/anaconda3/lib/python3.7/typing.py)

从最后一行可以清楚地看出,它正在使用Python 3.7。

英文:

I am using a conda environment when I launch jupyter notebook, and my environment has Python 3.8 installed.

However, when I launch the notebook and try to import packages, I get (note the LAST LINE):

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
&lt;ipython-input-7-2b...8b8&gt; in &lt;module&gt;
----&gt; 1 from blah import reference

~/work/blah/blah/__init__.py in &lt;module&gt;
     64 
     65 # Private methods for use here
---&gt; 66 from ._internals.api import configure as _configure
     67 from ._internals.api.utils.warnings import PatchWarning as _PatchWarning
     68 

~/work/blah/blah/_internals/api/configure.py in &lt;module&gt;
     10 from typeguard import typechecked
     11 
---&gt; 12 from blah._internals.rest import user
     13 from blah._internals.api.utils.authentication import get_token
     14 from blah._internals.api.utils.exceptions import BmllError

~/work/blah/blah/_internals/rest.py in &lt;module&gt;
     13 from functools import wraps
     14 from http import HTTPStatus
---&gt; 15 from typing import Dict, Optional, TypedDict
     16 
     17 from requests import request

ImportError: cannot import name &#39;TypedDict&#39; from &#39;typing&#39; (/home/pchong/anaconda3/lib/python3.7/typing.py)

From the last line it is clear that it is using python3.7??

答案1

得分: 1

如果您能看到导入错误路径,它显示为Python 3.7。因此,默认情况下,Jupyter笔记本在您使用conda安装的Python环境中运行。您可以通过创建一个虚拟的conda环境来轻松解决这个问题,使用以下命令:
conda create -n yourenvname python=3.8
然后在该终端中启动Jupyter笔记本。

提示:VS Code可以非常顺利地执行这个操作。

英文:

If you can see the import error path it says python 3.7, So by default the jupyter notebook runs on the python environment you installed using conda, you can easily solve this issue by creating a virtual conda environment using
conda create -n yourenvname python=3.8 and then launch jupyter notebook from that terminal.

Tip: VS code does this very smoothly

答案2

得分: 0

你可以使用所需版本来运行 Jupyter Notebook:

<path_to_python> -m jupyter notebook
英文:

You can run jupyter notebook using desired version by:

&lt;path_to_python&gt; -m jupyter notebook

huangapple
  • 本文由 发表于 2023年3月9日 18:22:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75683267.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定