user1411900
user1411900

Reputation: 414

Finding Python3 install location

For my project I'd like to be able to dynamically load and use a Python 3 shared library, if one is installed on the system (any version >=3.2). If more than one Python 3 version is installed, it would be nice to know which one is the default (i.e. the one that gets used whenever user types python3 in the terminal).

On Windows, Python install locations can be discovered via the registry, however, I am uncertain if the same can be done on MacOS and Linux. While python3 executable can typically be found on PATH, there seems to be no general way of locating Python's shared library?

Edit: To clarify, I am looking for libpython3.x.so (or libpython3.x.dylib), not the main python executable.

Also, I'd like the discovery method to be portable: it should work on different Linux distros, and for different package managers on MacOS, so saying e.g. "It's in /usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/Python" doesn't cut it.

Upvotes: 1

Views: 3283

Answers (2)

tocode
tocode

Reputation: 125

Have you tried :

''' 
    >>> import sys
    >>> sys.path
'''

That shows lib path.

Upvotes: 0

Cedric Druck
Cedric Druck

Reputation: 1041

In shell on MacOS or Linux, type:

which python and/or which python3 to get your answer

Example on a VM on my machine (under Docker):

uwsgi@08c2ed391dae:/src/psf$ which python
/usr/bin/python
uwsgi@08c2ed391dae:/src/psf$ which python3
/usr/bin/python3

Upvotes: 1

Related Questions