I am having trouble reading RData using pyreadr - python

I have installed pyreadr and would like to use it to read .RData. I have followed the direction given from the previous comment on here Loading RData but that did not work for me.
When I try the following line (with the path pointing to the right file):
result = pyreadr.read_r('/path/to/file.RData')
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/apps/bioapps/python/Python-3.6.1/lib/python3.6/site-packages/pyreadr/pyreadr.py",
line 80, in list_objects
parser.parse(path)
File "pyreadr/librdata.pyx", line 117, in pyreadr.librdata.Parser.parse
File "pyreadr/librdata.pyx", line 142, in pyreadr.librdata.Parser.parse
pyreadr.custom_errors.LibrdataError: Unable to read from file
Please let me know if you have any suggestions.
Thanks!

Related

error creating nbt file that includes nbt.tag.List file

I am creating a nbt file whose root has two tags:
DataVersion. It must be a tag_Int.
size. You must set a tag_List of 3 tag_ints.
I did a few tests and determined that an error occurs when I try to pass a tag_List to the file.
This is my code:
import nbtlib as nbt
class Structure(nbt.File):
def __init__(Self, data_version, size):
#super().__init__({"DataVersion":nbt.Int(data_version), "size":nbt.List(map(nbt.Int, size))})
super().__init__({"DataVersion":nbt.Int(data_version), "size":nbt.List(map(nbt.Int, size))})
structure = Structure(data_version=1952, size=(0, 0, 0))
structure.save("prueba.nbt")
This is the error:
Traceback (most recent call last):
File "D:\studios dante 2\MODULES\Games\structurenbt\module.py", line 10, in <module>
structure.save("prueba.nbt")
File "C:\Python38-32\lib\site-packages\nbtlib\nbt.py", line 132, in save
self.write(buff, byteorder or self.byteorder)
File "C:\Python38-32\lib\site-packages\nbtlib\tag.py", line 420, in write
tag.write(buff, byteorder)
File "C:\Python38-32\lib\site-packages\nbtlib\tag.py", line 365, in write
write_numeric(BYTE, self.subtype.tag_id, buff, byteorder)
File "C:\Python38-32\lib\site-packages\nbtlib\tag.py", line 84, in write_numeric
buff.write(fmt[byteorder].pack(value))
struct.error: required argument is not an integer
Can someone help me to fix the problem? I use python 3.8
I already fixed it, turns out I had the nbtlib out of date. I updated it and it works!

BadRarFile when extracting single file using RarFile in Python

I need to extract a single file (~10kB) from many very large RAR files (>1Gb). The code below shows a basic implementation of how I'm doing this.
from rarfile import RarFile
rar_file='D:\\File.rar'
file_of_interest='Folder 1/Subfolder 2/File.dat'
output_folder='D:/Output'
rardata = RarFile(rar_file)
rardata.extract(file_of_interest, output_folder)
rardata.close()
However, the extract instruction is returning the following error: rarfile.BadRarFile: Failed the read enough data: req=16384 got=52
When I open the file using WinRAR, I can extract the file successfully, so I'm sure the file isn't corrupted.
I've found some similar questions, but not a definite answer that worked for me.
Can someone help me to solve this error?
Additional info:
Windows 10 build 1909
Spyder 5.0.0
Python 3.8.1
Complete traceback of the error:
Traceback (most recent call last):
File "D:\Test\teste_rar_2.py", line 27, in <module>
rardata.extract(file_of_interest, output_folder)
File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\site-packages\rarfile.py", line 826, in extract
return self._extract_one(inf, path, pwd, True)
File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\site-packages\rarfile.py", line 912, in _extract_one
return self._make_file(info, dstfn, pwd, set_attrs)
File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\site-packages\rarfile.py", line 927, in _make_file
shutil.copyfileobj(src, dst)
File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\shutil.py", line 79, in copyfileobj
buf = fsrc.read(length)
File "C:\Users\bernard.kusel\AppData\Local\Continuum\anaconda3\lib\site-packages\rarfile.py", line 2197, in read
raise BadRarFile("Failed the read enough data: req=%d got=%d" % (orig, len(data)))
BadRarFile: Failed the read enough data: req=16384 got=52

Getting OSError when running script

I am trying to set up the ChirpSDK, but every time I configure and run the code, I get this error:
Traceback (most recent call last):
File "test.py", line 3, in <module>
chirp = ChirpSDK()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 395, in __init__
self.read_chirprc(block)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 501, in read_chirprc
raise IOError('Could not find a ~/.chirprc file')
OSError: Could not find a ~/.chirprc file
Exception ignored in: <function ChirpSDK.__del__ at 0x10fa31af0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 422, in __del__
self.close()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/chirpsdk/chirpsdk.py", line 470, in close
if self._sdk:
AttributeError: 'ChirpSDK' object has no attribute '_sdk'
I realize that the error is saying that my .chirprc file is not being recognized, but I have no idea how to remedy this. I created a .chirprc file in my /Users/username/ path, and named it c.chirprc (as the Chirp getting started article suggests), but I am still getting this error. Is there another part that I am missing? Am I reading the instructions wrong?
Thanks
The Chirp configuration file should be placed at /Users/<username>/.chirprc on macOS.
If you run ls -l ~/.chirprc in the terminal, do you get any results? If it displays no such file or directory then you have not created the file correctly.

Access neo4j via python-joern

When using Joern, I accessed the Neo4j database via python-joern with the following code.
from joern.all import JoernSteps
j = JoernSteps()
j.setGraphDbURL('http://localhost:7474/db/data/')
j.connectToDatabase()
res = j.runGremlinQuery('getFunctionsByName("main")')
for r in res: print r
Error like this
Traceback (most recent call last):
File "test.py", line 11, in <module>
res = j.runGremlinQuery('getFunctionsByName("main")')
File "/home/binbin/Downloads/python-joern-0.3.1/joern/all.py", line 44, in runGremlinQuery
return self.gremlin.execute(finalQuery)
File "/usr/local/lib/python2.7/dist-packages/py2neo-2.0-py2.7-linux-x86_64.egg/py2neo/ext/gremlin/__init__.py", line 36, in execute
response = self.resources["execute_script"].post({"script": script})
File "/usr/local/lib/python2.7/dist-packages/py2neo-2.0-py2.7-linux-x86_64.egg/py2neo/core.py", line 288, in post
raise_from(self.error_class(message, **content), error)
File "/usr/local/lib/python2.7/dist-packages/py2neo-2.0-py2.7-linux-x86_64.egg/py2neo/util.py", line 215, in raise_from
raise exception
py2neo.error.NoClassDefFoundError: javax/transaction/SystemException
How to fix it?
I had searched a lot for my question. Finally I found the solution here: https://github.com/fabsx00/python-joern/issues/14. Anyone who has got the same problem can see it.

when does bz2.decompress(rawdata) got an error of "couldn't find end of stream"?

I have checked that the file in my disk is the same as https://github.com/scipy/scipy/blob/master/scipy/misc/face.dat
but when I run this statement ,I have got this error. why ?
scipy.misc.face()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\scipy\misc\common.py", line 567, in face
data = bz2.decompress(rawdata)
ValueError: couldn't find end of stream
It's a bug (on Windows), see here
https://github.com/scipy/scipy/commit/7f0210fd28a2b3be79806d5cae462be52c1601e9

Categories

Resources