Python 3.x on python(x,y)?

2019-05-06 23:34发布

问题:

I'm in the process of setting up a Matlab like environment so I downloaded the latest version of python(x,y) with all the modules that come with it and downloaded python 3.4.1. Does python(x,y) not run the latest version of python? I noticed because the python(x,y) shell doesn't auto calculate mathematical operations into floats which I read is a difference between python 2.x and 3.x. Do I just have to wait for a new release of (x,y) or am I missing something here?

回答1:

You can make Python 2 behave the same as Python 3 w.r.t. division with the following command;

from __future__ import division

Imports from __future__ should be the in the top of the file. There is probably a way to auto-load this expression (I know it is possible in IPython) but I'm not familiar with python(x,y).



回答2:

For learning more about Python do the tutorials available via python.org. The latest version of Python3 is recommend.

Since you are in a transition process, take a look at SciPy (http://www.scipy.org) and Sage (http://www.sagemath.org/tour.html). These might be a better fit for the problems you need to solve.

If you do a lot of interactive work at the terminal, take a look at ipython (http://ipython.org).

Regarding the division operator is defaults to integer division in Python2, but will be just normal division in Python3. You can change this by using the -Q flag when starting the interpreter. (Do: python --help) For example:

$ 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
>>> 


回答3:

Having the feeling that the original question is epsecially regarding the python(x,y)-distribution and Python 3 my (long) answer to this is:

I used this distribution for many years and like it. But for me it seems that there are no plans to upgrade it to include a python 3 environment.

These days I would recommend the Anaconda distribution/project (https://www.anaconda.com/). Very similar to the python(x,y)-idea but better maintained and supporting the "latest of everything".