Forum Archive

Help, plz. Been trying to solve this prob for a while

Swoboderz

File "/var/containers/Bundle/Application/D1ECCA2A-92A4-498F-9924-55A09E1EE6CD/Pythonista3.app/Frameworks/Py3Kit.framework/pylib/distutils/log.py", line 32, in _log
if stream.errors == 'strict':
AttributeError: 'StdoutCatcher' object has no attribute 'errors'

Why is it doing this,

ccc

Do you use StaSH? What do you get when you...

import sys
print(sys.stdout)
print(sys.__stdout__)
JonB

stdout, stdin and the like in pythonista do not have the full capabilities of a regular terminal. in cases like this, you may need to monkeypatch stdout to have isatty(), errors, etc to mKe ezternal scripts work.

sys.stdout.errors = 'strict'

might work

dgelessus

What are you trying to use distutils for anyway? Its main purpose is setting up Python modules that require extra C code to be compiled, which is not possible on Pythonista.

Swoboderz

@ccc2

>>> import sys
>>> print(sys.stdout)
<__main__.main.<locals>.StdoutCatcher object at 0x1093257b8>
>>> print(sys.__stdout__)
<_io.TextIOWrapper name='<stdout>' mode='w' encoding='US-ASCII'>

I'm trying to use a C extension..

Swoboderz

@JonB this chunk of code (which is where it all goes wrong) already has that. Does it need to be hard coded? stream = sys.stdout
if stream.errors == 'strict':
# emulate backslashreplace error handler
encoding = stream.encoding
msg = msg.encode(encoding, "backslashreplace").decode(encoding)
stream.write('%s\n' % msg)
stream.flush()

ccc

I'm trying to use a C extension.

Apple's app guidelines prevent the linking of compiled code unless they are all signed by the same digital signature. This means that only @omz can add c extension.

JonB

@Swoboderz which extension are you trying to use?

You will note that that chunk if code is using errors, encoding, etc. However:

>>> dir(sys.stdout)
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'encoding', 'flush', 'isatty', 'write', 'writelines']

notice there is no errors attribute.

So, before calling that code (probably in your script, not in the console, since the streams might be reset when globals get cleared, i forget), just do

sys.stdout.errors ='strict'

or, maybe try a different option, depending on whether you want that bit of code executing or not.

It is all probably moot anyway, since you won't be able to call a c extension that wasnt shipped with pythonista.