Conda Init Error Reads -- TypeError: memoryview: a bytes-like object is required, not 'str'

Hello,

I’m attempting to install Anaconda using the command line and I get an error at the very end when it tries to run “conda init”. Everything installs just fine except at the last part, I get the following:

TypeError: memoryview: a bytes-like object is required, not ‘str’

(Screen shots of the full error and report are below)

Any help would be greatly appreciated.

Thanks,
Evan

1 Like

dear evanm16.

thank you for posting.

This is a problem caused by MacOS being zsh.
To avoid this, choose “no” for the first conda init answer during installation.
Then after the installation is complete run “conda init zsh” as you show in the screenshot.

However, in this case, the shell parameter is bash, so if you refer to the following article and fix it for zsh, jupyter etc. will work normally.

Zsh on MacOS X.

Refrence URL:

Regards, you.
ktsh.tanaka.2020

The reason for this error is that in Python 3, strings are Unicode, but when transmitting on the network, the data needs to be bytes instead. We can convert bytes to string using bytes class decode() instance method, So you need to decode the bytes object to produce a string. In Python 3 , the default encoding is “utf-8” , so you can use directly:

b"python byte to string".decode("utf-8")

Python makes a clear distinction between bytes and strings . Bytes objects contain raw data — a sequence of octets — whereas strings are Unicode sequences . Conversion between these two types is explicit: you encode a string to get bytes, specifying an encoding (which defaults to UTF-8); and you decode bytes to get a string. Clients of these functions should be aware that such conversions may fail, and should consider how failures are handled.

I ran into this same issue and searching for TypeError: memoryview: a bytes-like object is required, not ‘str’ brought me here.

It turned out that my .bashrc file had broken permissions and conda init was unable to write to it. Fixing up the permissions resolved the issue.

1 Like