当 Numpy 和 pip3 安装在 python2.7 时,如何为 python3.x 安装它们?使用康达?

How to install Numpy & pip3 for python3.x when they were installed in python2.7? Using Conda?

我想在 python3 (3.5) 中编写程序,因此我在 Mac [=] 上预安装的 python2 (2.7) 旁边安装了 python3 OS X El Captian.

因为我的终端默认运行 python2.7 并且已经为它安装了 Numpy,所以我输入 alias python=python3 并希望能够为 python3 安装 Numpy。当我输入 pip install numpy 时。这是生成的消息:

Requirement already satisfied (use --upgrade to upgrade): numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

我也注意到我没有 pip3 即使我正在使用 python3:python --version 返回 Python 3.5.2,但是 pip3 install numpy 得到了我 -bash: pip3: command not found

所以我的问题是:
1) 当 Numpy 安装在 python2.x 上时如何为 python3.x 安装 Numpy?
2) 如何获取pip3?
3) 使用 Conda 之类的虚拟环境,而不是在系统上的 python2 和 python3 之间摆弄会更好吗?

感谢总n00b

--------------------更新-----------------

重新安装 python3 还解决了我的另一个问题。
当我 运行 brew doctor 时,我收到的警告消息之一是:

Warning: You have unlinked kegs in your Cellar Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run brew link on these: python –

这是我运行brew unlink python为了修复

的结果

"Python quit unexpectedly"

当我启动 Vim 和

"The ycmd server SHUT DOWN"

两者似乎都与我为 Python 下载的 YouCompleteMe 自动完成插件有关。

我想到了从 here and here
中删除符号链接 但是,Homebrew 显然不喜欢缺少这 39 个符号链接。

按照 Toby 的建议卸载 (brew uninstall python3) 然后重新安装 python3 (brew install python3) 后,Homebrew 给了我

You can install Python packages with  
pip3 install <package>

然后我pip3 install numpypip3 install scipy都执行成功

令我惊讶的是,在 Python 安装期间创建的符号链接曾经导致 Python 和 YouCompleteMe 出现上述错误消息,但现在我使用 Vim 打开 python 文件而不用从全新的 Python 安装中崩溃,这肯定创建了符号链接。

--------------------更新2----------------

重新安装 Anaconda2 后,同样的 YouCompleteMe 错误又回来了。我怀疑 Anaconda 弄乱了符号链接。

Mac 上最简单的方法是使用 Homebrew:

http://brew.sh/

安装 Homebrew,然后 运行:

brew install python3 pip3

编辑 --

Python3 包括 pip3,但 Homebrew 偶尔会遇到链接到正确版本的问题,这取决于已安装的内容。 运行 以下命令:

brew doctor

如果您看到与 python 或未链接的小桶相关的错误,请尝试 运行ning:

brew uninstall python python3

检查brew doctor后重新安装。

https://unix.stackexchange.com/questions/233519/pip3-linked-to-python-framework-instead-of-homebrew-usr-local-bin

我建议使用 Anaconda Python 发行版。

主要原因如下:

  1. 您将拥有一个 Python 发行版,其中包含 numpyScientific Python 堆栈的其余部分。
  2. Anaconda Python 将安装在您的主目录下,无需 sudo-ing 来安装其他软件包。
  3. conda install [put_packagename_here]pip install [put_packagename_here] 一起工作; conda install多'cleaner'(恕我直言,欢迎不同意见)
  4. 如果您的默认环境是 Python 3,那么 pip 开箱即用,无需记住执行 pip3.
  5. 在我看来,
  6. conda environmentsvirtualenv 环境更易于管理。是的,您可以将 Python 2 与 Python 3.
  7. 我曾经搞砸了我的系统 Python 环境 - 我的 Mac 附带的环境 - 它破坏了 iPhoto(在当天)。从那时起,我开始相信不同的项目需要独立的原子环境。

我在 personal blog post 中详细说明了更多原因。

当然,其他发行版都很好,只要它们能满足您的需求:)。