简体   繁体   English

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

[英]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,我也没有pip3python --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 numpypip3 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: 主要原因如下:

  1. You will have a Python distribution that comes with numpy and the rest of the Scientific Python stack. 您将拥有numpy和其余的Scientific Python堆栈附带的Python发行版。
  2. The Anaconda Python will be installed under your home directory, with no need for sudo -ing to install other packages. Anaconda Python将安装在您的主目录下,而无需sudo -ing即可安装其他软件包。
  3. 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非常“干净”(恕我直言,欢迎有不同意见)。
  4. If you have a Python 3 environment as your default, then pip works out-of-the-box without needing to remember to do pip3 . 如果您将Python 3环境作为默认环境,则pip可以直接使用,而无需记住执行pip3
  5. 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. 是的,您可以将Python 2与Python 3结合使用。
  6. I once messed up my system Python environment - the one that came with my Mac - and it broke iPhoto (back in the day). 我曾经弄乱了我的系统Python环境-我的Mac随附的环境-它破坏了iPhoto(在过去)。 Since then, I became convinced of needing separate, atomic environments for different projects. 从那时起,我深信对于不同的项目需要单独的原子环境。

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.

相关问题 删除 pip 然后在 python3.x 中安装 pip3 - Remove pip and then install pip3 in python3.x 如何将 pip 命令覆盖为 Python3.x 而不是 Python2.7? - How to override the pip command to Python3.x instead of Python2.7? 如果我使用pip3安装了virtualenv,为什么为什么要用Python2.7创建环境? - Why does virtualenv create the environments with Python2.7 if I installed it using pip3? 使用pip python2.7安装python守护程序包 - python2.7 install python daemon package using pip 在 Python2.7 脚本中使用在 Python3.x 中生成的 .npy 数组? - Using .npy arrays generated in Python3.x in Python2.7 scripts? 在 macOS Sierra 中,如何配置 AWS CLI 以使用 Python3.x 而不是操作系统默认的 Python2.7? - In macOS Sierra, How Configure AWS CLI to Use Python3.x Instead of the OS Default Python2.7? 如何在 Ubuntu 20.04 中为 Python2.7 安装 pip - How can I install pip for Python2.7 in Ubuntu 20.04 如何在 Windows10 Path 中使用两个 Python3.x 版本访问 pip3? - How to access pip3 with two Python3.x versions in Windows10 Path? 在centos 6上安装了Python2.7,现在pip指向Python2.7而不是Python版本 - Installed Python2.7 on centos 6 and now pip points to Python2.7 instead of Python version 如何更正pip的路径(python2.7) - how to correct the path of pip (python2.7)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM