ValueError with nltk on python 3.6 Windows - windows

Tried to run
wordnet.synsets('table')
from Python 3.6 on Windows and got
File "<stdin>", line 1, in <module>
File "C:\Users\Leti\Anaconda3\envs\DeepVis\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1424, in synsets
for p in pos
File "C:\Users\Leti\Anaconda3\envs\DeepVis\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1426, in <listcomp>
for offset in index[form].get(p, [])]
File "C:\Users\Leti\Anaconda3\envs\DeepVis\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1280, in _synset_from_pos_and_offset
synset = self._synset_from_pos_and_line(pos, data_file_line)
File "C:\Users\Leti\Anaconda3\envs\DeepVis\lib\site-packages\nltk\corpus\reader\wordnet.py", line 1381, in _synset_from_pos_and_line
raise WordNetError('line %r: %s' % (data_file_line, e))
nltk.corpus.reader.wordnet.WordNetError: line 'tted dalmatian \r\n': not enough values to unpack (expected 2, got 1)
On Linux it works just fine!
Does someone know what is happening?

try to convert file nltk_data\corpora\wordnet\data.noun format to Unix by tools like UltraEdit or notepad++ (Edit-->EOL Conversion-->Unix(LF))

Related

Sentiment anaysis using Harvard IV-4 dictionary

I was trying to compute the sentiment using Harvard IV-4dictionary.
I installed the "pysentiment" successfully.
I run the following:
import pysentiment as ps
hiv4 = ps.HIV4()
tokens = hiv4.tokenize(text)
score = hiv4.get_score(tokens)
and I got the following error:
Traceback (most recent call last):
File "C:/Users/df/Desk Top/Finalazed/punctuation.py", line 274, in <module>
hiv4 = ps.HIV4()
File "C:\Users\df\AppData\Local\Programs\Python\Python37\lib\site-packages\pysentiment\base.py", line 55, in __init__
self._tokenizer = Tokenizer()
File "C:\Users\df\AppData\Local\Programs\Python\Python37\lib\site-packages\pysentiment\utils.py", line 36, in __init__
self._stopset = self.get_stopset()
File "C:\Users\df\AppData\Local\Programs\Python\Python37\lib\site-packages\pysentiment\utils.py", line 52, in get_stopset
fin = open('%s/%s'%(STATIC_PATH, f), 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\df\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\pysentiment\\static/Currencies.txt'
Could any body tell why I am getting this? Thanks.
Do copy pysentiment folder in the given path. Actually pysentiment folder doesnt contain static sub folder. You can check it by diplaying hidden folder "local".

FileNotFoundError: No such file: 'someones_epi.nii.gzip'

I am trying to load an MRI, I keep getting the following error:
Traceback (most recent call last):
File "F:/Study/Projects/BTSaG/Programs/t3.py", line 2, in <module> epi_img = nib.load('someones_epi.nii.gzip')
File "C:\Users\AnkitaShinde\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nibabel\loadsave.py", line 38, in load raise FileNotFoundError("No such file: '%s'" % filename)
FileNotFoundError: No such file: 'someones_epi.nii.gzip'
The code is used is as follows:
import nibabel as nib
epi_img = nib.load('someones_epi.nii.gzip')
epi_img_data = epi_img.get_data()
epi_img_data.shape(53, 61, 33)
import matplotlib.pyplot as plt
def show_slices(slices):
""" Function to display row of image slices """
fig, axes = plt.subplots(1, len(slices))
for i, slice in enumerate(slices):
axes[i].imshow(slice.T, cmap="gray", origin="lower")
slice_0 = epi_img_data[26, :, :]
slice_1 = epi_img_data[:, 30, :]
slice_2 = epi_img_data[:, :, 16]
show_slices([slice_0, slice_1, slice_2])
plt.suptitle("Center slices for EPI image")
I have also updated the loadsave.py file in nibabel but it didn't work. Please help.
Edit:
The earlier error was resolved. Now another error has been encountered.
Traceback (most recent call last):File "F:\Study\Projects\BTSaG\Programs\t3.py", line 2, in <module> epi_img = nib.load('someones_epi.nii.gzip')
File "C:\Users\AnkitaShinde\AppData\Local\Programs\Python\Python35-32\lib\site-packages\nibabel\loadsave.py", line 47, in load filename)
nibabel.filebasedimages.ImageFileError: Cannot work out file type of "someones_epi.nii.gzip"
This is an old question, however I may have the solution for it.
I just figured out that nibabel.save() does not allow me to have dot . or dash - in the folder names. These can exist in filenames however. In your case, the current path is:
C:\Users\AnkitaShinde\AppData\Local\Programs\Python\Python35-32\Lib\site-packages\nibabel\someones_epi.nii.gzip
I would change it to:
C:\Users\AnkitaShinde\AppData\Local\Programs\Python\Python35_32\Lib\site_packages\nibabel\someones_epi.nii.gzip
This is just to give an example. Of course, I don't mean that you actually change the names of these package folders as it might cause other errors.
The actual solution would be to move the file someones_epi.nii.gzip to the user structure, something like:
C:\Users\AnkitaShinde\Desktop\nibabel\someones_epi.nii.gzip

how do I set a turtle to an image

