gpt4 book ai didi

python - 使用框架式构建安装 Python 时遇到问题 (OS X)

转载 作者:行者123 更新时间:2023-11-30 23:37:29 24 4
gpt4 key购买 nike

在尝试开始学习和开发 python 时,我尝试遵循 Python Guide to installing python on OS X ,但没有发现它特别“新手友好”。我有一台内置 Python 2.7.2 的新 MacBook(Mtn.Lion - OS X 10.8.3)。但该指南建议通过 Homebrew 程序安装“框架式构建”。所以:

  1. 我通过ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"安装了 Homebrew 程序

  2. 然后它会告诉您将 homebrew 添加到 PATH 的顶部,方法是将其添加到 ~/.bashrc 文件中。 ls -a 显示我的主目录中没有 ~/.bashrc 文件。在 Stack Overflow 上搜索如何执行此操作后,我运行了 nano ~/.bashrc,并将行 export PATH=/usr/local/bin:$PATH 插入到文件并保存文件。

  3. 然后我运行 brew install python --framework 并完成安装。

  4. 然后,指南说“将新的 Python 脚本目录添加到您的 PATH”,因此,我假设这意味着我需要将它提供的行添加到我的 >~/.bashrc 文件也是如此。因此,我将 export PATH=/usr/local/share/python:$PATH 添加到我的 ~/.bashrc 文件上方我之前的条目.

  5. 最后,这是我遇到麻烦的地方,它说 easy_install pip。但是,当我这样做时,我得到一个 error 13

所以,这是我需要帮助的事情。

  1. 我关于如何将 Homebrew 程序和 python 脚本添加到我的 PATH 的假设是否正确?

  2. 我是否做错了什么,或者我只需要使用sudo来安装pip?(如果答案已经在this page上,我真的很抱歉但即使这些答案对我来说也不完全有意义,我想小心一 pip ,不要搞砸)

  3. 安装了 python 的框架式构建(我相信是当前的 2.7.3)后,为什么在我的终端中运行 python 仍然显示 v2.7.2?

谢谢!我感谢任何帮助。

最佳答案

I've tried to follow the Python Guide to installing python on OS X, but haven't found it particularly "noob friendly.

是的,我认为这是误导/过时的。

Then it tells you to add homebrew to the top of your PATH by adding it to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc file in my home directory. After searching Stack Overflow on how to do that, I ran nano ~/.bashrc, and inserted the line export PATH=/usr/local/bin:$PATH to the file and saved the file.

在 Mac 上,只需使用 ~/.profile

I then ran brew install python --framework and the install completed.

我认为您不需要 --framework 选项,除非您想替换 Mac OS 默认安装并需要 Mac OS Framework 样式的目录布局。不过不需要替换它,无论如何 Homebrew 安装都会优先。

Then, the guide says to "add the new Python scripts directory to your PATH" so, I'm assuming that means I need to add the line it provides to my ~/.bashrc file also. So, I added export PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my previous entry.

再次在 ~/.profile 中执行此操作。并且不要忘记做一个

source ~/.profile

否则,更改只会在任何新的终端窗口中生效,而不会在您当前使用的终端窗口中生效。

Finally, this is where I run into trouble, it says to easy_install pip. However, when I do that I get an error 13.

该错误表明您尝试将其安装到 Mac OS 系统的默认 Python 库(而不是/usr/local, Homebrew 风格),这需要 root 权限。只是不要。另外,对于 Homebrew python,pip 已经安装。

检查你的路径:

$ which pip
/usr/local/bin/pip
$ ls -l /usr/local/bin/pip
[..] /usr/local/bin/pip -> ../Cellar/python/2.7.3/bin/pip

额外奖励:然后做

pip install virtualenv

并使用它。

对于你的问题:

Was I correct in my assumptions about how to add homebrew and python scripts to my PATH?

是的,但使用 .profile 并随后执行源 .profile

Did I do something wrong or do I just need to use sudo to install pip? (I'm really sorry if the answer is already on this page but even those answers don't make total sense to me and I want to be careful and not screw something up)

Homebrew 程序不需要 sudo,pip 会随 Homebrew 程序 python 自动安装。

After installing the framework-style build of python (which I believe was the current 2.7.3), how come running python in my terminal still shows v2.7.2?

可能 PATH 不正确,请执行 echo $PATH 并检查它是否正确。但这与是否“框架风格”无关。

关于python - 使用框架式构建安装 Python 时遇到问题 (OS X),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15490287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com