python pathing issues

Even though my path in terminal indicates the correct Python it still seems to revert to apples built in Python and it never did that in previous versions


even though this shows in paths /Library/Frameworks/Python.framework/Versions/2.7/bin i have to run mmy sctip by typing this out fully


/Library/Frameworks/Python.framework/Versions/2.7/bin/python Script.py


i noticed every python in the system is sym linked to the new version of Python except usr/bin and i cant change it


any suggestions

MacBook Pro TouchBar and Touch ID, macOS High Sierra (10.13.1)

Posted on Nov 9, 2017 8:21 AM

Reply
1 reply

Nov 9, 2017 10:48 AM in response to fscalzo

All you have to do when wishing to run your Python script against the default system Python (2.7.10) provided by Apple is to ensure that the PYTHONPATH environment variable is unset, and run:


python foo.py


or, if the first line in your script is #!/usr/bin/python and the script is executable:


./foo.py


If you have installed Python from another source, let's say Python 2.7.14 from Python dot org, then its binaries will be in /usr/local/bin, and the required library location is at /Library/Frameworks/Python.framework/Versions/2.7/lib. To use this version of Python, instead of the System Python, you do the following:


set the PYTHONPATH environment variable to "/Library/Frameworks/Python.framework/Versions/2.7/lib" and change the first line of your Python script to:


#!/usr/bin/env python


Now, the script will look at PYTHONPATH, and use Python 2.7.14, instead of the default System Python 2.7.10. If you unset the PYTHONPATH environment variable, then the script will revert to using the System Python 2.7.10.


If however, you installed Python 3.6.3 from Python dot org, then you would have to use the appropriate change in PYTHONPATH for 3.6/lib, and change the first line of the script to #!/usr/bin/env python3.


All of this assumes that your Terminal PATH settings are properly set.


The following Python script will print out the current version of Python:


#!/usr/bin/env python

import platform

import sys

print(platform.python_version())

sys.exit()

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

python pathing issues

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.