如何删除Mac OS X自带的python版本

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何删除Mac OS X自带的python版本相关的知识,希望对你有一定的参考价值。

千万不要删掉系统自带的版本。。。
如果想搞,请通过brew来安装可以乱搞的python版本。只需要

$ brew install python
# 或者
$ brew install python3

这样通过brew会安装到/usr/local/bin/下,想使用自己安装的版本,把path的先后顺序调整一下,/usr/local/bin放在最前面
$ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

没安装brew的话,还是先装一个吧

ruby-e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
参考技术A   Sublime Text 2 依赖这个路径,所以可能无法启动。
  解决方法:从官方下载Python2.x,安装,然后做一个软链接
  前提:2.6 & 2.7(目前最新)都属于2.x,所以语法方面差别不大。
  [sudo] ln -s /Library/Frameworks/Python.framework/Versions/2.7/Python /System/Library/Frameworks/Python.framework/Versions/2.6/Python

如何在 Mac OS X Lion 上安装 Python 库“gevent”

【中文标题】如何在 Mac OS X Lion 上安装 Python 库“gevent”【英文标题】:How can I install the Python library 'gevent' on Mac OS X Lion 【发布时间】:2011-10-03 01:33:34 【问题描述】:

Python 库 gevent,版本 0.13.6(PyPI 上的当前版本)在 OS X Lion、Python 2.7(可能还有其他版本)上不会 pip install。它在 Snow Leopard 上运行良好。

如何安装这个库?

如果可以使用 pip install 而不是手动或自定义过程来完成,则可以加分,因为这样它可以很好地与自动构建配合使用。

这是我的pip install 输出:

pip install gevent
Downloading/unpacking gevent
  Running setup.py egg_info for package gevent

Requirement already satisfied (use --upgrade to upgrade): greenlet in ./tl_env/lib/python2.7/site-packages (from gevent)
Installing collected packages: gevent
  Running setup.py install for gevent
    building 'gevent.core' extension
    gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c gevent/core.c -o build/temp.macosx-10.6-intel-2.7/gevent/core.o
    In file included from gevent/core.c:225:
    gevent/libevent.h:9:19: error: event.h: No such file or directory
    gevent/libevent.h:38:20: error: evhttp.h: No such file or directory
    gevent/libevent.h:39:19: error: evdns.h: No such file or directory
    gevent/core.c:361: error: field ‘ev’ has incomplete type
    gevent/core.c:741: warning: parameter names (without types) in function declaration
    gevent/core.c: In function ‘__pyx_f_6gevent_4core___event_handler’:
    gevent/core.c:1619: error: ‘EV_READ’ undeclared (first use in this function)
    gevent/core.c:1619: error: (Each undeclared identifier is reported only once
    gevent/core.c:15376: warning: assignment makes pointer from integer without a cast
   [... about 1000 more lines of compiler errors...]
    gevent/core.c:15385: error: dereferencing pointer to incomplete type
    gevent/core.c: In function ‘__pyx_pf_6gevent_4core_4http___init__’:
    gevent/core.c:15559: warning: assignment makes pointer from integer without a cast
    gevent/core.c: At top level:
    gevent/core.c:21272: error: expected ‘)’ before ‘val’
    lipo: can't figure out the architecture type of: /var/folders/s5/t94kn0p10hdgxzx9_9sprpg40000gq/T//cczk54q7.out
    error: command 'gcc-4.2' failed with exit status 1
    Complete output from command /Users/jacob/code/toplevel/tl_env/bin/python -c "import setuptools;__file__='/Users/jacob/code/toplevel/tl_env/build/gevent/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /var/folders/s5/t94kn0p10hdgxzx9_9sprpg40000gq/T/pip-s2hPd3-record/install-record.txt --install-headers /Users/jacob/code/toplevel/tl_env/bin/../include/site/python2.7:
    running install

running build

running build_py

running build_ext

building 'gevent.core' extension

gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c gevent/core.c -o build/temp.macosx-10.6-intel-2.7/gevent/core.o

【问题讨论】:

pypi.python.org/packages/source/g/gevent/gevent-0.13.6.tar.gz 在这里下载。并使用 sudo python setup.py install -I /opt/local/include -L /opt/local/lib 安装。假设您至少通过 Macports 安装了 libevent。 将此作为“不是一个真正的问题”结束是非常无益的。它可能不符合“真实性”的一些抽象标准,但能够找到此页面并阅读提供的答案为我节省了大量时间。 gevent的新版本,目前是1.0beta,在google code上可用,不再依赖libevent。它在 OSX 上安装得很好,虽然你必须下载 sdist 并手动安装,因为它还没有在 PyPI 上。 我知道这是一篇较旧的帖子,但我也发现 ***.com/questions/32417141/… 有助于解决在 OSX 10.10.5 上安装 gevent 的问题。具体来说,使用CFLAGS='-std=c99' pip install gevent 将使用较旧的兼容编译器。新问题本身并不是重复的,但我也不希望人们像我在寻找不相关的解决方案时那样浪费太多时间。 【参考方案1】:

不要发布整个内容!这太多了! 90%的时候,第一个错误就够了……

