简体   繁体   中英

Mac Python pointing to different site-packages after python upgrade - How do i point all site-packages to correct python version?

I am trying to upgrade my Mac from 2.6 to 2.7 and everything went fine except for some libraries are being used from 2.6 now instead of 2.7, any idea how I can point all the new libraries to 2.7? Basically I am trying to install yolk for 2.7 but it says that its already installed (under 2.6).

$ python
Python 2.7 (r27:82508, Jul  3 2010, 21:12:11) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
[~, kamilski81_macbook@mac]
$ which easy_install
/Library/Frameworks/Python.framework/Versions/2.7/bin/easy_install
[~, kamilski81_macbook@mac]
$ which pip
/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
[~, kamilski81_macbook@mac]
$ which yolk
/Library/Frameworks/Python.framework/Versions/2.6/bin/yolk

From the evidence you present, it appears you have both of the framework bin directories of Python 2.6 and Python 2.7 on your shell search path, $PATH . If you used the python.org installers to install both 2.6 and 2.7, each installer by default modifies your shell startup files to include the bin directory it installed on $PATH . For example:

$ more ~/.bash_profile
[...]

# Setting PATH for MacPython 2.6
# The orginal version is saved in .profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.6/bin:${PATH}"
export PATH

# Setting PATH for Python 2.7
# The orginal version is saved in .profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/2.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

It looks you've done the right thing of installing pip and easy_install in your 2.7 instance. You should be able to use that pip or that easy_install to install yolk for 2.7. There is nothing wrong with having both framework bins on your $PATH ; this is one of the advantages of the Python framework installation scheme for Mac OS X. The files that Python itself installs in those bin directories are generally installed as a versioned file name, like python2.7 , with a symlink to its unversioned name, python . The versioned names will be unique across all of the framework bin directories; which unversioned one is used will depend upon the order in which the bin directories appear in $PATH . For third-party packages with scripts, like yolk , the script name is not automatically versioned so you can end up with a yolk in multiple bin directories if you install it multiple times.

If your end goal is to only have one version of Python, you can modify your shell startup file ( .bash_profile , .profile et al) to remove the references to 2.6. If you want you can delete the 2.6 files in the framework altogether.

If you want to retain both versions of Python and have a yolk command for each, either change your shell $PATH as necessary to ensure the desired version comes first (an awkward solution) or create shell aliases to the absolute paths of the duplicated commands, or create a versioned symlink in each of the framework bin directories:

$ cd /Library/Frameworks/Python.framework/Versions/2.6/bin
$ ln -s yolk yolk2.6
$ cd /Library/Frameworks/Python.framework/Versions/2.7/bin
$ ln -s yolk yolk2.7
$ which yolk2.6
/Library/Frameworks/Python.framework/Versions/2.6/bin/yolk2.6
$ which yolk2.7
/Library/Frameworks/Python.framework/Versions/2.7/bin/yolk2.7

First, verify if yolk isn't installed in Version/2.7/site-packages . If it is not then you need to tell pip which python version to install to:

pip -E /Library/Frameworks/Python.framework/Versions/2.7/bin/python yolk

If it is then it is a problem with you path settings, and need to change the PATH variable appropriately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM