我正在尝试将泡菜格式的数据集加载到R中。 由于以下问题,我发现程序包“成网状”:
Reading a pickle file (PANDAS Python Data Frame) in R
这是我的Python文件,名为“ pickle_reader.py”
def read_pickle_file(file):
pickle_data = pd.read_pickle(file)
return pickle_data
这是我的R代码:
library(reticulate)
use_python("/usr/bin/python3", required = T)
source_python("pickle_reader.py")
pickle_data <- read_pickle_file("/path/to/file.pkl")
R中出现以下错误消息:
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: unsupported pickle protocol: 4
Detailed traceback:
File "<string>", line 11, in read_pickle_file
File "/usr/lib/python2.7/dist-packages/pandas/io/pickle.py", line 60, in read_pickle
return try_read(path)
File "/usr/lib/python2.7/dist-packages/pandas/io/pickle.py", line 57, in try_read
return pc.load(fh, encoding=encoding, compat=True)
File "/usr/lib/python2.7/dist-packages/pandas/compat/pickle_compat.py", line 116, in load
return up.load()
File "/usr/lib/python2.7/pickle.py", line 864, in load
dispatch[key](self)
File "/usr/lib/python2.7/pickle.py", line 892, in load_proto
raise ValueError, "unsupported pickle protocol: %d" % proto
因此似乎发生了错误,因为Python 2.7无法处理pickle协议。因此,我使用
use_python("/usr/bin/python3", required = T)
以上。但这似乎没有效果。 py_discover_config()
的输出是:
python: /usr/bin/python3
libpython: /usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/libpython3.5.so
pythonhome: /usr:/usr
version: 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609]
numpy: /usr/local/lib/python3.5/dist-packages/numpy
numpy_version: 1.14.2
NOTE: Python version was forced by use_python function
py_config()
的输出是:
python: /usr/bin/python
libpython: /usr/lib/python2.7/config-x86_64-linux-gnu/libpython2.7.so
pythonhome: /usr:/usr
version: 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609]
numpy: /usr/lib/python2.7/dist-packages/numpy
numpy_version: 1.11.0
python versions found:
/usr/bin/python
/usr/bin/python3