gevent/libevent.h:9:19:错误:event.h:没有这样的文件或目录

这意味着提供event.h 标头的库未安装。该库名为 libevent (website)。

一般来说,像这样的编译错误是构建脚本中的一个缺陷。构建脚本应该给出一个错误消息,指出 libevent 没有安装,这是一个错误,它没有安装。

从 MacPorts 获取 libevent,然后使用环境变量 CFLAGS 手动告诉编译器在运行 pip 时在哪里可以找到 event.hlibevent

sudo port install libevent
CFLAGS="-I /opt/local/include -L /opt/local/lib" pip install gevent

您也可以使用自制软件安装 libevent:brew install libevent (来自 David Wolever 的评论)

【讨论】:

补充一点:您可以使用 brew install libevent 使用自制软件安装 libevent 根据定义,提出问题的人没有资格判断输出的哪些部分是重要的,因此他们应该始终发布整个内容。否则,重要的细节有时会被忽略。 @Mikael Lepistö:这真的有效吗?没有-L 标志,所以我认为您会收到链接错误。 我和@DietrichEpp 有同样的经历,需要在Lion 上CFLAGS="-I /opt/local/include -L /opt/local/lib" @KristianGlass:既然你确认了我的期望,我就编辑了它。我怀疑 Mikael Lepistö 可能有一些自定义的环境变量或类似的东西。【参考方案2】:
CFLAGS='-std=c99' pip install gevent

查看:Can't install gevent OSX 10.11

在 OS X 10.11 上,clang 使用 c11 作为默认值,因此只需将其转回 c99。

【讨论】:

【参考方案3】:

过了一会儿,我意识到上面提到的 CFLAGS 变量的路径在从端口安装 libevent 时有效,但从 brew 安装时无效。以下对我有用(在 OSX Mavericks 上):

$ brew install libevent
$ export CFLAGS="-I /usr/local/Cellar/libevent/2.0.21/include -L /usr/local/Cellar/libevent/2.0.21/lib"
$ pip install gevent

【讨论】:

希望第二个答案可以接受。最初的答案似乎基于 macports 而不是自制软件。这为我解决了。谢谢。 它设置了 pip 能够构建和安装 gevent 所需的一些 c 编译器标志 (en.wikipedia.org/wiki/CFLAGS)【参考方案4】:

这是我发现的最简单的方法:

使用自制软件安装 libevent

$ brew install libevent

安装 gevent

$ pip install gevent

这是我让它工作的唯一方法。

【讨论】:

我在运行时得到“ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)”:brew install libevent 【参考方案5】:

在雪豹上寻求安装帮助时找到了这个答案,发布这个以防其他人遇到同样的问题。

我通过 macports 安装了 libevent。

导出 CFLAGS=-I/opt/local/include 导出 LDFLAGS=-L/opt/local/lib sudo pip install gevent

【讨论】:

我已经通过 macports 安装了 libevents,但是我在使用这个命令时遇到了同样的错误【参考方案6】:

我通过 brew 安装了 libevent,但它也失败了,工作原理与 Stephen 所做的类似,但指向 brew 默认安装:

CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib pip install gevent

【讨论】:

【参考方案7】:

如果您从源安装所有内容并使用 csh,则以下适用于 mac os 10.9

    下载最新稳定版http://libevent.org/libevent-2.0.21-stable

    ./配置 制作 sudo make install

    虚拟环境

    源 env/bin/activate.csh

    setenv CFLAGS "-I /usr/local/include -L /usr/local/lib"

    pip install gevent

【讨论】:

【参考方案8】:

我使用 virtualenv 和 virtualenv 包装器,所以我希望它是自包含的。我让 gevent 像这样工作:

假设你有虚拟环境设置,那么:

workon my_virtual_env

然后下载 libevent 并针对 virtualenv 安装它。

curl -L -O https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz

tar -xzf libevent-2.0.21-stable.tar.gz
cd libevent-2.0.21-stable
./configure --prefix="$VIRTUAL_ENV"
make && make install

我假设你已经安装了 gcc 5+(我使用 brew)

希望这会有所帮助。

【讨论】:

【参考方案9】:
sudo pip install cython git+git://github.com/gevent/gevent.git#egg=gevent

【讨论】:

考虑描述您的建议以及相同的原因。【参考方案10】:

我正在使用 MacOs High Sierra (10.13.3) 首先我做了: brew install libevent

我将我的 pip 版本升级到 pip-18.0。 然后尝试使用以下内容再次安装:-

pip install gevent

成功了。

【讨论】:

以上是关于如何删除Mac OS X自带的python版本的主要内容,如果未能解决你的问题,请参考以下文章

Mac OS X 如何升级系统自带的 Ruby ?

Mac OS下使用pyenv管理Python版本

如何将Mac OS X10.9下的Python2.7升级到最新的Python3.3

如何将Mac OS X10.10.5下的Python2.7升级到最新的Python3.5

如何在 Mac OS X Lion 上安装 Python 库“gevent”

mac OS X Yosemite (10.10.5) 下 安装vim 7.4笔记