Location of global libraries for Python on Mac?
Asked Answered
D

5

33

I'm fighting with installation SIP for Python on Mac OS X. Finally after compilation and installation when I run console form folder of SIP (locally) I can import sipconfig, but when I`m in other folder I cant - there is no module called sipconfig.

My question is - Where is folder to which I have to copy modules if I want to have them available globally (like "import os"), or how I can check it, because location "/Library/Python/2.6/site-packages/" doesn`t work.

Disunion answered 29/4, 2010 at 23:53 Comment(1)
If /Library/Python/2.6/site-packages doesn't work, then you are probably using a version of Python other than the system Python.Elvyn
N
67

Try checking your python's sys.path list with:

import sys
print(sys.path)
Needham answered 30/4, 2010 at 0:16 Comment(0)
D
32

A simple method I use is to ask a module where it is:

import os
print(os.__file__)
Dingy answered 8/6, 2011 at 12:55 Comment(0)
F
11

/Library/Python/2.6/site-packages/ is indeed the right place (assuming it's Mac OS 10.6 "Snow Leopard" - you didn't mention which).

As @diatoid mentioned, check your system path (and make sure you're actually using Python 2.6 by running python -V).

Fantast answered 8/6, 2011 at 12:52 Comment(0)
T
11

For Python 3.5, It's /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages

Tempura answered 10/7, 2017 at 22:15 Comment(1)
Make sure you aren't using your user Library and use the Macintosh HD Library, this caught me out.Oriana
S
0

You can designate an additional locations when python starts up by setting the environmental variable PYTHONPATH.

If you add to ~/.bashrc or ~/.zscrc (depending on your default shell) something like:

PYTHONPATH=/Library/MyPyhonPackages:/Another/Location; export PYTHONPATH

Then those locations will be added to "sys.path" whenever python starts up.

This will give you additional places to store your own packages or modules.

Serrulate answered 27/1, 2021 at 9:17 Comment(2)
Welcome to the StackOverflow! Your answer is not really relevant to the question.Fulgurant
The reason I added it here was because this is where I landed when looking for how to add locations to the global list and thought this might be useful to others looking for this. I apologise unreservidly if it was not appropriate to do so.Serrulate

© 2022 - 2024 — McMap. All rights reserved.