问题
I have three different Python 2.7s at:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
I use a number of packages that come from different sources. I am currently installing packages from port (MacPorts), easy_install, pip (installed by easy_install), and Mercurial. There are also some that I have to install from image or build from source. I have more control over those.
The problem is that easy_install and pip seem to be installing to one location (/Library/Frameworks/...
) and MacPorts installs to another (/opt/local/Library/Frameworks/...
).
What's my best action now? Delete /Library/Frameworks/.../python2.7
and move easy_install and pip to the MacPorts one at /opt/local/...
? Link the two directories? Move the MacPorts installation to /Library/Frameworks/...
?
How can I consolidate these Pythons? I have tried putting both site-packages locations in my path, but only certain packages are available only for one Python and not the other and others vice versa, and I need them all available at once.
回答1:
It seems that you have control over the stuff you're building yourself. This is how I consolidate macports with pip:
I like using Macports for all my stuff, so I just make sure that pip
and easy_install
build into macports' installation of python (the one in /opt/local/...
).
You can tell where pip and easy_install will install things by using:
readlink `which pip`
(those are backticks)
If you want pip to install to the macports direcectories, use macports to install pip:
sudo port install py-pip
Then, be sure that which pip
points to something like:
askewchan@rock:~$ which pip
/opt/local/bin/pip
askewchan@rock:~$ readlink `which pip`
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip-2.7
From the comments below (thanks @Jonathan and @Ned) you can do the same with easy_install
but its port is called py-distribute
:
sudo port install py-distribute
But as far as I know, you never need to use easy_install
because anything that can be easy_installed can be piped better.
Note the port descriptions:
askewchan@rock:Tracking {master *}$ port search *easy*install*
py-pip @1.2.1 (python, www)
An easy_install replacement
askewchan@rock:Tracking {master *}$ port search py*distribute
py-distribute @0.6.35 (python, devel)
Replacement for setuptools
回答2:
I suggest deciding on one and only one Python for your development work ( personally, I use distribution from Python.org )
- You can't get rid of /Library/Frameworks - that's the default OSX one, and you could break things
- of the two remaining Pythons, I'm assuming one is Macports and the other is Python.org -- you need to choose which one you want to be your development env and to stick with that.
I would strongly recommend against using pip
or easy_install
from one Python to install modules for another. The reason is that there can be differences in the compile options. It can be hard enough as-is to get certain packages to compile on OSX properly -- if you start compiling against different binaries ( which might support different architectures ) you're just going to increase your headaches.
I personally chose the following path:
- I use the Python.org package for all development.
- On a terminal login, I run shell scripts to prioritize my Python choice
- All of my projects have their own virtualenv , and I disable system packages
- When starting to work on any project, I tend to have an environment setup script. I just type in
go_myproject.source
; thatcd
s me to the right directory and runs thesource /path/to/virtualenv/bin/activate
to get me set up for that project.
There's a tiny bit of overhead on getting things setup, but I have been in complete heaven ever since. Managing projects and not needing to worry about dependencies/upgrades for one thing killing something else is... blissful.
回答3:
While not a general solution, I install Mercurial and other Python-based applications using virtualenv. In particular, pip and easy_install will install to the respective virtual environment only and not clutter any system folder. The downside is, of course, that I will have duplicates of some packages; the advantage is that I have a clean, self-contained environment with a known version of Python (which for things such as Mercurial and other mission-critical applications is more important for me).
Another downside is that I need to link individual applications to my personal bin directory or add the bin directories of the virtual environments to my path. (Personally, I manage this with some simple scripts that do the symlinking for me.)
回答4:
I sugest to move all python installations to the one place and create symlinks. After that configure python environment to avoid problems with imports and "visibility" of the modules. Try to use commands:
# easy_install
env PYTHONPATH=/custom/path easy_install –install-dir /custom/path
#pip
pip install --install-option="--prefix=$PREFIX_PATH" package_name
来源:https://stackoverflow.com/questions/15368582/for-real-too-many-installations-of-python-on-osx-mountain-lion