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.


    About the PYTHONPATH envvar

    Pythonista
    1
    2
    3980
    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.
    • dgelessus
      dgelessus last edited by

      Normally the PYTHONPATH environment variable can be used to add additional directories in front of the default import path. By default it is empty or not set, and the default import path is always added after any locations from PYTHONPATH. On Pythonista, PYTHONPATH contains all locations from the default import path, as if there were no default import locations and all locations were user-defined. It should really be emtpy, because all sys.path entries are provided by default, and none of them are set by the user.

      Why does this matter? setuptools does some magic by installing a custom site.py under site-packages, which needs to find the real site.py module from the stdlib to work correctly. During this search it ignores any import locations from PYTHONPATH, which includes all import locations on Pythonista, meaning that nothing is searched at all and the import of site fails.

      1 Reply Last reply Reply Quote 1
      • dgelessus
        dgelessus last edited by

        On a slightly related note, it looks like sys.path is reset every time a script is run (even an editor action) without reloading site again, which means that any previous sys.path changes from site (including .pth files) are lost until site is manually reloaded.

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