简体   繁体   English

在OS X上安装Python 3.3后出现“找不到命令”错误

[英]“Command not found” error after installing Python 3.3 on OS X

I was using Python 2.7 as it was installed on my Mac by default. 我使用的是Python 2.7,因为它默认安装在Mac上。 I tried to update it to python 3.4. 我试图将其更新为python 3.4。 In the process I deleted 2.7 via the command line. 在此过程中,我通过命令行删除了2.7。 I installed python 3.4 using an installer but I am still getting following error: 我使用安装程序安装了python 3.4,但仍然出现以下错误:

python: Command not found python:找不到命令

I checked and found that this folder does not exist: 我检查发现该文件夹不存在:

/Library/Frameworks/Python.framework/Versions/3.4 /Library/Frameworks/Python.framework/Versions/3.4

I followed the instructions on this website to update Python. 我按照该网站上的说明更新了Python。 Everything went well until step 5 but was unsuccessful for step 6 and 7. 一切顺利,直到第5步,但在第6步和第7步均未成功。

I am in a complete mess as I have deleted the older version, Python 2.7. 我已经陷入混乱,因为我删除了旧版本的Python 2.7。 How can I fix my Python installation to solve the error and use Python 3.4? 如何修复我的Python安装程序以解决错误并使用Python 3.4?

While I agree with the several users who have commented that it's a bad idea to alter or remove the system's Python installation, it looks like the problem here is that you followed the steps given in the linked blog post to upgrade from version 2.x to a more recent version 2.x . 虽然我同意数位评论者的意见,但是更改或删除系统的Python安装是一个坏主意,但这里的问题似乎是您按照链接的博客文章中给出的步骤从2.x升级到较新的版本2.x。 Note where it says (emphasis mine): 注意它说的是什么(强调我的意思):

To read about how to upgrade to Python 3.3, jump to the very bottom of this post. 要了解有关如何升级到Python 3.3的信息,请跳至本文的最底部。

Steps 1 through 7 in the blog post show how to upgrade the system Python from 2.7.1 to 2.7.3. 博客文章中的步骤1至7显示了如何将系统Python从2.7.1升级到2.7.3。 While it would be fine to install them side-by-side instead—leaving you free to alter or delete your version without breaking the system version—you probably wouldn't run into trouble upgrading the system version from patch 1 to patch 3 of the same minor release. 虽然可以并排安装它们(可以不破坏系统版本的情况下随意更改或删除版本)并排安装,但您可能不会遇到将系统版本从补丁1升级到补丁3的麻烦。相同的次要版本。

However, Python 3 is not backwards-compatible with Python 2 . 但是, Python 3与Python 2不向后兼容 If your system version of Python is 2.x, replacing it with version 3.x just won't work; 如果您的Python的系统版本为2.x,则将其替换为3.x版本将无法正常工作; the system depends on having 2.x available. 系统取决于是否有2.x版本。 Note that the section at the bottom of the blog post titled "Updating to Python 3.3" does not remove Python 2.7: 请注意,博客文章底部标题为“更新至Python 3.3”的部分不会删除Python 2.7:

rm -R /System/Library/Frameworks/Python.framework/Versions/3.3
mv /Library/Frameworks/Python.framework/Versions/3.3 /System/Library/Frameworks/Python.framework/Versions

What it does instead is remove any existing installation of the version to be upgraded , in this case Python 3.3, to avoid a Directory not empty error when trying to move the upgraded version into the system folder. 相反,它是删除要升级的版本的所有现有安装(在本例中为Python 3.3),以避免在尝试将升级后的版本移入系统文件夹时出现Directory not empty错误。

You need a working version of Python 2 in your system folder. 您需要在系统文件夹中使用Python 2的有效版本。 If you want to use Python 3, you need a separate installation entirely. 如果要使用Python 3,则完全需要单独安装。 Rather than backtracking the steps of the guide in reverse order, you may be able to simply start again at step 1, but this time download and install Python 2 instead of Python 3, but you will need to make sure you understand what each step does, looking up shell commands if necessary, because it sounds like you've already made some modifications you don't understand in trying to adapt the wrong section to apply to Python 3. 与其以相反的顺序回溯本指南的步骤,您也许可以简单地从步骤1重新开始,但是这次下载并安装Python 2而不是Python 3,但是您需要确保您了解每个步骤的作用。 ,查找shell,如果必要的命令,因为它听起来像你已经做了一些修改,你不要试图去适应错误的部分适用于Python 3的理解。

For example, you might have changed the second command from step 2 from 例如,您可能已将步骤2中的第二条命令更改为

sudo mv /Library/Frameworks/Python.framework/Versions/2.7 /System/Library/Frameworks/Python.framework/Versions

to

sudo mv /Library/Frameworks/Python.framework/Versions/3.4 /System/Library/Frameworks/Python.framework/Versions

when you were trying to use this step to "upgrade" from 2 to 3; 当您尝试使用此步骤从2升级到3时; otherwise, you would have gotten a No such file or directory error. 否则,您将得到“ No such file or directory错误。 If this is the case, you won't have a 2.7 folder to remove in the very first step because you already removed it the first time around and didn't replace it. 在这种情况下,第一步将没有要删除的2.7文件夹,因为您已经是第一次删除该文件夹,并且没有替换过它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM