"module 'torchtext.data' has no attribute 'Field'" - python

import torchtext
ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
Error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-12-2a3d11c77e7d> in <module>
----> 1 ENGLISH = torchtext.data.Field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")
AttributeError: module 'torchtext.data' has no attribute 'Field'
It won't import torchtext.data.Field for some reason even though that's whats in the docs

[BC Breaking] Legacy
In v0.9.0 release, we move the following legacy code to torchtext.legacy. This is part of the work to revamp the torchtext library and the motivation has been discussed in Issue #664:
torchtext.legacy.data.field
torchtext.legacy.data.batch
torchtext.legacy.data.example
torchtext.legacy.data.iterator
torchtext.legacy.data.pipeline
torchtext.legacy.datasets
We have a migration tutorial to help users switch to the torchtext datasets in v0.9.0 release. For the users who still want the legacy components, they can add legacy to the import path.
Try it with ENGLISH = torchtext.legacy.data.field(tokenize=tokenizer_english, lower=True, init_token="<sos>", eos_token="<eos>")

Related

module 'tensorflow' has no attribute 'variable' in google Colaboratory

I'm trying to create a variable tensor in google Collaboratory with this code, but error because TensorFlow doesn't have a module about variables. what's the solution?
import tensorflow as tf
var_1 = tf.variable(tf.ones([2,3]))
Error:
AttributeError Traceback (most recent call last)
<ipython-input-2-2666f49bf801> in <module>()
----> 1 var_1 = tf.variable(tf.ones([2,3]))```
AttributeError: module 'tensorflow' has no attribute 'variable'
There is a typo error. Use capital letter V for Variable.
You can refer below code for the same.
import tensorflow as tf
var_1 = tf.Variable(tf.ones([2,3]))
var_1
Click here, for more details

i am doing webscraping so this error is occuring kindly check this out?

TypeError Traceback (most recent call last) <ipython-input-21-b281566ea133> in <module>
----> 1 desc = soup.findall("td",{"class":"views-field views-field-search-api-excerpt views-field-field-api-description hidden-xs visible-md visible-sm col-md-8"})
TypeError: 'NoneType' object is not callable
You're using beautifulsoup version 3 & it has stopped receiving updates in 2012; it is severely out of date now. I strongly urge you to upgrade:
pip install beautifulsoup4
and
from bs4 import BeautifulSoup
The Element.find_all() method is available in latest major version. Use it instead of Element.findall() and try again.

Importing & using HoltWinters from hardPredictions

I'm stuck on importing a module from hardPredictions. I can find documentation on installing the libraryand using the module module, but not how to import the module.
I've tried the following:
from hardPredictions import HoltWinters
model = HoltWinters()
This gives me an error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-10-72e6928695cf> in <module>
----> 1 model = HoltWinters()
TypeError: 'module' object is not callable
This works, but then I can't pass my ts to the model:
from hardPredictions import HoltWinters
model = HoltWinters
model.fit(ts)
gives an error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-13-f40ff401465a> in <module>
1 model = HoltWinters
----> 2 model.fit(ts)
AttributeError: module 'hardPredictions.HoltWinters' has no attribute 'fit'
I've also tried running help() and dir() on HoltWinters, but think the main thing is I'm lacking the skill to ask the library how to import a model. Your advice is much appreciated!

AttributeError: 'module' object has no attribute 'version' Canopy

Hi I am going to preface this with I could just be really dumb so don't overlook that, but suddenly when opening canopy today I wasn't able to run one of my typical scripts with the error AttributeError: 'module' object has no attribute ' version' when trying to load pandas. From what I can gather it seems when bumpy is called through pandas it fails. I checked my working directory for files named numpy.py to see if I idiotically named a file numpy but failed to find such a file. I also attempted to uninstall and reinstall both numpy and pandas from the package manager in canopy. Any suggestions?
%run "/Users/jim/Documents/ORAL-PAT-2.5-3.5plotly.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/jim/Documents/ORAL-PAT-2.5-3.5plotly.py in <module>()
1 #import the modules you need
----> 2 import pandas as pd
3 import numpy as np
4 import plotly.plotly as py
5 import plotly.tools as tls
/Users/jim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/__init__.py in <module>()
20
21 # numpy compat
---> 22 from pandas.compat.numpy_compat import *
23
24 try:
/Users/jim/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pandas/compat/numpy_compat.py in <module>()
13
14 # numpy versioning
---> 15 _np_version = np.version.short_version
16 _np_version_under1p8 = LooseVersion(_np_version) < '1.8'
17 _np_version_under1p9 = LooseVersion(_np_version) < '1.9'
AttributeError: 'module' object has no attribute 'version'
Just had the same problem after downgrading Pandas and upgrading again to fix another issue. This is just a hack, but you could try this:
Open ...pandas/compat/numpy_compat.py and replace np.version.short_version with np._np_version
Hope that helps!

Importing Classes & Variables in Python 2.7

Hi I'm having trouble importing classes and variables into python files from other python files. Functions work fine.
As a test, I set up file1 with a function, a class, an assigned instance of the class, and a random variable. I then used various methods in file2:
1.
import file1
2.
from file1 import *
error: 'name not defined'
3.
from file1 import variable,class,instance,etc
error: cannot import name Class
4+. And then doing some other things...
creating a init.py file
or then trying to set directory:
import os
os.chdir("/Users/mardersteina/Documents")
Not sure what I'm doing wrong. Function imports fine, but can't figure this one out with the classes and variables no matter what I'm looking up.
Untitled7:
def happy():
print "yo!"
class Tap(object):
def __init__(self,level):
self.level = level
level4 = Tap(4)
x = 14
Untitled9:
%run "/Users/mardersteina/Documents/Untitled9.py"
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Users/mardersteina/Documents/Untitled9.py in <module>()
1 import Untitled7
2
----> 3 print Untitled7.x
4 """
5 from Untitled7 import Tap
AttributeError: 'module' object has no attribute 'x'
%run "/Users/mardersteina/Documents/Untitled9.py"
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/mardersteina/Documents/Untitled9.py in <module>()
4 print Untitled7.x
5 """
----> 6 from Untitled7 import Tap
7
8 print Tap(4).level
ImportError: cannot import name Tap
%run "/Users/mardersteina/Documents/Untitled9.py"
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/Users/mardersteina/Documents/Untitled9.py in <module>()
11 from Untitled7 import *
12
---> 13 print level4.level
NameError: name 'level4' is not defined
I can see that you are running the file from an open console .
Most probably the issue is that you had imported the Untitled7.py previously when it only had one function . When you do that Python caches the module in sys.modules .
So if you try to import it in same session again, you would get the cached version from sys.modules , and that would be the reason any changes to the Untitled7 you did after importing it once are not visible.
To fix this issue, you can reload the module -
In Python 3.x , use importlib.reload() to reload the module (to take in new changes) , Example -
import importlib
importlib.reload(Untitled7)
In Python 2.x , use reload() method -
reload(Untitled7)
Or you can also close the python terminal and reopen it, and it should fix the issue.

Categories

Resources