简体   繁体   中英

Fix multiple python installations

It looks like I have multiple python installations, which are making things difficult -- eg pip will tell me that a package has been installed through pip freeze, but when attempting to use it within a program, I get an error that it does not exist. Here are a few diagnostic tests I've run:

>>> import sys 
>>> sys.executable
'/usr/local/opt/python/bin/python2.7'
>>> sys.exec_prefix
'/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7'
>>> print '\n'.join(sys.path)

/usr/local/lib/python2.7/site-packages/setuptools-15.2-py2.7.egg
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
/Library/Python/2.7/site-packages/ipython-2.1.0-py2.7.egg
/Library/Python/2.7/site-packages/gnureadline-6.3.3-py2.7-macosx-10.9-intel.egg
/Library/Python/2.7/site-packages/pip-6.1.1-py2.7.egg
/Library/Python/2.7/site-packages

As well as checking the path for python and some common tools:

which easy_install
/usr/local/bin/easy_install
which python
/usr/local/bin/python
which pip
/usr/local/bin/pip

How can I fix it, short of doing a clean re-install of OS X?

Edited to add $PATH and .bashrc info:

My $PATH is as follows:

Users/me/workspace/google-cloud-sdk/bin:/usr/local/bin:/Users/me/workspace/google-cloud-sdk/bin:/urs/local/bin:/Users/me/workspace/google-cloud-sdk/bin:/urs/local/bin:/Users/me/workspace/google-cloud-sdk/bin:usr/local/python:usr/bin/python:/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/texbin: No such file or directory

-- the fact that it is returning an error makes me suspect that I've set up my .bash_profile wrong somehow. These are the only modifications I have made:

#Set architecture flags
export ARCHFLAGS="-arch x86_64"

#Ensure user-installed binaries take precedence
export PATH=/usr/local/bin:$PATH

#Load .bashrc if it exists
test -f ~/.bashrc && source ~/.bashrc

# The next line updates PATH for the Google Cloud SDK.
source '/Users/me/workspace/google-cloud-sdk/path.bash.inc'

# The next line enables bash completion for gcloud.
source '/Users/me/workspace/google-cloud-sdk/completion.bash.inc' 

And this is my .bashrc:

# pip should only run if there is a virtualenv currently activated
export PIP_REQUIRE_VIRTUALENV=true
# cache pip-installed packages to avoid re-downloading
export PIP_DOWNLOAD_CACHE=$HOME/.pip/cache

无法找到解决方法,因此最终进行了干净的操作系统安装并建立了新的python开发环境。

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