我怎样才能纠正OS X 10.8我的Python / PIP配置?(How can I correc

2019-09-22 16:05发布

我有一个MacBook Pro的运行OS X 10.8,安装的Xcode 4.4。 我最近安装lxml的,但是当我去导入它,我得到了以下内容:

MacBook-Pro:~ jedc$ sudo pip install lxml==2.3.5
Password:
Downloading/unpacking lxml==2.3.5
  Downloading lxml-2.3.5.tar.gz (3.2Mb): 3.2Mb downloaded
  Running setup.py egg_info for package lxml
    Building lxml version 2.3.5.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    warning: no previously-included files found matching '*.py'
Installing collected packages: lxml
  Running setup.py install for lxml
    Building lxml version 2.3.5.
    Building without Cython.
    Using build configuration of libxslt 1.1.26
    building 'lxml.etree' extension
    /usr/bin/cc -fno-strict-aliasing -O3 -w -pipe -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/libxml2 -I/usr/local/Cellar/python/2.7.1/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.4-x86_64-2.7/src/lxml/lxml.etree.o -w -flat_namespace
    /usr/bin/cc -L/usr/local/Cellar/readline/6.1/lib -bundle -undefined dynamic_lookup -L/usr/local/Cellar/readline/6.1/lib build/temp.macosx-10.4-x86_64-2.7/src/lxml/lxml.etree.o -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.4-x86_64-2.7/lxml/etree.so
    building 'lxml.objectify' extension
    /usr/bin/cc -fno-strict-aliasing -O3 -w -pipe -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/usr/include/libxml2 -I/usr/local/Cellar/python/2.7.1/include/python2.7 -c src/lxml/lxml.objectify.c -o build/temp.macosx-10.4-x86_64-2.7/src/lxml/lxml.objectify.o -w -flat_namespace
    /usr/bin/cc -L/usr/local/Cellar/readline/6.1/lib -bundle -undefined dynamic_lookup -L/usr/local/Cellar/readline/6.1/lib build/temp.macosx-10.4-x86_64-2.7/src/lxml/lxml.objectify.o -lxslt -lexslt -lxml2 -lz -lm -o build/lib.macosx-10.4-x86_64-2.7/lxml/objectify.so

Successfully installed lxml
Cleaning up...
MacBook-Pro:~ jedc$ python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named lxml

我已经清楚地得到的东西配置不正确,因为LXML安装成功,但Python不能找到它。 这里的其他信息:

MacBook-Pro:~ jedc$ which python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
MacBook-Pro:~ jedc$ which pip
/usr/local/bin/pip
MacBook-Pro:~ jedc$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/usr/local/go/bin:/Users/jedc/.rvm/bin

而我的〜/ .bash_profile中包含此:

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
export PATH

我被告知,(以前在某些时候)有可能这是我搞砸了通过安装Python的非苹果默认版本。 谁能帮我找出我需要做诊断本,然后解决它?

Answer 1:

你的pip命令安装了一个不同的Python(一个安装在/usr/local/bin ,你会发现,对于/usr/local/bin/python进口工作。

您需要安装PIP seperately你其他的Python(一种在/Library/Frameworks/Python.framework/Versions/2.7/bin/python )到安装有该Python版本LXML。

使用/Library/Frameworks/Python.framework/Versions/2.7/pip以确保正确pip命令是用来安装lxml一旦pip已安装完毕。



文章来源: How can I correct my Python/pip configuration on OS X 10.8?