ImportError: No module named _pickle

Viewed 10384

I am working with this python code which has

import _pickle 

I get a ImportError: No module named _pickle

But I am not able to install either _pickle or pickle using conda or pip install. What is this lib and how to install it?

2 Answers

It should be

import pickle

instead of

import _pickle

In general, don't import anything starting with an underscore unless you know what you are doing. They are mostly some modules that are not supposed to be used directly, and usually have wrappers around them (to make platform independent for eg.).

The pickle module is used for serialization of python objects, for example if you want to write objects to a file. The pickle module is in-built so you don't need to install it. The _pickle version is written in C, and is implemented already in pickle. Just use "import pickle" (without quotes!).

Related