My situation is this:
x.pth
/usr/local/lib/site-packages
/usr/local
/usr/local/bin
sys.path
python -S
site.PREFIXES
import sys; sys.path.remove('pth/to/faulty/numpy')
Is there a way to disable loading the specified pth file or remove the path from sys.path before python loads?
I tried to configure virtualenv and this does not suit my current situation.
I finally managed to solve this problem. My site package library had an easy_install.pth file, which for some reason contained an erroneous numpy, and not an x.pth file on /usr/local/lib/site-packages .
easy_install.pth
After a lot of time that I spent on this, I will share some of the things I learned if anyone else ever comes here:
If you have locally installed python installed, it will not search in '/ usr / local / lib' by default. If you want to know where he is looking, run:
import site print site.PREFIXES
python is looking for paths here + lib/python2.X/site-packages . Described here
lib/python2.X/site-packages
According to these docs you can play with your sys.path. If you add the usercustomize module to your local sites ( import site; site.getusersitepackages() ), it will import site; site.getusersitepackages() . However, it took me a while to figure out - this happens after python processes the pth files located on your sites and before it processes their AGAIN. If I add a print statement to this method (lib / site.py addeditedir), it will print:
usercustomize
import site; site.getusersitepackages()
pth
/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
As soon as I had a pth file that I missed in the site packages, I could not fix it with usercustomize , since this pth file was able to run one more time after that!
Unable to delete pth file. Standard python will look for pth files in /usr/lib and /usr/local/lib .
/usr/lib
/usr/local/lib
You can create isolated python via viartualenv though.