我正在设置一个类似 Matlab 的环境,所以我下载了最新版本的 python(x,y) 以及它附带的所有模块,并下载了 python 3.4.1。python(x,y) 不运行最新版本的 python 吗?我注意到,因为 python(x,y) shell 不会自动将数学运算计算为浮点数,我读到这是 python 2.x 和 3.x 之间的区别。我只需要等待 (x,y) 的新版本还是我在这里遗漏了什么?
3 回答
要了解有关 Python 的更多信息,请参阅 python.org 提供的教程。推荐使用最新版本的 Python3。
由于您处于过渡过程中,请查看 SciPy ( http://www.scipy.org ) 和 Sage ( http://www.sagemath.org/tour.html )。这些可能更适合您需要解决的问题。
如果您在终端上进行大量交互工作,请查看 ipython ( http://ipython.org )。
关于除法运算符在 Python2 中默认为整数除法,但在 Python3 中只是普通除法。您可以在启动解释器时使用 -Q 标志来更改它。(执行:python --help)例如:
$ python2.7 -Qnew
Python 2.7.6 (default, Nov 18 2013, 15:12:51)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0.5
>>>
$ python2.7
Python 2.7.6 (default, Nov 18 2013, 15:12:51)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0
>>>
$ python3.4
Python 3.4.1 (default, May 21 2014, 01:39:38)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 1/2
0.5
>>>
您可以使用以下命令使 Python 2 的行为与 Python 3 wrt 除法相同;
from __future__ import division
Imports from__future__
应该在文件的顶部。可能有一种方法可以自动加载这个表达式(我知道这在 IPython 中是可能的)但我不熟悉 python(x,y)。
感觉最初的问题主要是关于 python(x,y)-distribution 和 Python 3,我对此的(长)回答是:
我使用这个发行版很多年并且喜欢它。但对我来说,似乎没有计划升级它以包含 python 3 环境。
这些天来,我会推荐 Anaconda 发行版/项目(https://www.anaconda.com/)。与 python(x,y)-idea 非常相似,但更好地维护和支持“最新的一切”。