[英]How to install Numpy & pip3 for python3.x when they were installed in python2.7? Using Conda?
I want to write program in python3 (3.5), hence I installed python3 next to the pre-installed python2 (2.7) on Mac OS X El Captian. 我想用python3(3.5)编写程序,因此在Mac OS X El Captian上预安装的python2(2.7)旁边安装了python3。
Since my terminal runs python2.7 by default and Numpy is already installed for it, I put alias python=python3
and expected to be able to install Numpy for python3. 由于我的终端默认情况下运行python2.7,并且已经为其安装了Numpy,因此我放置了
alias python=python3
并期望能够为python3安装Numpy。 when I type pip install numpy
. 当我输入
pip install numpy
。 This was the generated message: 这是生成的消息:
Requirement already satisfied (use --upgrade to upgrade): numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
I also noticed that I have no pip3
even though I am using python3: python --version
returned Python 3.5.2
, but pip3 install numpy
got me -bash: pip3: command not found
. 我还注意到,即使我使用的是python3,我也没有
pip3
: python --version
返回了Python 3.5.2
,但是pip3 install numpy
让我-bash: pip3: command not found
。
So my questions are: 所以我的问题是:
1) How to install Numpy for python3.x when Numpy is installed on python2.x? 1)当在python2.x上安装了Numpy时,如何为python3.x安装Numpy?
2) How to get pip3? 2)如何获得pip3?
3) Is it better to use virtual environments, such as Conda, instead of juggling between python2 and python3 on the system? 3)使用虚拟环境(例如Conda),而不是在系统上的python2和python3之间玩弄更好?
Thank you from a total n00b 从总n00b谢谢
------------------- Update ------------------- -------------------更新-------------------
Reinstalling python3 also fixed another problem in my case. 重新安装python3还解决了我的另一个问题。
When I ran brew doctor
, one of the warning message I got was: 当我去做
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 –
This is a result of me running brew unlink python
in order to fix 这是我运行
brew unlink python
进行修复的结果
"Python quit unexpectedly"
“ Python意外退出”
when I launch Vim and also 当我启动Vim时
"The ycmd server SHUT DOWN"
“ ycmd服务器关闭”
Both seem to relate to the YouCompleteMe autocomplete plugin which I downloaded for Python. 两者似乎都与我为Python下载的YouCompleteMe自动完成插件有关。
I got my idea of removing symlinks from here and here 我有从这里和这里删除符号链接的想法
However, Homebrew evidently did not like the absence of those 39 symlinks. 但是,Homebrew显然不喜欢缺少这39个符号链接。
After uninstall ( brew uninstall python3
) and then re-install python3 ( brew install python3
) as Toby suggested, Homebrew gave me 卸载后(
brew uninstall python3
),然后按照Toby的建议重新安装python3( brew install python3
),Homebrew给了我
You can install Python packages with
pip3 install <package>
Then when I pip3 install numpy
and pip3 install scipy
, both executed successfully. 然后,当我
pip3 install numpy
和pip3 install scipy
,都成功执行。
To my surprise, symlinks created during Python installation used to cause aforementioned error messages for Python and YouCompleteMe, but now I open python files using Vim without crash from a fresh Python installation, which definitely created the symlinks. 令我惊讶的是,在Python安装过程中创建的符号链接曾经导致Python和YouCompleteMe出现上述错误消息,但是现在我使用Vim打开python文件,而不会因为全新的Python安装而崩溃。
------------------- Update2 ------------------ ------------------- Update2 ------------------
After re-installing Anaconda2, the same YouCompleteMe error came back. 重新安装Anaconda2后,再次出现相同的YouCompleteMe错误。 I suspect Anaconda messed up symlinks.
我怀疑水蟒弄乱了符号链接。
I would recommend using the Anaconda Python distribution. 我建议使用Anaconda Python发行版。
The main reasons are as such: 主要原因如下:
numpy
and the rest of the Scientific Python stack. numpy
和其余的Scientific Python堆栈附带的Python发行版。 sudo
-ing to install other packages. sudo
-ing即可安装其他软件包。 conda install [put_packagename_here]
works alongside pip install [put_packagename_here]
; conda install [put_packagename_here]
与pip install [put_packagename_here]
一起工作; conda install
is much 'cleaner' (IMHO, differing opinions are welcome). conda install
非常“干净”(恕我直言,欢迎有不同意见)。 pip
works out-of-the-box without needing to remember to do pip3
. pip
可以直接使用,而无需记住执行pip3
。 conda environments
are easier to manage than virtualenv
environments, in my opinion. conda environments
相比,是容易管理virtualenv
环境,在我看来。 And yes, you can have Python 2 alongside Python 3. I've detailed more reasons in a personal blog post . 我在个人博客文章中详细说明了更多原因。
Other distributions, of course, are all good, provided they give you what you need :). 当然,其他发行版也都不错,只要它们能满足您的需求:)。
The simplest way on a Mac is with Homebrew: 在Mac上,最简单的方法是使用Homebrew:
http://brew.sh/ http://brew.sh/
Install Homebrew, then run: 安装Homebrew,然后运行:
brew install python3 pip3
Edit -- 编辑-
Python3 includes pip3, but Homebrew occasionally has trouble linking to the correct versions, depending on what has been installed. Python3包含pip3,但是Homebrew有时在链接到正确版本时遇到麻烦,具体取决于安装的版本。 Running the following command:
运行以下命令:
brew doctor
And if you see errors relating to python or unlinked kegs, try running: 如果您看到与python或未链接的小桶有关的错误,请尝试运行:
brew uninstall python python3
And reinstalling after checking brew doctor
. 并在检查
brew doctor
后重新安装。
https://unix.stackexchange.com/questions/233519/pip3-linked-to-python-framework-instead-of-homebrew-usr-local-bin https://unix.stackexchange.com/questions/233519/pip3-linked-to-python-framework-instead-of-homebrew-usr-local-bin
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.