Cannot import name 'soft_unicode' from 'markupsafe' in google colab - python

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)

This is caused by upgrade in MarkupSafe:2.1.0 where they have removed soft_unicode, try using:
pip install markupsafe==2.0.1

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

Related

Import Spacy Error "cannot import name dataclass_transform"

I am working on a jupyter notebook project which should use spacy. I already used pip install to install spacy in anaconda prompt.
However, when I tried to import spacy, it gives me the follwing error.
I wonder what the problem is and what I can do to solve that.
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-96-3173a3034708> in <module>
9 #nltk.download()
10 from nltk.corpus import stopwords
---> 11 import spacy
12
13 #path where we store the txt files
D:\Python\lib\site-packages\spacy\__init__.py in <module>
4
5 # set library-specific custom warning handling before doing anything else
----> 6 from .errors import setup_default_warnings
7
8 setup_default_warnings() # noqa: E402
D:\Python\lib\site-packages\spacy\errors.py in <module>
1 import warnings
----> 2 from .compat import Literal
3
4
5 class ErrorsWithCodes(type):
D:\Python\lib\site-packages\spacy\compat.py in <module>
1 """Helpers for Python and platform compatibility."""
2 import sys
----> 3 from thinc.util import copy_array
4
5 try:
D:\Python\lib\site-packages\thinc\util.py in <module>
6 import functools
7 from wasabi import table
----> 8 from pydantic import create_model, ValidationError
9 import inspect
10 import os
D:\Python\lib\site-packages\pydantic\__init__.cp38-win_amd64.pyd in init pydantic.__init__()
D:\Python\lib\site-packages\pydantic\dataclasses.cp38-win_amd64.pyd in init pydantic.dataclasses()
ImportError: cannot import name dataclass_transform
You can try following codes:
pip install -U pip setuptools wheel
pip install -U spacy
python -m spacy download en_core_web_sm
After installation restart the kernal if you are using Jupyter notebook or lab.
It does works for my end.
I am using Windows with Anaconda virtual environment. Uninstalling spacy from pip and installing it from conda did the job for me.
pip uninstall spacy
conda install spacy
python -m spacy download en_core_web_sm --user

Attribute error when trying to import Spacy

I have some issues when I try to import spacy. I downloaded the package and have the newest version, but still I get this error and I cannot find any answer. Maybe someone here had this problem and can help me out here.
This is the error when I do "import spacy":
AttributeError Traceback (most recent call last)
in ()
----> 1 import spacy
~\Anaconda3\lib\site-packages\spacy_init_.py in ()
8
9 # These are imported as part of the API
---> 10 from thinc.neural.util import prefer_gpu, require_gpu
11
12 from . import pipeline
~\Anaconda3\lib\site-packages\thinc_init_.py in ()
6
7 from .about import name, version # noqa: F401
----> 8 from ._registry import registry
~\Anaconda3\lib\site-packages\thinc_registry.py in ()
----> 1 import catalogue
2
3
4 class registry(object):
5 optimizers = catalogue.create("thinc", "optimizers", entry_points=True)
~\Anaconda3\lib\site-packages\catalogue.py in ()
16
17 # Only ever call this once for performance reasons
---> 18 AVAILABLE_ENTRY_POINTS = importlib_metadata.entry_points()
19
20 # This is where functions will be registered
AttributeError: module 'importlib_metadata' has no attribute 'entry_points'
Thanks in advance!
It's just a problem with your metadata package. Try this since you are using conda environments:
conda install -c conda-forge importlib_metadata
If you prefer pip, you can do
pip uninstall importlib_metadata
pip install importlib_metadata --force-reinstall

ImportError when installing Colorama

I installed Colorama into Google Colab.
When I tried to import it, it shows ImportError:
import colorama
ImportError Traceback (most recent call last)
<ipython-input-33-88ec09736251> in <module>()
----> 1 import colorama
2 frames
/usr/local/lib/python3.6/dist-packages/colorama/ansitowin32.py in <module>()
4 import os
5
----> 6 from .ansi import AnsiFore, AnsiBack, AnsiStyle, Style, BEL
7 from .winterm import WinTerm, WinColor, WinStyle
8 from .win32 import windll, winapi_test
ImportError: cannot import name 'BEL'
---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.
To view examples of installing some common dependencies, click the
"Open Examples" button below.
How can I get rid from this problem?
Do..
pip install colorama
and its work.

ModuleNotFoundError: No module named 'mglearn'

This is a commmon question, but nothing worked for me so far.
I have seen this answer too Python 3 on Mac : ModuleNotFoundError: No module named 'mglearn'
!pip install mglearn
!pip install sklearn
!pip install -U scikit-learn
import mglearn
import sklearn
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-fe22f30497b9> in <module>
----> 1 import mglearn
2 import sklearn
ModuleNotFoundError: No module named 'mglearn'
I checked other questions but failed to solve it. I have macOS Catalina 10.15.7
import sys
!{sys.executable} -m pip install mglearn
Try using this. This assures that you are using the pip version associated with the environment.

torchtext ImportError in colab

I am trying to run this tutorial in colab.
However, when I try to import a bunch of modules:
import io
import torch
from torchtext.utils import download_from_url
from torchtext.data.utils import get_tokenizer
from torchtext.vocab import build_vocab_from_iterator
It gives me the errors for extract_archive and build_vocab_from_iterator:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-a24e72502dbc> in <module>()
1 import io
2 import torch
----> 3 from torchtext.utils import download_from_url, extract_archive
4 from torchtext.data.utils import get_tokenizer
5 from torchtext.vocab import build_vocab_from_iterator
ImportError: cannot import name 'extract_archive'
ImportError Traceback (most recent call last)
<ipython-input-4-02a401fd241b> in <module>()
3 from torchtext.utils import download_from_url
4 from torchtext.data.utils import get_tokenizer
----> 5 from torchtext.vocab import build_vocab_from_iterator
6
7 url = 'https://s3.amazonaws.com/research.metamind.io/wikitext/wikitext-2-v1.zip'
ImportError: cannot import name 'build_vocab_from_iterator'
Please help me with this one.
You need to upgrade torchtext first
!pip install -U torchtext==0.8.0
Currently, version 0.8.0 works with torch 1.7.0 (no need to upgrade torch, torchvision)
Update (sep 2021)
Currently, torchtext is already 0.10.0 and you don't need to upgrade anything.
Update December 2021
!pip install -U torchtext==0.10.0
torchtext.data becomes torchtext.legacy.data
use:
from torchtext.legacy.data import Field, TabularDataset, BucketIterator, Iterator
credit
You can use:
pip install -U torchtext==0.6.0
if 0.8 version is not available
This might help solve your problem:
conda install -c pytorch torchtext==0.8

Categories