X Tutup
The Wayback Machine - https://web.archive.org/web/20251205000639/https://github.com/python/cpython/issues/102290
Skip to content

pickle.load method works in ipynb but fails in a .py file #102290

@Justinfungi

Description

@Justinfungi

Bug report

image

The error is :

 File "/home/fish/Documents/API/DSLAB/AIMS/A.py", line 3, in <module>
    model = pickle.load(open('AIMS.pkl', 'rb'))
  File "/home/fish/anaconda3/envs/DSLAB/lib/python3.9/site-packages/keras/saving/pickle_utils.py",
 line 39, in deserialize_model_from_bytecode
    with tarfile.open(fileobj=b, mode="r") as archive:
  File "/home/fish/anaconda3/envs/DSLAB/lib/python3.9/tarfile.py", line 1614, in open
    raise ReadError("file could not be opened successfully")
tarfile.ReadError: file could not be opened successfully

Issue

The issue is when i work in jupyter notebook, it does work and gives me the true mode.
But when i try to import the model in .py file. it fails.

I think there is an inconsistency between this 2 format file operations.

Code block

import pickle
model = pickle.load(open('AIMS.pkl', 'rb'))

Simple code can show the error reproductively.

  • Operating system and architecture: Ubuntu 20.04 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup