Jupyter Notebook 导入 nbinteract 时出现导入错误。

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

Jupyter Notebook Import Error when importing nbinteract

问题

这是导入库时遇到的错误,看起来与系统有关,尤其是因为您正在使用M1-MacBook。错误信息显示无法从'base64'导入'name',您可以尝试以下方法来解决问题:

  1. 检查Python版本:确保您正在使用的Python版本与nbinteract和其他库兼容。有时,库可能不适用于某些Python版本。

  2. 更新库:使用命令pip install --upgrade nbinteract来更新nbinteract库,以确保您使用的是最新版本。

  3. 检查依赖项:确保所有库的依赖项也已安装。您可以使用pip list来查看已安装的库和版本。

  4. 检查Python环境:如果您使用了虚拟环境,请确保您的Jupyter Notebook在正确的虚拟环境中运行。

  5. 检查系统路径:有时,系统路径配置可能会导致导入问题。确保您的Python解释器可以找到所需的库。

尝试这些步骤中的一个或多个,看看是否可以解决您遇到的问题。

英文:

I am importing libraries inside jupyter notebook, when I face an awkward error. Could you please tell me how I could fix it?
It seems the problem has something to do with the system, and I am using a M1-MacBook.
Here is the import:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
%matplotlib inline
import ipywidgets as widgets
from ipywidgets import interact, interactive, fixed, interact_manual
import nbinteract as nbi

sns.set()
sns.set_context('talk')
np.set_printoptions(threshold=20, precision=2, suppress=True)
pd.set_option('display.max_rows', 7)
pd.set_option('display.max_columns', 8)
pd.set_option('precision', 2)
# This option stops scientific notation for pandas
# pd.set_option('display.float_format', '{:.2f}'.format)

Here is the error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/var/folders/h3/kst79dg57g18qj470505fpq40000gn/T/ipykernel_6876/3125672849.py in ()
     14 import ipywidgets as widgets
     15 from ipywidgets import interact, interactive, fixed, interact_manual
---> 16 import nbinteract as nbi
     17 
     18 sns.set()

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nbinteract/__init__.py in 
     10 warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
     11 
---> 12 from .exporters import *
     13 from .plotting import *
     14 from .questions import *

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nbinteract/exporters.py in 
     24 from IPython.display import display, Javascript, Markdown
     25 
---> 26 from nbconvert import HTMLExporter
     27 from traitlets import default, Unicode, Bool, validate, TraitError
     28 

/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/nbconvert/__init__.py in 
      2 
...
---> 19 from base64 import encodestring
     20 from .rwbase import NotebookReader, NotebookWriter
     21 from .nbbase import from_dict

ImportError: cannot import name 'encodestring' from 'base64' (/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/base64.py)

Try to fix the problem.

答案1

得分: 1

这是nbinteract的已知问题,因为它不支持最新的Python版本,您正在使用的是Python 3.11,这是相当新的版本。

您可以查看此链接ImportError: cannot import name encodestring from base64,因为其他人在Python 3.9中也遇到了此问题。

您还可以在pypi: nbinteract中查看,此包支持到Python 3.5

我的建议是将Python版本降低到3.5,或者您也可以考虑以下替代方案:

这些库官方支持最新版本,直到Python 3.10

英文:

This is a known issue of nbinteract because it doesnot have support with latest python version, as you are using pyhton 3.11 which is quite latest.

You can go through this link ImportError: cannot import name encodestring from base64 as others are also facing this issue even in pyhton 3.9

You can also see here pypi: nbinteract this package have support till python 3.5

My suggestion is lower your python version to 3.5 or you can also look an alternative

These libs have support with latest versions officially till python 3.10

huangapple
  • 本文由 发表于 2023年6月12日 19:30:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76456239.html
匿名

发表评论

匿名网友

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

确定