Python 3, trouble with "import pickle"

I’m learning how to use pickle/unpickle to save useful background info for my program, but Komodo IDE/Python doesn’t seem to accept this little program from Python Wiki.

#!/usr/bin/env python3
# Save a dictionary into a pickle file.

import pickle
SvNam = "save.p"
favorite_color = { "lion": "yellow", "kitty": "red" }
pickle.dump( favorite_color, open(SvNam, "wb"))

Pressing F5 gives error output as follows:

Traceback (most recent call last):
  File "D:\Python 3\PitchStrucs\PickleEx.py", line 4, in < module>
    import pickle
  File "< frozen importlib._bootstrap>", line 0, in _find _and _load
  File "C:\Python34\lib\base64.py", line 536, in encodebytes
    _ input_type_check(s)
  File "C:\Python34\lib\base64.py", line 522, in _ input_type_check
    raise TypeError(msg) from err
TypeError: expected bytes-like object, not str

(I have inserted blanks in a few places where your display misinterprets “_” and “<”)

Any idea what might be wrong? I’m using Komodo IDE, ver. 9.1.0.87337, Python 3 ver. 3.4.3
I have not had trouble with anything else in Komodo IDE that I have used so far in my measly little experience.

Does the script run fine when running it from the command line?

Yes, from command line it runs just right. In fact that’s why I posted it here. It seems to me like a Komodo problem, not a Python problem.

Is your file marked as Python or Python3?

It’s Python 3, as you can see in the first line. Hope I did it properly.

To confirm though, does the language menu at the bottom of Komodo actually say Python3? It does not necessarily have to reflect what you have in your file there.

Eh?? Just below the edit window there’s a status line giving the path to the file I’m editing, the “file encoding” (ASCII), the “file type” (Python3), and the line and column number. Next to “Python3” there’s a funny little icon , which corresponds to “Python3” in the long list of languages that pops up when you press it. And in this list there’s a checkmark next to “Python3”. Does this answer your question?? Is my file in fact a Python3 file? Sorry, I’m not sure where to find “the bottom of Komodo”. I hope this helps.

I’m trying your script on linux using Python 3.4.3, it runs without any issues both in and outside of Komodo.

@careyh could you see if it works on WIndows?

@nathanr, runs without issue for me.

Cheers,

  • Carey

I have the same issue, am on Mac OS X Yosemite. I have a mixed project of Python 2 and 3 code, which I cannot post here. The project runs without problems from the command line.

Here’s the traceback:
Traceback (most recent call last):
File “/Users/Shared/Projects/my_project/tools/my_code.py”, line 23, in
from pprint import pprint, pformat
File “”, line 0, in _find_and_load
File “”, line 0, in _find_and_load
File “/Users/Shared/Virtualenvs/myvenv/lib/python3.4/base64.py”, line 536, in encodebytes
_input_type_check(s)
File “/Users/Shared/Virtualenvs/myvenv/lib/python3.4/base64.py”, line 522, in _input_type_check
raise TypeError(msg) from err
TypeError: expected bytes-like object, not str