PyInstaller fails to correctly package ruamel.yaml

383 Views Asked by At

I'm unable to package ruamel.yaml using PyInstaller.

I've used the following simple test case:

from ruamel.yaml import YAML
parser = YAML(typ="safe", pure=True)
print(parser.load("17"))

This works fine when run normally, but produces this exception after being packaged with PyInstaller:

ImportError: cannot import name 'YAML' from 'ruamel.yaml' (/tmp/_MEIsScRyt/ruamel/yaml/__init__.pyc)

I can partially work around this problem by referring to YAML as ruamel.yaml.main.YAML, but various properties are referred to via ruamel.yaml inside the library, and I can't change those.

How can I ensure PyInstaller correctly packages the entire ruamel.yaml package?

I'm using the latest PyInstaller version as installed via pip3, 4.2.dev0.

1

There are 1 best solutions below

0
On

If you can refer to ruamel.yaml.main.YAML but not to ruamel.yaml.YAML it looks like pyinstaller doesn't correctly install ruamel.yaml's __init__.py as that does:

from ruamel.yaml.main import *

You should check to see if that file is available under subdir ruamel/yaml.

In general you should compare the file hierarchy that PyInstaller produces/stores with the the result of how `ruamel.yaml should be installed, as specified in the documentation:

pip install ruamel.yaml

There are some corrections in the setup.py of all ruamel.* and ruamel.*.* packages to deal with correctly installing these nested namespaced packages. This however is only adjusted for, and tested using, pip. Installers that are not 100% compatible with pip might make assumptions that are not valid and fail to install correctly.