python location on mac osx

前端 未结 12 1820
失恋的感觉
失恋的感觉 2020-11-28 02:02

I\'m a little confused with the python on osx. I do not know if the previous owner of the laptop has installed macpython using macport. And I remembered that osx has an buil

相关标签:
12条回答
  • 2020-11-28 02:41

    i found it here: /Library/Frameworks/Python.framework/Versions/3.6/bin

    0 讨论(0)
  • 2020-11-28 02:43

    Run this in your interactive terminal

    import os
    os.path
    

    It will give you the folder where python is installed

    0 讨论(0)
  • 2020-11-28 02:44

    run the following code in a .py file:

    import sys
    
    print(sys.version)
    print(sys.executable)
    
    0 讨论(0)
  • 2020-11-28 02:46

    This one will solve all your problems dealing with Python on basic shell:

    If you have a Mac and you've installed python3 like most of us do :) (with brew install - ofc)

    your file is located in:

    /usr/local/Cellar/python/3.6.4_4/bin/python3
    

    How do you know? -> you can run this on every basic shell Run:

    which python3
    

    You should get:

    /usr/local/bin/python3
    

    Now this is a symbolic link, how do you know? Run:

    ls -al /usr/local/bin/python3 
    

    and you'll get:

    /usr/local/bin/python3 -> /usr/local/Cellar/python/3.6.4_4/bin/python3
    

    which means that your

    /usr/local/bin/python3 
    

    is actually pointing to:

    /usr/local/Cellar/python/3.6.4_4/bin/python3
    

    If, for some reason, your

    /usr/local/bin/python3 
    

    is not pointing to the place you want, which in our case:

    /usr/local/Cellar/python/3.6.4_4/bin/python3
    

    just backup it:

    cp /usr/local/bin/python3{,.orig} 
    

    and run:

    rm -rf /usr/local/bin/python3
    

    now create a new symbolic link:

    ln -s /usr/local/Cellar/python/3.6.4_4/bin/python3 /usr/local/bin/python3 
    

    and now your

    /usr/local/bin/python3
    

    is pointing to

    /usr/local/Cellar/python/3.6.4_4/bin/python3 
    

    Check it out by running:

    ls -al /usr/local/bin/python3
    
    0 讨论(0)
  • 2020-11-28 02:48

    On Mac OS X, it's in the Python framework in /System/Library/Frameworks/Python.framework/Resources.

    Full path is:

    /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
    

    Btw it's easy to find out where you can find a specific binary: which Python will show you the path of your Python binary (which is probably the same as I posted above).

    0 讨论(0)
  • 2020-11-28 02:48

    I checked a few similar discussions and found out the best way to locate all python2/python3 builds is:

    which -a python python3
    
    0 讨论(0)
提交回复
热议问题