[英]Installing Python 3.3 on mac
I used the installer from http://www.python.org/download . 我使用了http://www.python.org/download中的安装程序。 The install appeared successful, and it dropped the Python 3.3 folder in my Applications directory. 安装似乎成功,它删除了我的Applications目录中的Python 3.3文件夹。 I ran the "Update Shell Profile.command" script it contained, and it prepended /Library/Frameworks/Python.framework/Versions/3.3/
to my path. 我运行了它包含的“Update Shell Profile.command”脚本,它将/Library/Frameworks/Python.framework/Versions/3.3/
添加到我的路径中。 Yet the Python
version in that directory appears to be 2.7.5. 然而该目录中的Python
版本似乎是2.7.5。
/Library/Frameworks/Python.framework/Versions/3.3 ls
Headers Python Resources bin include lib share
/Library/Frameworks/Python.framework/Versions/3.3 Python --version
Python 2.7.5
Also, ls /usr/bin | grep python
另外, ls /usr/bin | grep python
ls /usr/bin | grep python
shows: ls /usr/bin | grep python
显示:
python
python-config
python2.5
python2.5-config
python2.6
python2.6-config
python2.7
python2.7-config
pythonw
pythonw2.5
pythonw2.6
pythonw2.7
What have I missed? 我错过了什么?
There are multiple problems here. 这里有很多问题。
First, you should not be running Python
, the framework's executable. 首先,您不应该运行框架的可执行文件Python
。 Framework executables aren't meant to be run, and it's really only a coincidence that this one happens to work. 框架可执行文件并不意味着可以运行,而这恰好只是巧合而已。
Frameworks with programs meant to be run put them in a bin
directory somewhere—either outside the framework (like /usr/local/bin
) or inside it (like /Library/Frameworks/Foo.framework/Versions/XY/bin
). 具有要运行的程序的框架将它们放在某个bin
目录中 - 在框架之外(如/usr/local/bin
)或在其中(如/Library/Frameworks/Foo.framework/Versions/XY/bin
)。 By default, Python 3.3 does the latter. 默认情况下,Python 3.3执行后者。
And the programs inside the bin
directory are all lowercased, not capitalized, so there is no Python
to run. bin
目录中的程序都是小写的,不是大写的,所以没有Python
可以运行。
Next, on Mac, and on almost every other platform in the world besides Windows, the current working directory is not part of your PATH
. 接下来,在Mac上以及除Windows之外的世界上几乎所有其他平台上,当前工作目录不是PATH
一部分。 So, when you type Python --version
, that finds Python
somewhere on the PATH
. 因此,当您键入Python --version
,会在PATH
上的某处找到Python
。 The fact that you happened to have an executable of that name in the current directory doesn't mean anything (except that it's confusing to you). 您碰巧在当前目录中拥有该名称的可执行文件这一事实并不意味着什么(除了它让您感到困惑)。 If you really want to run that file (but again, you really don't), you have to write ./Python
instead. 如果你真的想要运行那个文件(但是你真的没有),你必须编写./Python
。
Also, there is really no good reason to cd
into the framework directory in the first place. 此外,我们实在没有很好的理由cd
到摆在首位的框架目录。 Sure, you could run the file you want, from there, with the appropriate relative pathname: bin/python3
, for example, but you don't want to. 当然,你可以从那里运行你想要的文件,使用适当的相对路径名: bin/python3
,但你不想这样做。
Next, likely you're using a shell you already had running before installing Python 3.3. 接下来,在安装Python 3.3之前,您可能正在使用已运行的shell。 The Update Shell Profile.command
script can be used to add Python 3.3 to the PATH
for all future shells, or to spawn a new shell with that PATH
, but either way it will not affect any existing shells. Update Shell Profile.command
脚本可用于将Python 3.3添加到PATH
以用于所有将来的shell,或者使用该PATH
生成新的shell,但无论哪种方式它都不会影响任何现有的 shell。 To solve that, you just have to start a new shell. 要解决这个问题,你只需要启动一个新的shell。
Next: 下一个:
ls /usr/bin | grep python
ls /usr/bin | grep python
shows:ls /usr/bin | grep python
显示:
The /usr/bin
directory is only for programs that are part of the OS. /usr/bin
目录仅适用于属于OS的程序。 Programs you install yourself go in /usr/local/bin
, or somewhere else on your PATH, instead. 您自己安装的程序将放在/usr/local/bin
或PATH上的其他位置。 The Python installer has an option (although it may be hidden, I can't remember…) to put launchers in /usr/local/bin
. Python安装程序有一个选项(虽然它可能是隐藏的,我不记得了......)将启动器放在/usr/local/bin
。 And it also has an option—which you selected—to put its framework bin
directory onto your PATH
. 它还有一个选项 - 您选择 - 将其框架bin
目录放到PATH
。 But either way, it's never going to put anything in /usr/bin
. 但不管怎样,它永远不会在/usr/bin
放任何东西。
And finally, even after installing Python 3.3, the default python
will still be 2.7. 最后,即使在安装Python 3.3之后,默认的python
仍然是2.7。 python3
and python3.3
will be 3.3, but python
and python2.7
will be 2.7. python3
和python3.3
将是3.3,但python
和python2.7
将是2.7。 See PEP 394 — The "python" Command on Unix-Like Systems for the rationale. 有关基本原理,请参阅PEP 394 - 类Unix系统上的“python”命令 。 But the short version is, there's all kinds of code that depends on Python 2.7 and isn't compatible with 3.3 that may be installed on your system, and you don't want it all to stop working. 但是简短的版本是,各种代码依赖于Python 2.7并且与可能安装在系统上的3.3不兼容,并且您不希望所有代码都停止工作。
So, putting it all together: 所以,把它们放在一起:
python3 --version
. 输入python3 --version
。 You may want to consider using a virtualenv: 您可能需要考虑使用virtualenv:
$ /Library/Frameworks/Python.framework/Versions/3.3/bin/python3 -m venv ~/myvenv
$ source ~/myvenv/bin/activate
(myvenv) $ curl https://bootstrap.pypa.io/get-pip.py | python
(myvenv) $ deactivate
$ source ~/myvenv/bin/activate
http://docs.python-guide.org/en/latest/dev/virtualenvs/ http://docs.python-guide.org/en/latest/dev/virtualenvs/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.