I have pickled a csv dataset, which I then call in my main script. When executing line by line the code in my console, everything works fine; when running the whole program, I receive the error message: AttributeError: module 'pickle' has no attribute 'HIGHEST_PROTOCOL'
I have a csv dataset (also available in fixed-width text, tab-delimited text or HTML table if needed), which I need to import in Python. Due to the fact that every time that I run my script this big file gets re-loaded, I have created a separate program "pickle.py" which reads in the csv file and saves it in the more quickly accessible pkt format. Then I have created a program "main.py" to do my data analysis, where I start by reading in the pickled file. If I run line by line the program "main.py" in the console, the script runs smoothly. If I run it with the run button, it receive the following error:
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevconsole.py", line 33, in <module>
from _pydev_bundle.pydev_console_utils import BaseInterpreterInterface
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_console_utils.py", line 6, in <module>
from _pydev_bundle.pydev_code_executor import BaseCodeExecutor
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_code_executor.py", line 7, in <module>
from _pydevd_bundle import pydevd_vars
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydevd_bundle/pydevd_vars.py", line 4, in <module>
import pickle
File "/Users/nicolo/pickle.py", line 11, in <module>
import pandas as pd
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/__init__.py", line 42, in <module>
from pandas.core.api import *
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/api.py", line 26, in <module>
from pandas.core.groupby import Grouper
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/groupby/__init__.py", line 1, in <module>
from pandas.core.groupby.groupby import GroupBy # noqa: F401
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/groupby/groupby.py", line 37, in <module>
from pandas.core.frame import DataFrame
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/frame.py", line 87, in <module>
from pandas.core.generic import NDFrame, _shared_docs
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 98, in <module>
class NDFrame(PandasObject, SelectionMixin):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 2534, in NDFrame
protocol=pkl.HIGHEST_PROTOCOL):
AttributeError: module 'pickle' has no attribute 'HIGHEST_PROTOCOL'
pickle.py
This script needs to be run each time the database (.csv) is updated. It pickles the database to generate a new file (.pkl) which can be imported much faster in the "main" script.
# IMPORT LIBRARIES
import pandas as pd
# PICKLE THE FILE
data = pd.read_csv("database.csv")
data.to_pickle("/Users/nicolo/database.pkl")
main.py
"""
Implementation of the main script.
"""
# IMPORT LIBRARIES
import pandas as pd
# IMPORT THE DATABASE
data = pd.read_pickle("/Users/nicolo/database.pkl")
I do not understand what is generating the error. Thank you in advance for your help.