torchtext ImportError in colab - python

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

Related

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.

Import Error: Problem with importing from Python Package

import audiolabel
import numpy as np
from ultramisc import ebutils as eb
from audiolabel import LabelManager
ImportError Traceback (most recent call last)
<ipython-input-38-2387500242d1> in <module>
4
5 from ultramisc import ebutils as eb
----> 6 from audiolabel import LabelManager
ImportError: cannot import name 'LabelManager' from 'audiolabel' (unknown location)
In [39]:
I'm trying to import LabelManager from the audiolabel package I got using git clone but for some reason there is no way to import LabelManager? I'm not sure why this is the case, because from all the documentation I've seen from audiolabel, they are able to import LabelManager
This error could be caused by multiple reasons...
Have you tried downloading via pip install ?
pip3 install "git+https://github.com/rsprouse/audiolabel.git"

How to install python package 'rpy2' in Databricks?

I am trying to install and utilize pymer4 package functionalities in Databricks which requires rpy2 to be installed as well. Under Library in the Cluster I am able to install them, it even says "Installed", but when I try to import them then it gives error, as if it was not installed properly. In local system it works perfectly.
from pymer4.test_install import test_install
Error is:
ImportError: No module named 'pandas.core.dtypes'
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<command-2946392196605768> in <module>()
----> 1 from pymer4.test_install import test_install
/databricks/python/lib/python3.5/site-packages/pymer4/__init__.py in <module>()
6 "__version__"]
7
----> 8 from .models import Lmer, Lm
9 from .simulate import (easy_multivariate_normal,
10 simulate_lm,
/databricks/python/lib/python3.5/site-packages/pymer4/models.py in <module>()
2 import rpy2.robjects as robjects
3 from rpy2.robjects.packages import importr
----> 4 from rpy2.robjects import pandas2ri
5 import rpy2
6 from copy import copy
/databricks/python/lib/python3.5/site-packages/rpy2/robjects/pandas2ri.py in <module>()
14 from pandas.core.series import Series as PandasSeries
15 from pandas.core.index import Index as PandasIndex
---> 16 from pandas.core.dtypes.api import is_datetime64_any_dtype
17 import pandas
18 import numpy
ImportError: No module named 'pandas.core.dtypes'
Was able to solve my own problem. It was nothing but version issues of dependent packages of pymer4 package.
Changed the version of following packages with the latest one prior to release date of pymer4 and it worked:
matplotlib==3.0.2
pandas==0.23.4
rpy2==2.9.4
tzlocal

Fuel Dataset Import Error

When i am importing fuel.datasets.hdf5. I am getting below error. Does anyone know the solution?
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-23-9cbd4ef5a9e4> in <module>()
----> 1 from fuel.datasets.hdf5 import H5PYDataset
2 from fuel.schemes import ShuffledScheme, SequentialScheme
3 from fuel.streams import DataStream
ModuleNotFoundError: No module named 'fuel.datasets'
try this
sudo apt-get install libhdf5
sudo pip install h5py
and then import module
1. import h5py
2. from fuel.datasets.hdf5 import H5PYDataset
3. from fuel.schemes import ShuffledScheme, SequentialScheme
4. from fuel.streams import DataStream

Why can't I import folium python package?

I've pip installed folium and get this error when I try to import it in when Im working in my home directory:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-af6e4f19ef00> in <module>()
----> 1 import folium
//anaconda/lib/python2.7/site-packages/folium-0.3.0.dev0- py2.7.egg/folium/__init__.py in <module>()
3 from __future__ import absolute_import
4
----> 5 from folium.folium import Map, initialize_notebook, CircleMarker
6
7 from folium.map import (FeatureGroup, FitBounds, Icon, LayerControl, Marker,
//anaconda/lib/python2.7/site-packages/folium-0.3.0.dev0- py2.7.egg/folium/folium.py in <module>()
13 import json
14
---> 15 from branca.colormap import StepColormap
16 from branca.utilities import color_brewer
17 from branca.six import text_type, binary_type
ImportError: No module named branca.colormap
However, i can import it when I cd to /Library/Python/2.7/site-packages.... What gives?
Did you install the package with Anaconda? It looks like it's reading the package from Anaconda python's package install locations. A few things to try:
conda install branca
pip install branca

Categories