Can't unpickle a file in 3.6 Python - python

I had a pandas df a while back in 3.10 that I put into a .pkl pickle file. Because one of my modules is only available in 3.6, I had to revert the rest back to 3.6. However, I can't do pandas.read_pickle("file.pkl") now because my older pandas can't handle the newer file.
I'm getting an error like this:
AttributeError: Can't get attribute '_unpickle_block' on <module 'pandas._libs.internals' from '/opt/mambaforge/envs/...
What I tried to do as a workaround is to load the file in the new python 3.10 and then write to another file using PROTOCOL=4 because 4 is the protocol used in python 3.6.
Here's my code:
df = pd.read_pickle('file3ten.pkl')
import pickle5 as pickle
with open(path_to_protocol5, "rb") as fh:
data = pickle.load(fh)
import pickle
pickle.HIGHEST_PROTOCOL=4
with open("file3six.pkl", 'wb') as pfile:
pickle.dump(df, pfile, protocol=pickle.HIGHEST_PROTOCOL)
Now I thought that I would be able to do pd.read_pickle('file3six.pkl') because the protocol was reduced, but I just got a chained error, saying:
AttributeError: module 'pandas._libs.internals' has no attribute '_unpickle_block'
During handling of the above exception, another exception occurred:
...
AttributeError: Can't get attribute '_unpickle_block' on <module 'pandas._libs.internals' from '/opt/mambaforge/envs/
If anyone knows what do to fix this, I'd appreciate it a lot

Related

AttributeError: module 'openpyxl.cell' has no attribute 'get_column_letter'

when I try to run code regarding retrieving column letter from a number I keep getting the following error:
AttributeError: module 'openpyxl.cell' has no attribute 'get_column_letter'
This is the code I am trying to run:
print(openpyxl.cell.get_column_letter(26))
I expect this to run with no error.
Because this attribute has been moved to utils within this module, the way to call this without getting an error is to call it from its new location:
print(openpyxl.utils.cell.get_column_letter(26))
This should be working now.

Error reading "pickle" file, no module named 'Data'

I tried to read pickle file using Anaconda Navigator and have the following script.
import pickle
import sys, os
with open('pickle1', 'rb') as fp:
data_new = pickle.load(fp)
After running the window I get the following error window.
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-047bee0f1247> in <module>()
3
4 with open('pickle1', 'rb') as fp:
----> 5 data_new = pickle.load(fp)
ModuleNotFoundError: No module named 'Data'
Can you please help me fix this issue? I tried to rename file to *.pkl, and *.csv formats, but it did not help. Original data file has no extension of its own.
The program that created the pickle file did import Data and there are references to that module inside the pickled object. The program that loads the pickled object needs to be able to import that module to resolve those references. Either put the location of Data.py on your PYTHONPATH (or add the location to sys.path), or copy the module to where your program can find it.

Python Dataset module AttributeError: 'module' object has no attribute 'connect'

I'm trying to use the dataset module in python.
import dataset
# connecting to a MySQL database with user and password
db = dataset.connect('mysql://root:Kradz579032!!#localhost/aliexpressapidb')
But I keep getting the following error :
AttributeError: module object has no attribute 'connect'
What does it mean?
Thank you for posting your Traceback.
The error message shows that you've named your file dataset.py:
File "/Users/reezalaq/Downloads/newali/db/dataset.py"
This masks the module you want to import, here dataset. To solve this, just rename your file to something else.

'DecisionTreeClassifier' object has no attribute 'export_graphviz'

I'm using python sklearn RandomForestClassifier and try to export decisiontrees.
The basic code is as following:
from sklearn import tree
with open(dot_file_name, 'w') as my_file:
tree.export_graphviz(tree1, out_file = my_file,feature_names = feature_names)
After run the python script, following error show up:
Attribute error: 'DecisionTreeClassifier' object has no attribute 'export_graphviz'
I'm using python 2.7. Is it because of the version of python? Do I have to use python 3.0?
That's because you used somewhere tree name as name for DecisionTreeClassifier. Use another name there.

skimage ImageCollection and Python3

I am having trouble using the skimage ImageCollection (http://scikit-image.org/docs/dev/api/skimage.io.html#imagecollection) object in Python3. For example, in python 2,7, I was using it as follows:
import skimage.io as io
files = io.ImageCollection('/home/luca/sequence/*.*)
method_do_something(files[0])
This worked fine. When I use it in Python 3.4, the creation of the ImageCollection object works fine and len(files) returns the correct amount of files.
However, when I try the files[0] call, I get the following error:
AttributeError: 'builtin_function_or_method' object has no attribute 'keys'
I was wondering if anyone knows of a workaround that might work on both 2.7 and python 3.x

Categories

Resources