无法导入名称' soft_unicode'从markupsafe'在Google Colab中

发布于 2025-02-06 14:30:28 字数 686 浏览 2 评论 0原文

我正在尝试在Google Colab中安装pycaret == 3.0.0,但是我有问题,库需要安装jinja2,但我终于丢下了另一个错误。

ImportError                               Traceback (most recent call last)
<ipython-input-26-4f8843d24b3a> in <module>()
----> 1 import jinja2
      2 from pycaret.regression import *

3 frames
/usr/local/lib/python3.7/dist-packages/jinja2/filters.py in <module>()
     11 from markupsafe import escape
     12 from markupsafe import Markup
---> 13 from markupsafe import soft_unicode
     14 
     15 from ._compat import abc

ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/root/.local/lib/python3.7/site-packages/markupsafe/__init__.py)

I'm trying to install pycaret==3.0.0 in google colab, But I'm having a problem, the library requires Jinja2 to be installed which I did, but then It finally throws off another error.

ImportError                               Traceback (most recent call last)
<ipython-input-26-4f8843d24b3a> in <module>()
----> 1 import jinja2
      2 from pycaret.regression import *

3 frames
/usr/local/lib/python3.7/dist-packages/jinja2/filters.py in <module>()
     11 from markupsafe import escape
     12 from markupsafe import Markup
---> 13 from markupsafe import soft_unicode
     14 
     15 from ._compat import abc

ImportError: cannot import name 'soft_unicode' from 'markupsafe' (/root/.local/lib/python3.7/site-packages/markupsafe/__init__.py)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

記憶穿過時間隧道 2025-02-13 14:30:28

这是由 upgrade 在markupsafe:2.1.0中soft_unicode,尝试使用:

pip install markupsafe==2.0.1

This is caused by upgrade in MarkupSafe:2.1.0 where they have removed soft_unicode, try using:

pip install markupsafe==2.0.1
时光病人 2025-02-13 14:30:28

你能尝试一下吗?这将安装Pycaret的最新版本,并应为您照顾所有依赖。请记住,安装后重新启动内核,以使安装正确生效。

pip install -U --pre pycaret

Can you try this. This will install the latest release of pycaret and should take care of all dependencies for you. Just remember to restart the kernel after installation for the install to take effect correctly.

pip install -U --pre pycaret
你的笑 2025-02-13 14:30:28

我做了以下操作来解决相同的问题:

pip install -U markupsafe

以便我可以使用最新版本。我还必须使用相同类型的命令更新Jinja2。

I did the following to solve the same issue:

pip install -U markupsafe

so that I can use the latest version. I also had to update jinja2 with the same type of command.

好听的两个字的网名 2025-02-13 14:30:28

您的问题的根本原因可能源于两个软件生态系统之间的依赖关系管理冲突。根据错误消息,您的标记安全是在路径/root/.local/lib/python3.7/site-packages/markupsafe/上使用PIP安装的。依赖于它的jinja2是使用apt在路径上安装的/usr/local/lib/python3.7/dist-packages/jinja2。两者的版本不兼容。实际上,系统中有一个版本的markupsafe正确取决于jinja2,但是Python解释器优先考虑PIP安装的标记保护,从而导致了这个问题。这个问题通常有两个解决方案:(1)使用PIP卸载MarkupSafe,然后使用APT重新安装它,或使用APT卸载Jinja2,然后使用PIP重新安装它。 (2)使用Python的IMP模块自定义路径并在导入Jinja2之前从APT路径导入标记保护。一个例子如下:

import imp
path = ['/usr/local/lib/python3.7/dist-packages']
fp, pathname, description = imp.find_module('markupsafe', path)
imp.load_module("markupsafe", fp, pathname, description)

希望我的诊断对您有帮助!

The root cause with your question may stem from a dependency management conflict between two software ecosystems. According to the error message, your markupsafe was installed using pip at the path /root/.local/lib/python3.7/site-packages/markupsafe/. The jinja2 that depends on it was installed using apt at the path /usr/local/lib/python3.7/dist-packages/jinja2. The versions of the two are not compatible. In fact, there is a version of markupsafe in the system that jinja2 correctly depends on, but the Python interpreter prioritizes the markupsafe installed by pip, leading to this issue. There are typically two solutions to this problem: (1) Use pip to uninstall markupsafe, and then reinstall it using apt, or uninstall jinja2 using apt and reinstall it using pip. (2) Use Python's imp module to customize the path and import the markupsafe from the apt path before importing jinja2. An example is as follows:

import imp
path = ['/usr/local/lib/python3.7/dist-packages']
fp, pathname, description = imp.find_module('markupsafe', path)
imp.load_module("markupsafe", fp, pathname, description)

Hope my diagnosis is helpful to you!

天涯离梦残月幽梦 2025-02-13 14:30:28

尝试以下操作:

pip install markupsafe==2.1.1
conda update jupyter

Try this:

pip install markupsafe==2.1.1
conda update jupyter
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文