[Python-Dev] Error embedding python

Brett Cannon brett at python.org
Sat Apr 7 14:02:20 EDT 2018


Most likely your 'args' module is calling import with a bytes object and
not a string and that it's getting that far into the process before you hit
code that only works with strings (_os.listdir() returns bytes if you pass
a bytes argument to it).

At this point I would take the question to python-list or python-tutor to
get more help with embedding.

On Fri, 6 Apr 2018 at 10:29 Chris Bryan <cbryan at rapitasystems.com> wrote:

> Hello list,
>
> I am embedding a python 3.6 environment in another executable, which is
> compiling and executing ok. However I get an error on Windows when I try
> to import any module except sys:
>
> Traceback (most recent call last):
>    File "args", line 1, in <module>
>    File "<frozen importlib._bootstrap>", line 971, in _find_and_load
>    File "<frozen importlib._bootstrap>", line 951, in
> _find_and_load_unlocked
>    File "<frozen importlib._bootstrap>", line 894, in _find_spec
>    File "<frozen importlib._bootstrap_external>", line 1157, in find_spec
>    File "<frozen importlib._bootstrap_external>", line 1129, in _get_spec
>    File "<frozen importlib._bootstrap_external>", line 1245, in find_spec
>    File "<frozen importlib._bootstrap_external>", line 1302, in _fill_cache
> TypeError: a bytes-like object is required, not 'str'
>
> Looking on line 1302, it would appear that the call to _os.listdir()
> (line 1285) is returning a list of byte objects. I can confirm that I
> get the same error doing the following from a normal python interactive
> session:
>
>  >>> x = b'a.b.c'
>  >>> x.partition('.')
> Traceback (most recent call last):
>    File "<stdin>", line 1, in <module>
> TypeError: a bytes-like object is required, not 'str'
>
> Is this a bug in the bootstrap module, or am I doing something wrong
> which is causing listdir() to return bytes?
>
> Chris
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/brett%40python.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180407/d68d6331/attachment.html>


More information about the Python-Dev mailing list