I am trying to set my image to a file, but when i run it i get
Exception in Tkinter callback Traceback (most recent call last):
File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 1699, in call
return self.func(*args) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 686, in eventfun
fun() File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\RPG.py",
line 20, in up
combat() File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\RPG.py",
line 57, in combat
enemy.shape(image) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 2777, in shape
self.turtle._setshape(name) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 2506, in _setshape
self._item = screen._createimage(screen._shapes["blank"]._data) File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\turtle.py",
line 723, in _createimage
return self.cv.create_image(0, 0, image=image) File "", line 1, in create_image File
"C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 2483, in create_image
return self._create('image', args, kw) File "C:\Users\Travi\AppData\Local\Programs\Python\Python36-32\lib\tkinter__init__.py",
line 2474, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: image "pyimage1" doesn't exist
when I have the file name clearly stated exactly where it is on my pc.
the code
import os
from turtle import Turtle,Screen
print(os.getcwd())
os.chdir('C:\\Users\\Travi\\Downloads')
screen.register_shape("Crawfish_attack.gif")
turtle = Turtle()
turtle.setimage("Crawfish_attack.gif")
thanks in advance
BTW the link is here
and the rest of the code all works and is not needed to be shown
Remove "\\Crawfish_attack" from the os.chdir() arguments. You need to path to the folder it is in, not the file. That is what the register_shape function will do is pull the exact file in that folder.
You were getting the error because you were trying to path to something (it was looking for a folder) that does not exist.
import os
from turtle import Turtle,Screen
print(os.getcwd())
os.chdir('C:\\Users\\Travi\\Downloads')
screen.register_shape("Crawfish_attack.gif")

openshift-ansible fails since 2 days with No module named OpenSSL.crypto

since doing the latest pull after the 1.07 release to the ansible github repository, it seems to be failing during the install phase.
example:
ansible-playbook playbooks/byo/config.yml
returns with:
Traceback (most recent call last):
File "/bin/ansible-playbook", line 324, in <module>
sys.exit(main(sys.argv[1:]))
File "/bin/ansible-playbook", line 264, in main
pb.run()
File "/usr/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 310, in run
play = Play(self, play_ds, play_basedir, vault_password=self.vault_password)
File "/usr/lib/python2.7/site-packages/ansible/playbook/play.py", line 124, in __init__
ds = template(basedir, ds, temp_vars)
File "/usr/lib/python2.7/site-packages/ansible/utils/template.py", line 140, in template
d[k] = template(basedir, v, templatevars, lookup_fatal, depth, expand_lists, convert_bare, fail_on_undefined, filter_fatal)
File "/usr/lib/python2.7/site-packages/ansible/utils/template.py", line 140, in template
d[k] = template(basedir, v, templatevars, lookup_fatal, depth, expand_lists, convert_bare, fail_on_undefined, filter_fatal)
File "/usr/lib/python2.7/site-packages/ansible/utils/template.py", line 124, in template
varname = template_from_string(basedir, varname, templatevars, fail_on_undefined)
File "/usr/lib/python2.7/site-packages/ansible/utils/template.py", line 346, in template_from_string
environment.filters.update(_get_filters())
File "/usr/lib/python2.7/site-packages/ansible/utils/template.py", line 54, in _get_filters
plugins = [ x for x in utils.plugins.filter_loader.all()]
File "/usr/lib/python2.7/site-packages/ansible/utils/plugins.py", line 232, in all
self._module_cache[path] = imp.load_source('.'.join([self.package, name]), path)
File "/root/cluster/openshift-ansible/filter_plugins/oo_filters.py", line 10, in <module>
import OpenSSL.crypto
ImportError: No module named OpenSSL.crypto
This was working fine a couple of days ago, before the pull so I have the feeling something in the repository caused this change.
Any ideas?
thx
Reason for this error, that apparently since a couple of days ansible-openshift depends on another additional module, which was not listed in the requirements or is not installed automatically.
executing:
yum install -y pyOpenSSL
seems to fix this issue for now.
Or you can try pip install pyopenssl

Can't install anything with pip2 on Windows 7 due to UnicodeDecodeError

I'm trying to install Django (with another package the error is the same) for Python 2.7.10/Windows 7 with pip, and getting this strange error
Command is
pip install django
Sorry, but I can't write an entire log because of dumb Windows console. Here is the second part of log.
File "C:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\resp
onse.py", line 307, in stream
data = self.read(amt=amt, decode_content=decode_content)
File "C:\Python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\resp
onse.py", line 243, in read
data = self._fp.read(amt)
File "C:\Python27\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py",
line 54, in read
self.__callback(self.__buf.getvalue())
File "C:\Python27\lib\site-packages\pip\_vendor\cachecontrol\controller.py", l
ine 244, in cache_response
self.serializer.dumps(request, response, body=body),
File "C:\Python27\lib\site-packages\pip\download.py", line 276, in set
return super(SafeFileCache, self).set(*args, **kwargs)
File "C:\Python27\lib\site-packages\pip\_vendor\cachecontrol\caches\file_cache
.py", line 99, in set
with self.lock_class(name) as lock:
File "C:\Python27\lib\site-packages\pip\_vendor\lockfile\mkdirlockfile.py", li
ne 18, in __init__
LockBase.__init__(self, path, threaded, timeout)
File "C:\Python27\lib\site-packages\pip\_vendor\lockfile\__init__.py", line 18
9, in __init__
hash(self.path)))
File "C:\Python27\lib\ntpath.py", line 85, in join
result_path = result_path + p_path
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 0: ordinal not in range(128)
May be it's because of cyrillic username that runs the system. Is there a way to fix it without creating a new user?
Or maybe there is some bad thing that I missed?

Resources