16

I am not a total newbie but I am trying to install modules for quite a long time and at this point i would like to have a fresh start and install python and all the modules I need so i really understand them. My problem is that some of them import, but most of them install either to the wrong site-packages or dont import maybe because i messed up my system/python. Also I tried the PYTHONPATH and PATH to set this up right, but it never worked.

So my questions are:

  1. Is there a way to ensure I can clean everything up and start from zero ? Ideally this would be without having to set up Mac OSX new.
  2. Is there a way to install all the modules in the correct place (whatever the directory is I dont care, it should just work)?
  3. Is there a good step-by-step description on how installing modules works. And I dont mean just the info to use easy_install, pip install etc, but a way to fully understand what I need to consider, where I need to put them, why these modules are recognized in certain directories, how the system finds them and most important what are the most common pitfalls and how to avoid them.

I also tried Macports and various other similiar ways to install but even if some of them worked and while I am sure that these are really great tools, most I had to hack to work.

So if someone can recommend a good and stable way to install a lot of modules at once, this would be incredibly useful.

Thanks a lot !!!!

And sorry for the long questions.

digit
  • 1,513
  • 5
  • 29
  • 49

3 Answers3

5

Buildout and virtualenv should be what you are looking for.

Buildout helps you configure a python installation and virtualenv allows you to isolate multiple different configurations from each other.

Here's a nice blog post explaining how to use them together.

Also, see this other question: Buildout and Virtualenv

Community
  • 1
  • 1
David K. Hess
  • 16,632
  • 2
  • 49
  • 73
3

You can safely install an up-to-date Python 2 and/or Python 3 on OS X using the python.org installers here. They will coexist with any other Pythons you have installed or that were shipped by Apple with OS X. To install packages, for each Python instance first install Distribute which will install a version-specific easy_install command, i.e. easy_install-2.7 or easy_install-3.2. Many people prefer to use pip to manage packages; you can use easy_install to install a version-specific copy of it. If you want something fancier, you could also install virtualenv but, with the isolation provided by Python framework builds on OS X, that isn't as necessary as on most other platforms.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
-3
  • Is there a way to install all the modules in the correct place?

    Download and untar/gunzip/etc the module source (Most of the modules ares available in gzip form at http://pypi.python.org/pypi), then run configure with --prefix set to the same thing for every install:

        [ 11:06 jon@hozbox.com ~ ]$ ./configure --prefix=/usr/local
    

    /usr/local is usually the default, but it doesn't hurt to specify it and will ensure that every module you install will be placed in /usr/local/lib/python/...

  • Is there a good step-by-step description on how installing modules works?

    The Python website has a great page called: Installing Python Modules


http://pypi.python.org/pypi
http://docs.python.org/install/index.html

keturn
  • 4,780
  • 3
  • 29
  • 40
chown
  • 51,908
  • 16
  • 134
  • 170
  • 2
    Python is not installed in `/usr/lib` on Mac OS X. Further, you should never remove anything in `/usr/lib` on Mac OS X as it is managed by Apple and could cripple your system. For that matter, you should normally not do that on any Linux system that uses a package manager. – Ned Deily Dec 01 '11 at 19:38
  • @NedDeily Actually `/usr/lib/python2.7` is just a symlink to `/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7` but `/usr/lib/python2.7` is quicker to `cd` to. But your right; for those who are unfamiliar with a *nix filesystem probably should not play around with stuff in `/usr/lib` unless you know exactly what you are doing. – chown Dec 01 '11 at 19:45
  • thanks a lot. I checked and in usr/lib/ and there is only this symlink. And i know the unix file system very well by now. My problem is that python does not recognize my modules in /Library/Python/2.6/site-packages and does in /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6. And i know the difference between PATH and PYTHONPATH and put it on the right path. But it does not recognize it. Everytime i install it installs to the wrong site packages and I copy and paste to the other. And then some of them work. Here i have another question. – digit Dec 02 '11 at 05:40
  • What is a module ? Can I unzip and put it in a sitepackage by copy and paste ? I will try to use the --prefix mentioned above. And if this works I will be happy. Interesting I put the django directory on the pythonpath and it worked. Very confusing :) – digit Dec 02 '11 at 05:40
  • 5
    You will **break your system** if you remove /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7, as those are not just things you've added, but also python's standard library and other things used by programs included with OS X. – keturn Mar 20 '14 at 19:57