How Do I Get An Installed Script To Ignore Pythonpath
I know I can get Python to ignore PYTHONPATH if I start it with the -E flag. But how do I get a script installed by pip to have this flag? I tried both the 'scripts' and the 'conso
Solution 1:
I generally recommend against this sort of trickery. The target system puts paths in place for a reason. If you want to break out of a virtualenv you should simply recommend not installing in a virtualenv in your documentation.
However you can remove the entry from sys.path
.
import sys
import os
sys.path = [p for p in sys.pathif p notin [os.path.abspath(x) for x inos.environ['PYTHONPATH'].split(':')]]
Solution 2:
The easiest way right now seems to be to put write a scripts that restarts Python if the flag is not included:
#!/bin/env pythonimport sys
ifnot sys.flags.ignore_environment:
import os
os.execv(sys.executable, [sys.executable, '-E'] + sys.argv)
# Run your actual script here
Then in setup.py, put this:
setup(..., scripts=['myscript'], ...)
Don't use entry_points/console_scripts. This should not be used for public modules, just for internal scripts.
Post a Comment for "How Do I Get An Installed Script To Ignore Pythonpath"