无法导入名称' soft_unicode'从markupsafe'在Google Colab中
我正在尝试在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是由 upgrade 在markupsafe:2.1.0中soft_unicode,尝试使用:
This is caused by upgrade in MarkupSafe:2.1.0 where they have removed soft_unicode, try using:
你能尝试一下吗?这将安装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.
我做了以下操作来解决相同的问题:
以便我可以使用最新版本。我还必须使用相同类型的命令更新Jinja2。
I did the following to solve the same issue:
so that I can use the latest version. I also had to update jinja2 with the same type of command.
您的问题的根本原因可能源于两个软件生态系统之间的依赖关系管理冲突。根据错误消息,您的标记安全是在路径
/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路径导入标记保护。一个例子如下:希望我的诊断对您有帮助!
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:Hope my diagnosis is helpful to you!
尝试以下操作:
Try this: