当前位置: 首页>>技术教程>>正文


如何在Python 3.4上安装cPickle?

,

问题描述

我尝试了 sudo apt-get install cPicklepython3.4-cPickle 但不起作用。

最佳回答

python 3中没有cPickle

\\n

A common pattern in Python 2.x is to have one version of a module implemented in pure Python, with an optional accelerated version implemented as a C extension; for example, pickle and cPickle. This places the burden of importing the accelerated version and falling back on the pure Python version on each user of these modules. In Python 3.0, the accelerated versions are considered implementation details of the pure Python versions. Users should always import the standard version, which attempts to import the accelerated version and falls back to the pure Python version. The pickle / cPickle pair received this treatment.

\\n

Source

次佳回答

来自 pickle 模块文档:

\\n

The pickle module has an transparent optimizer (_pickle) written in C. It is used whenever available. Otherwise the pure Python implementation is used.

\\n

python3 中使用:

import _pickle as cPickle

参考资料

本文由Ubuntu问答整理, 博文地址: https://ubuntuqa.com/article/13835.html,未经允许,请勿转载。