omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    yaml error in Pythonista 3.4

    Pythonista
    3
    6
    74
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      johndoe77 last edited by

      Hi,

      I just updated to Pythonista 3.4 and wanted to use yaml for setting up a configuration file. I did this before on my DEV machine, so the following code (c&p) should work:

      import yaml
      # Read yaml config
      with open('config.yaml', 'r') as file:
          configuration = yaml.safe_load(file)
      

      However, in Pythonista I get an error, saying

      AttributeError
      module 'collections' has no attribute 'Hashable'

      It maybe has to do with the version of pyyaml running in Pythonista on Python 3.10 and is probably related to this issue:
      https://github.com/yaml/pyyaml/issues/622

      Any way to fix it on my own? Or is a Pythonista update with a more recent yaml necessary?

      Thanks in advance.
      J.

      cvp 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @johndoe77 last edited by

        @johndoe77 said

        It maybe has to do with the version of pyyaml running in Pythonista on Python 3.10

        Yes, you're right...

        cvp 1 Reply Last reply Reply Quote 0
        • cvp
          cvp @cvp last edited by cvp

          @cvp put this code in the script where collections is imported

          # Python 3.10 has put Hashable and MutableMapping in collections.abc instead of collections
          import collections
          collections.Hashable = collections.abc.Hashable
          collections.MutableMapping = collections.abc.MutableMapping
          
          J 1 Reply Last reply Reply Quote 0
          • J
            johndoe77 @cvp last edited by

            @cvp Thank you very much! As a workaround it does the job.

            Hopefully, it's not a major hassle to upgrade Pythonista with a newer version of yaml.

            cvp 1 Reply Last reply Reply Quote 0
            • cvp
              cvp @johndoe77 last edited by cvp

              @johndoe77 Solution does not come from me but from @ccc advice, see here

              ccc 1 Reply Last reply Reply Quote 0
              • ccc
                ccc @cvp last edited by

                @omz please consider upgrading pyyaml in a future release.

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post
                Powered by NodeBB Forums | Contributors