AttributeError: module 'sst' has no attribute 'train_reader' - python

I am very new to sentiment analysis. Trying to use Stanford Sentiment Treebank(sst) and ran into an error.
from nltk.tree import Tree
import os
import sst
trees = "C:\\Users\m\data\trees"
tree, score = next(sst.train_reader(trees))
[Output]:
AttributeError Traceback (most recent call last)
<ipython-input-19-4101f90b0b16> in <module>()
----> 1 tree, score = next(sst.train_reader(trees))
AttributeError: module 'sst' has no attribute 'train_reader'

I think you're looking for https://github.com/JonathanRaiman/pytreebank, not https://pypi.org/project/sst/.
On the python side, that error is pretty clear. Once you import the right package, though, I'm not sure I saw train_reader but I could be wrong.
UPDATE:
I'm not entirely sure why you're running into the 'sst' not having the attribute train_reader. Make sure you didn't accidentally install the 'sst' package if you're using conda. It looks like the 'sst' is referring to a privately created module and that one should work.
I got your import working but what I did was I:
Installed everything specified in the requirements.txt file.
import sst was still giving me an error so I installed nltk and sklearn to resolve that issue. (fyi, im not using conda. im just using pip and virtualenv for my own private package settings. i ran pip install nltk and pip install sklearn)
At this point, import sst worked for me.

I guess you're importing the sst package selenium-simple-test, which is not what you're looking for.
Try sst.discover() , if you get the error
TypeError: discover() missing 4 required positional arguments: 'test_loader', 'package', 'dir_path', and 'names'
You are using the selenium-simple-test package

Related

AttributeError: module 'preprocessor' has no attribute 'clean'

I am trying to use the preprocessor library in order to clean text stored in a Pandas Data Frame. I've installed the last version (https://pypi.org/project/tweet-preprocessor/), but I receive this error message:
import preprocessor as p
#forming a separate feature for cleaned tweets
for i,v in enumerate(df['text']):
df.loc[v,'text'] = p.clean(i)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-183-94e08e1aff33> in <module>
1 #forming a separate feature for cleaned tweets
2 for i,v in enumerate(df['text']):
----> 3 df.loc[v,'text'] = p.clean(i)
AttributeError: module 'preprocessor' has no attribute 'clean'
You probably have the preprocessor module installed as well, which is entirely distinct from the tweet-preprocessor module. However, confusingly, the import preprocessor as p statement can be used for both. When both modules are installed, Python ignores tweet-preprocessor and automatically opts for preprocessor, which does not contain a clean function, hence the error you received.
To resolve this, I had to uninstall both modules with the following commands:
pip uninstall preprocessor
pip uninstall tweet-preprocessor
Then I closed all shells for a fresh start and typed:
pip install tweet-preprocessor
And finally:
>>> import preprocessor as p
>>> p.clean('#this and that')
'and that'
Merely uninstalling preprocessor did not work. Python kept importing the module despite it being uninstalled. I am not sure why, but I suspect it has something to do with caches that Python keeps in the background.
Try installing first:
pip install tweet-preprocessor
Then:
import preprocessor as p

AttributeError: module 'cupy' has no attribute 'cupyx'

I have this python code when I run it ,it say
AttributeError: module 'cupy' has no attribute 'cupyx'
code:
# upload matrix and inverse diagonal GPU
A = cp.cupyx.scipy.sparse.csr_matrix(A)
I've installed cupy successfully in docker using
pip install cupy-cuda100
any help will be appreciated, thx
See the discussion in https://github.com/cupy/cupy/issues/2654 and try the following
import cupyx.scipy.sparse
cupyx.scipy.sparse.csr_matrix(A)
The alias cupy.cupyx was unintentionally there in some prereleases, but it has been removed because it is too confusing.

AttributeError: module 'IPython.core' has no attribute 'shadowns'

I'm running these lines
import dill
dill.load_session("session2.pkl")
and getting the error AttributeError: module 'IPython.core' has no attribute 'shadowns'.
I've saved this session on Google Colab Notebooks. How can I get rid of the error?
I used the simple workaround:
import IPython
IPython.core.shadowns = 1
For some extra packages missing like google or google.colab, I used
%%bash
mkdir google/colab
touch google/colab/__init__.py

AttributeError: module 'shodan' has no attribute 'Shodan'

I need to perform a BULK whois query using shodan API.
I came across this code
import shodan
api = shodan.Shodan('inserted my API-KEY- within single quotes')
info = api.host('8.8.8.8')
After running the module i get the following error:
Traceback (most recent call last):
File "C:/Users/PIPY/AppData/Local/Programs/Python/Python37/dam.py", line 1, in
import shodan
File "C:/Users/PIPY/AppData/Local/Programs/Python/Python37\shodan.py", line 2, in
api = shodan.Shodan('the above insereted API KEY')
AttributeError: module 'shodan' has no attribute 'Shodan'
I'm learning python and have limited scripting/programming experience.
Could you please help me out?
Cheers
You seem to have dam.py and shodan.py – Python defaults to importing from the module directory, so the installed shodan package gets masked.
Try renaming shodan.py to e.g. shodan_test.py (and of course fixing up any imports, etc.).
I have solved the issue by re-installing the shodan module under the C:\Users\PIPY\AppData\Local\Programs\Python\Python37\Scripts>pip install shodan
Thank you for the help AKX.
I had this same issue but after renaming my file as something different than shodan.py, I had to also delete the compiled class shodan.pyc to avoid the error.
Also, if you have more than one version of python installed, i.e. python2 and python3, use
python -m pip install shodan instead of pip install shodan, to ensure that you are installing the library in the same version of shodan that you are using to execute your script.
If you are executing your script with python3 shodan_test.py then use python3 -m pip install shodan

Package import from script raises “AttributeError: module has no attribute”

My goal is to acquire image from an Allied Vision camera thanks to Python (Anaconda 3.7). For that I tried to use the "Pymba" package but I get the error : “AttributeError: module has no attribute”.
I looked in the previous posts but I didn't find any working solution. I put below some of my tests.
Here is my code :
import pymba
with pymba.Vimba() as vimba:
print (vimba.getVersion())
system = vimba.getSystem()
The precise error :
File "<ipython-input-2-ff80570a1f3d>", line 3, in <module>
print (vimba.getVersion())
AttributeError: 'Vimba' object has no attribute 'getVersion'
And here are some informations that could be usefull about my research to solve this problem:
I checked if the package was correctly installed.
from pymba import Vimba, PYMBA_VERSION
print(PYMBA_VERSION)
print(Vimba.version())
0.3.2
1.7.0
Despite the fact that I don't have any other file named "Pymba", I checked what file was imported:
print(pymba.__file__)
C:\Users\agricultu\Anaconda3\lib\site-packages\pymba\__init__.py
I don't have either a previous file named "getVersion" and I get the same error for every other function of the package anyway.
I'm running out of ideas and I hope one of you will be able to help me.

Categories