2

I have a small python script

#!/usr/bin/env python3

import some_python3_module

def main():
    # do stuff

if __name__ == '__main__':
    main()

and cannot run this script with Python3, since ROS sets the PYTHONPATH variable to some version 2.7.-related locations, meaning Python 3 cannot find any modules in its dist-packages directory. I would like to override this behaviour without having to modify the outside envorinment. That is, I wish to unset PYTHONPATH, but only for this script, and preferably from within it, so that the shebang will still work. Is this possible?

Not sure if this is better suited to superuser.com

5

There is a command line option that suits your needs:

#!/usr/bin/env python3 -E

-E

Ignore all PYTHON* environment variables, e.g. PYTHONPATH and PYTHONHOME, that might be set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.