4

I am kind of annoyed by the installation of modules in python and had a lot of trouble with it, so it would be fantastic to find a good solution for it. Here are my issues:

  1. PYTHONPATH: How can I tell easy_install/Python where to install my packages?

Even though I put: /Library/Python/2.6/site-packages in my .bash_profile

With:

PYTHONPATH="/Library/Python/2.6/site-packages"
export PYTHONPATH

It wont import packages I have there.

On the other site everything I put into:

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

Works. I dont know why and would love to know.

  1. I just install "south" with the command easy_install south and it installed it, guess, right into:

/Library/Python/2.6/site-packages

Now copied "south" Which was installed there (it was in a Folder called: South-0.7.2-py2.6.egg, i just copied south) and pasted it to

/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages

And now I can import it when going to directory of my django project (in which settings.py-Installed Apps I have 'south') and

python manage.py shell

Which according to south is a good indicator that it works.

  1. Can/Do I have to do that for every module? Is there a better elegant way to solve this. Please say there is.

Thanks

DilithiumMatrix
  • 17,795
  • 22
  • 77
  • 119
MacPython
  • 17,901
  • 10
  • 42
  • 48
  • What does *easy_install* do when you remove `PYTHONPATH="/Library/Python/2.6/site-packages" export PYTHONPATH` from your *.bash_profile*? Or to put it the other way: Why did you change the *PYTHONPATH*? – Eike Aug 25 '10 at 14:03
  • I thought I have to add every directory which contains modules of python, django etc. I have multiple pythonpath like the one I posted here. Is this wrong? What is the right way? – MacPython Aug 25 '10 at 14:26
  • See http://stackoverflow.com/questions/4460367/install-python-2-7-1-side-by-side-with-apple-supplied-python – SPRBRN Jan 04 '14 at 22:38

3 Answers3

8

Based on the path (/Library/Frameworks/Python.framework/Versions/2.6) in your question, you appear to have installed an additional Python besides the ones supplied by Apple. That's the standard installation path for the python.org OS X installer.

The trick to getting easy_install to install to the right Python site-packages location is to understand that each Python instance you have needs to have its own copy of easy_install and you need to make sure you are using the right one when you install a package. For OS X 10.5 and 10.6, Apple supplies easy_install commands in /usr/bin for the Pythons it supplies. For example, in 10.6:

$ ls -l /usr/bin/easy_install*
-rwxr-xr-x  2 root  wheel  925 Jun 30  2009 /usr/bin/easy_install*
-rwxr-xr-x  1 root  wheel  421 Jun 30  2009 /usr/bin/easy_install-2.5*
-rwxr-xr-x  1 root  wheel  421 Jun 30  2009 /usr/bin/easy_install-2.6*

They will install into the appropriate locations in /Library/Python/2.x/ which is where the Apple-supplied Pythons look for site-packages by default.

For a python.org Python, the default site-package locations are in /Library/Frameworks/Python.framework/Versions/x.y. Under the appropriate directory there is a lib/pythonx.y/site-packages as you found and also a bin directory. To make the Python there the default, make sure that that bin directory is on your shell PATH and comes before /usr/bin/, so something like:

export PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"

The python.org installers by default try to modify your shell profile files, like .bash_profile, to do this. Then follow the instructions to install either setuptools, which supplies the traditional version of easy_install, or Distribute, the more cutting-edge version of easy_install. You should then see aneasy_install command in the framework bin directory:

$ cd /Library/Frameworks/Python.framework/Versions/2.6
$ ls -l bin/easy_install*
-rwxr-xr-x  1 nad  admin  360 Aug 25 07:30 bin/easy_install*
-rwxr-xr-x  1 nad  admin  368 Aug 25 07:30 bin/easy_install-2.6*

and, if you use it to install packages, they will end up in the right place and everything will be happy.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
  • That was exactly what I needed to understand. Thanks three billion for that. One more question since you seem to be the right person for this. What is the difference between PATH and PYTHONPATH? and can I have multiple PATH..exportPATH AND PYTHONPATH...exportPYTHONPATH? Thanks a lot for that. i am going to favorite my own question if its possible. – MacPython Aug 25 '10 at 14:42
  • Also I just checked I have: export PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}" on my PYTHONPATH. First Position – MacPython Aug 25 '10 at 14:53
  • If I understand your question properly, `PATH` is an environment variable you use to tell the operating system and the shell in what order to search for executable programs at the command line (http://en.wikipedia.org/wiki/PATH_(variable)). `PYTHONPATH` is an environment variable to tell Python additional locations to search for Python modules (http://docs.python.org/using/cmdline.html#envvar-PYTHONPATH). If you set up PATH as described above and use the right `easy_install` to install to the proper default location for the Python in use, you generally don't need to set `PYTHONPATH`. – Ned Deily Aug 25 '10 at 14:55
  • Also, while all of the above discussion was in the context of using `easy_install`, similar considerations apply when installing Python modules *manually*, that is, by using a package's `setup.py` script. The trick again is to ensure you are using the right Python. Under the covers, the hard work is being done by Python's `Distutils` which is what most `setup.py` scripts, `easy_install`, and other higher-level package managers, like `pip`, all rely on. – Ned Deily Aug 25 '10 at 15:00
0

The -d argument to easy_install tells it where to install the module(s).

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • 1
    so like this? easy_install -d /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages – MacPython Aug 25 '10 at 14:06
-1

sudo env ARCHFLAGS="-arch x86_64" easy_install-2.7 lxml worked on Mac OS 10.9. Make sure to qualify the version of python you are using in the easy_install command.

maxko87
  • 2,892
  • 4
  • 28
  • 43