Menu

#5 Import error running yaml

resolved
nobody
None
major
bug
2020-01-23
2020-01-23
No

Python 3.7

> yaml --help
Traceback (most recent call last):
  File "f:\portableapps\python\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "f:\portableapps\python\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "F:\PortableApps\Python\Scripts\yaml.exe\__main__.py", line 5, in <module>
  File "f:\portableapps\python\lib\site-packages\ruamel\yaml\cmd\__main__.py", line 17, in <module>
    from .yaml_cmd import YAMLCommand
  File "f:\portableapps\python\lib\site-packages\ruamel\yaml\cmd\yaml_cmd.py", line 17, in <module>
    from ruamel.yaml import YAML
ImportError: cannot import name 'YAML' from 'ruamel.yaml' (f:\portableapps\python\lib\site-packages\ruamel\yaml\__init__.py)

(originally posted on 2018-10-14 at 10:08:14 by Thorsten Kampe <thorstenkampe@bitbucket>)

Discussion

  • Anthon van der Neut

    • status set to on hold

    How did you install ruamel.yaml.cmd? Which version is this? If you install using pip it will install/upgrade ruamel.yaml to version 0.15.72 (https://bitbucket.org/ruamel/yaml.cmd/src/6750e051d2f24dffc97e1e9192928268b536d79a/init.py#lines-19)

    (originally posted on 2018-10-14 at 10:36:58)

     
  • Anthon van der Neut

    This is not a yaml.cmd issue but a yaml issue. I tested it on Linux going back to 1.4.12 and Python 2.7: all show the same error.

    (originally posted on 2018-10-14 at 10:54:25 by Thorsten Kampe <thorstenkampe@bitbucket>)

     
  • Anthon van der Neut

    The Ubuntu package (python3-ruamel.yaml) works. I'm trying to figure out the difference between the pip version and the apt-get package.

    (originally posted on 2018-10-14 at 10:57:32 by Thorsten Kampe <thorstenkampe@bitbucket>)

     
  • Anthon van der Neut

    Older versions of ruamel.yaml ( < 0.15 ) don't have YAML imported into ruamel.yaml.__init__.py, so ruamel.yaml.cmd cannot find that. That is why I asked for the version, but I realise it was not clear that I needed the ruamel.yaml version number on your windows installation, not the ruamel.yaml.cmd version. You are not using anaconda do you (their stuff is broken).

    (originally posted on 2018-10-14 at 11:04:12)

     
  • Anthon van der Neut

    it looks like yaml.cmd pulls in the wrong(?) dependencies:

    1. Installing ruamel.yaml directly:
    sudo --set-home pip3 install ruamel.yaml
    Collecting ruamel.yaml
      Downloading https://files.pythonhosted.org/packages/e0/5b/1e2fe3c00e0ecf37bebeb0a7c7eab24bbcc0cb0d7fab8e7ab3e41eaf788c/ruamel.yaml-0.15.72-cp36-cp36m-manylinux1_x86_64.whl (659kB)
        100% |████████████████████████████████| 665kB 122kB/s
    Installing collected packages: ruamel.yaml
    Successfully installed ruamel.yaml-0.15.72
    
    python3 -c 'from ruamel.yaml import YAML'
    [no error]
    
    1. installing via ruamel.yaml.cmd:
    sudo --set-home pip3 install ruamel.yaml.cmd
    Collecting ruamel.yaml.cmd
      Downloading https://files.pythonhosted.org/packages/75/72/b06b4a623cc2152f1e422d0f82c51a98de52d9732cf704d0b23f54efd7fa/ruamel.yaml.cmd-0.5.0-py2.py3-none-any.whl
    Collecting ruamel.std.argparse>=0.8 (from ruamel.yaml.cmd)
      Downloading https://files.pythonhosted.org/packages/7e/f1/4148b62a1f92c5d7a46eb79046bcbf11be3c419f64677b12c3cac3b5ab9e/ruamel.std.argparse-0.8.1-py2.py3-none-any.whl
    Collecting ruamel.yaml.convert>=0.3 (from ruamel.yaml.cmd)
      Downloading https://files.pythonhosted.org/packages/f8/70/9309cca651caea2d9a1dbec900646cdff9431b32f76b41960858a8d56a35/ruamel.yaml.convert-0.3.0-py2.py3-none-any.whl
    Collecting configobj (from ruamel.yaml.cmd)
      Downloading https://files.pythonhosted.org/packages/64/61/079eb60459c44929e684fa7d9e2fdca403f67d64dd9dbac27296be2e0fab/configobj-5.0.6.tar.gz
    Collecting ruamel.yaml>=0.15.71 (from ruamel.yaml.cmd)
      Downloading https://files.pythonhosted.org/packages/e0/5b/1e2fe3c00e0ecf37bebeb0a7c7eab24bbcc0cb0d7fab8e7ab3e41eaf788c/ruamel.yaml-0.15.72-cp36-cp36m-manylinux1_x86_64.whl (659kB)
        100% |████████████████████████████████| 665kB 124kB/s
    Collecting python-dateutil (from ruamel.yaml.convert>=0.3->ruamel.yaml.cmd)
      Downloading https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_dateutil-2.7.3-py2.py3-none-any.whl (211kB)
        100% |████████████████████████████████| 215kB 85kB/s
    Requirement already satisfied: six in /usr/local/lib/python3.6/dist-packages (from configobj->ruamel.yaml.cmd) (1.11.0)
    Installing collected packages: ruamel.std.argparse, python-dateutil, ruamel.yaml, ruamel.yaml.convert, configobj, ruamel.yaml.cmd
      Running setup.py install for configobj ... done
    Successfully installed configobj-5.0.6 python-dateutil-2.7.3 ruamel.std.argparse-0.8.1 ruamel.yaml-0.15.72 ruamel.yaml.cmd-0.5.0 ruamel.yaml.convert-0.3.0
    
    python3 -c 'from ruamel.yaml import YAML'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    ImportError: cannot import name 'YAML'
    

    (originally posted on 2018-10-14 at 11:23:47 by Thorsten Kampe <thorstenkampe@bitbucket>)

     
  • Anthon van der Neut

    it actually is a problem with yaml.cmd. Uninstalling yaml.cmd removes the yaml error:

    sudo --set-home pip3 uninstall ruamel.yaml.cmd
    Uninstalling ruamel.yaml.cmd-0.5.0:
      Would remove:
        /usr/local/bin/yaml
        /usr/local/lib/python3.6/dist-packages/ruamel.yaml.cmd-0.5.0-py3.6-nspkg.pth
        /usr/local/lib/python3.6/dist-packages/ruamel.yaml.cmd-0.5.0.dist-info/*
        /usr/local/lib/python3.6/dist-packages/ruamel/yaml/cmd/*
    Proceed (y/n)? y
      Successfully uninstalled ruamel.yaml.cmd-0.5.0
    
    python3 -c 'from ruamel.yaml import YAML'
    

    (originally posted on 2018-10-14 at 11:30:10 by Thorsten Kampe <thorstenkampe@bitbucket>)

     
  • Anthon van der Neut

    The issue is the .pth file for yaml.cmd:

    sudo rm /usr/local/lib/python3.6/dist-packages/ruamel.yaml.cmd-0.5.0-py3.6-nspkg.pth
    python3 -c 'from ruamel.yaml import YAML' 
    [no error]
    

    (originally posted on 2018-10-14 at 11:34:27 by Thorsten Kampe <thorstenkampe@bitbucket>)

     
  • Anthon van der Neut

    .Confirmed on Windows: after removing the pth file for yaml.cmd, I can run "from ruamel.yaml import YAML" again. But yaml(.exe) still doesn't work because of the missing pth file. Why are those even needed?! The only other package on my machine that uses a pth file is pywin32.

    (originally posted on 2018-10-14 at 11:41:39 by Thorsten Kampe <thorstenkampe@bitbucket>)

     
  • Anthon van der Neut

    It looks like pip/distutils/setuptools once more screw up installing and handling namespace packages properly. If you install ruamel.yaml separately things work fine. If you remove the ruamel.yaml.cmd-0.5.0* info from site-packages things work so that metadata interferes in some way.

    (originally posted on 2018-10-14 at 11:42:25)

     
  • Anthon van der Neut

    Those .pth files extend the paths from which python imports, which is only important if you install next to each other.

    (originally posted on 2018-10-14 at 11:45:35)

     
  • Anthon van der Neut

    I uploaded a new version of ruamel.yaml.cmd (0.5.1), can you try that one, and if that works close this issue?

    (originally posted on 2018-10-14 at 12:38:36)

     
  • Anthon van der Neut

    After upgrading to 0.5.1:

    Traceback (most recent call last):
      File "f:\portableapps\python\lib\runpy.py", line 193, in _run_module_as_main
        "__main__", mod_spec)
      File "f:\portableapps\python\lib\runpy.py", line 85, in _run_code
        exec(code, run_globals)
      File "F:\PortableApps\Python\Scripts\yaml.exe\__main__.py", line 9, in <module>
      File "f:\portableapps\python\lib\site-packages\ruamel\yaml\cmd\__main__.py", line 212, in main
        sys.exit(n.run())
      File "f:\portableapps\python\lib\site-packages\ruamel\yaml\cmd\__main__.py", line 50, in run
        if self._args.func:
    AttributeError: 'Namespace' object has no attribute 'func'
    

    (originally posted on 2018-10-14 at 13:11:06 by Thorsten Kampe <thorstenkampe@bitbucket>)

     
  • Anthon van der Neut

    Sorry for that, I had only tested with yaml -h. 0.5.3 should now have that fixed (and tox based testing works as well again)

    (originally posted on 2018-10-15 at 05:31:02)

     
  • Anthon van der Neut

    • status set to resolved

    (originally posted on 2018-10-15 at 06:34:31)

     

Log in to post a comment.