32

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.

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
michaltaberski
  • 633
  • 1
  • 10
  • 17
  • If /Library/Python/2.6/site-packages doesn't work, then you are probably using a version of Python other than the system Python. – Nicholas Riley May 04 '10 at 03:19

5 Answers5

66

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

import sys
print(sys.path)
Ivelin
  • 12,293
  • 5
  • 37
  • 35
diatoid
  • 1,061
  • 7
  • 4
32

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

import os
print(os.__file__)
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
11

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

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).

Ingmar Hupp
  • 2,409
  • 18
  • 22
-1

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.

  • 1
    Welcome to the StackOverflow! Your answer is not really relevant to the question. – Antigluk Jan 27 '21 at 09:40
  • 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. – Antony Harris Jan 28 '21 at 11:18