Ammar Alyousfi
Ammar Alyousfi

Reputation: 4372

The location of standard Python libraries?

It is stated in Python documentation here that:

By default, the libraries are searched in prefix/lib/pythonversion and exec_prefix/lib/pythonversion, where prefix and exec_prefix are installation-dependent directories, both defaulting to /usr/local.

But when I looked into my /usr/local directory, what I found was a folder named python2.7. I did install python3.5 not python2.7 on my device (MacBook mid 2012).

Upvotes: 2

Views: 6884

Answers (3)

user3827206
user3827206

Reputation:

Mac comes with a default Python 2.7 installation. Your installation did not remove python2.7. Probably also the reason why the system libraries are not under usr/local.

Upvotes: 2

GracefulRestart
GracefulRestart

Reputation: 781

You never state how you attempted to install Python 3.5 onto your MacBook, depending on the installation options you used while building the Python source (or the bundle you downloaded) the install location could be different from the defaults. If you provide further details on your installation method, it will be easier to answer all aspects of your question.

As far as I can tell, Apple does not use the installation defaults to provide Python with OSX. On my OSX El Capitan machine, I can see the system Python library at /System/Library/Frameworks/Python.framework/Versions/2.7 and the binary at /usr/bin/python (Python 2.7.x comes preinstalled for all recent versions of OSX).

It looks like the easiest way to get Python 3.5 on Mac is to use MacPython which will install alongside the system version of Python (as you should not alter the default system version of Python or risk breaking OSX). It installs some helper applications into your Finder's Applications directory and installs the library files to /System/Library/Frameworks/Python.framework/Versions/3.5. Since you will have more then one version of Python installed, you would also need to put some effort into making sure your scripts are using the proper version.

If you have a /usr/local/python2.7 directory, that sounds like something that was previously installed by a user. If I remember correctly, OSX does not normally use /usr/local for system software.

Hope that helps

Upvotes: 1

linpingta
linpingta

Reputation: 2620

You could use sys module to find that.

import sys
print sys.path

Ouput like:

['', '/usr/local/lib/python2.7/dist-packages/mccabe-0.3.1-py2.7.egg', ...

Upvotes: 3

Related Questions