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.


    Import newer version of built-in module

    Pythonista
    3
    7
    4121
    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.
    • manuguerra
      manuguerra last edited by

      Newbie question:
      The current version of Pythonista (1.5) comes with Sympy 0.7.4.1, but I need version 0.7.5.
      I have downloaded the newest version of the module using the script installsympy at https://gist.github.com/henryiii/9011826 and I can see a sympy folder in Pythonista.

      How can I import the newest version?
      "import sympy" imports the builtin version, and renaming the folder to something like sympy2 and then importing it gives me conflict errors.

      What is the right way to do this? absolute_import?

      Thanks

      Update:

      If I try:

      from . import sympy
      

      I get:

      Traceback (most recent call last):
      File "<string>", line 1, in <module>
      ValueError: Attempted relative import in non-package
      
      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        Update sys.path to out your new sympy folder at the start.
        I think you can also use imp.load_module.
        I think it is also possible to manually set __package__ before doing the import the way your tried, but not sure.

        1 Reply Last reply Reply Quote 0
        • manuguerra
          manuguerra last edited by

          Thanks for the reply JonB.
          Using sys.path.append does not solve the problem.
          Honestly I am a bit in the dark (i.e. am a complete newbie), so I run sys.path.append('.'), sys.path.append('..') and sys.path.append('sympy'), not knowing which one was the right one (and killing Pythonista each time to stay on the safe side).
          In all cases,

          import sympy
          sympy.__version__
          

          gave 0.7.4.1
          What am I doing wrong?

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            I believe you want to insert at the top, not append at the end, so that it searches your new folder first. Be sure to restart pythinista before trying this (or possibly del(sys.modules[sympy]))

            1 Reply Last reply Reply Quote 0
            • JonB
              JonB last edited by

              Ok, suppose you put sympy in the main pythonista directory, under newsympy.
              So, you have a folder called newsympy/sympy, which contains the __init__ script.

              Then, you would insert this top level path, at the start of sys.path, like this

              sys.path.insert(0,os.path.abspath('~/newsympy'))

              Point to the path above the folder named sympy.

              1 Reply Last reply Reply Quote 0
              • omz
                omz last edited by

                You should use os.path.expanduser('~/newsympy') – abspath won't expand the tilde (~).

                1 Reply Last reply Reply Quote 0
                • manuguerra
                  manuguerra last edited by

                  Thanks that worked!

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