Skip to content Skip to sidebar Skip to footer

Prevent Python From Loading A Pth File

My situation is as follows: I have a locally installed version of python. There exists also a global one, badly installed, which I do not want to use. (I don't have admin privilig

Solution 1:

I finally managed to solve this - my site-packages library had an easy_install.pth file containing the faulty numpy for some reason, and not the x.pth file on /usr/local/lib/site-packages.

After the major amount of time I spent on this, I'll share some of the stuff I've learned if someone else ever gets here:

  • If you have a locally installed python it will not search in '/usr/local/lib' by default. If you want to know where it searches, run:

    import site
    print site.PREFIXES
    

    python searches for the paths here + lib/python2.X/site-packages. It's described here

  • According to these docs, you can in fact play around with your sys.path. If you add usercustomize module to your local sitepackages (import site; site.getusersitepackages()), it will be ran. However, and this took me time to realize - it happens after python processes the pth files located at your site-packages, and before he processes them AGAIN. If I add a print statement to the method that does this (lib/site.py addsitedir), this is what it will print:

    /home/user/.local/lib/python2.7/site-packages
    /home/user/py/lib/python2.7/site-packages
    #This is where your code runs
    /home/user/py/lib/python2.7/site-packages/numpy-1.9.0-py2.7-linux-x86_64.egg
    /home/user/Develop/Python/myproject
    /home/user/lmfit-0.7.2
    /home/user/py/lib/python2.7/site-packages #NOTE: this runs a second time
  • Once I had a pth file that I missed in site-packages, I couldn't fix it with a usercustomize, since that pth file got a chance to run one more time afterwards!

Solution 2:

There is no way to delete pth file. Standard python will search for pth files in /usr/lib and /usr/local/lib.

You can create isolated python via viartualenv though.

Post a Comment for "Prevent Python From Loading A Pth File"