I tried sudo apt-get install cPickle and python3.4-cPickle but it doesn't work.
-
3I would assume you install a python module with `pip`? – Rinzwind Mar 06 '16 at 17:24
-
can you give me the command please – vincet Mar 06 '16 at 17:33
-
10AFAIK, in python 3, you use `pickle` only. Internally it will use `cpickle` if available. See https://docs.python.org/3.1/whatsnew/3.0.html#library-changes – cshubhamrao Mar 06 '16 at 17:36
2 Answers
There is no cPickle in python 3:
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.
-Source.
- 4,143
- 3
- 24
- 32
- 886
- 8
- 4
-
"the accelerated versions are considered implementation details of the pure Python versions": what does this exactly mean? – Basj Feb 04 '20 at 12:57
-
1
-
5@basj, "Implementation detail" means something that should be hidden from us users. We just want the pickle functionality and should not care if its implemented in python or c. So, it means don't make us understand...python just do the best thing. – Robert Lugg May 06 '20 at 20:40
From the pickle module documentation:
The
picklemodule has an transparent optimizer (_pickle) written in C. It is used whenever available. Otherwise the pure Python implementation is used.
In python3 use:
import _pickle as cPickle
- 151
- 1
- 5
-
Have I misunderstood this? `python3.8 -m pip install pickle`. Output: `ERROR: Could not find a version that satisfies the requirement pickle (from versions: none) ERROR: No matching distribution found for pickle`. How should I install it then? – questionto42 Sep 01 '21 at 13:07
-
1@questionto42standswithUkraine have you tried just importing pickle? It is a built-in so you shouldn't need to install it at all. – Kraigolas Jul 27 '22 at 17:19
-