MacPorts and the bash PATH

泪湿孤枕 提交于 2021-02-18 08:35:43

问题


I am using 10.8.1 (Mountain Lion).

After upgrading to Mountain Lion, some of my MacPorts stopped working. For an easier life, I simply cleared out /opt/local/ and reinstalled the latest version of MacPorts, followed by the ports themselves.

This has had the side-effect that many of the ports I was using have gone back to their bundled OS X defaults. I opened up .profile to make sure that /opt/local/bin came first in the PATH, but that hasn't solved the problem.

I suspect the output of port select is a symptom:

$ port select python
Available versions for python:
    none (active)  # shouldn't the bundled version be here?
    python27
    python32

$ which python
/usr/bin/python

Changing the active port (sudo port select --set python python27) solves the problem, but not all ports work with port select. Does anyone know what's going on here?

Edit: I should clarify that I don't consider this a complete fix - you're supposed to be able to change back to the Apple version with a command like sudo port select --set python python25-apple, which I suspect I'll only get back by solving the underlying problem.

For the record, the contents of ~/.profile:

export PATH=/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/texbin

回答1:


Without more information, it's hard to guess what behavior you are seeing and what you expect to see. MacPorts does provide port select options for some of the commands you mention like python and ipython but does not yet for pip. In general, MacPorts installs Python scripts with version-specific suffixes, so independent of port select options, you should find those commands with their suffix, for example:

$ port select --list ipython
Available versions for ipython:
    ipython27
    ipython32 (active)
    none
$ which ipython
/opt/local/bin/ipython
$ which ipython-2.7
/opt/local/bin/ipython-2.7
$ port select --list pip
Warning: Unable to get active selected version: The specified group 'pip' does not exist.
Error: The 'list' command failed: The specified group 'pip' does not exist.
$ which pip
$ which pip-2.7
/opt/local/bin/pip-2.7

BTW, neither pip nor ipython are supplied by Apple with OS X system Pythons, so it's not clear what you mean by bundled OS X defaults. Perhaps you installed versions of these to the system Python 2.7. If so, by default, you would see them with /usr/bin/python2.7 and/or installed in /usr/local/bin and /Library/Python/2.7.

Update: Until MacPorts provides a port select pip option (as requested in the MacPorts issue linked above), you should be able to have pip execute the MacPorts version by modifying your .profile to add the Python framework bin directory at the head of the paths:

export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:/opt/local/bin:...

Update 2014-04: MacPorts now does provide a port select pip option so you should no longer need to do the PATH hack.

$ sudo port select pip
Available versions for pip:
    none (active)
    pip27
    pip33
$ sudo port select pip pip27
Selecting 'pip27' for 'pip' succeeded. 'pip27' is now active.
$ hash
$ which pip
/opt/local/bin/pip


来源:https://stackoverflow.com/questions/12557114/macports-and-the-bash-path

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!