Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installing cPickle with python 3.5

This might be silly but I am unable to install cPickle with python 3.5 docker image

Dockerfile

FROM python:3.5-onbuild 

requirements.txt

cpickle 

When I try to build the image

$ docker build -t sample . Sending build context to Docker daemon 3.072 kB Step 1 : FROM python:3.5-onbuild # Executing 3 build triggers... Step 1 : COPY requirements.txt /usr/src/app/ Step 1 : RUN pip install --no-cache-dir -r requirements.txt  ---> Running in 016c35a032ee Collecting cpickle (from -r requirements.txt (line 1))   Could not find a version that satisfies the requirement cpickle (from -r requirements.txt (line 1)) (from versions: ) No matching distribution found for cpickle (from -r requirements.txt (line 1)) You are using pip version 7.1.2, however version 8.1.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. The command '/bin/sh -c pip install --no-cache-dir -r requirements.txt' returned a non-zero code: 1 
like image 770
kampta Avatar asked May 10 '16 08:05

kampta


People also ask

Is cPickle available in Python 3?

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.

What is cPickle in python?

“Pickling” is the process whereby a Python object hierarchy is converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte stream (from a binary file or bytes-like object) is converted back into an object hierarchy.

What is the difference between Pickle and cPickle?

The pickle data format is standardized, so strings serialized with pickle can be deserialized with cPickle and vice versa. The main difference between cPickle and pickle is performance. The cPickle module is many times faster to execute because it's written in C and because its methods are functions instead of classes.


2 Answers

cPickle comes with the standard library… in python 2.x. You are on python 3.x, so if you want cPickle, you can do this:

>>> import _pickle as cPickle 

However, in 3.x, it's easier just to use pickle.

No need to install anything. If something requires cPickle in python 3.x, then that's probably a bug.

like image 157
Mike McKerns Avatar answered Sep 24 '22 15:09

Mike McKerns


You can use this for both python 2 and 3

try:   import cPickle as pickle except:   import pickle 
like image 27
nicosp Avatar answered Sep 23 '22 15:09

nicosp