Under MS Windows, download the installer
(e.g., python-3.9.5-amd64.exe
)
from www.python.org
and run it, choosing whether to include all
of the optional features (documentation, pip
,
tcl/tk
and IDLE
, the
Python test suite and the py
launcher,
and the default advanced options (associate files, create shortcuts, add to
environment variables).
Under Debian Linux, install the packages python3
and python3-pip
. There is no official Linux equivalent
of the py
launcher for Windows,
but there is an unofficial
python-launcher project
by Brett Cannon which provides a functionally similar py
command. There is no Debian package for it but there are multiple
ways to install it.
Alternatively, one can just use the command python3
instead of py
, or perhaps define an alias
(e.g., alias py='python3'
in .bashrc
).
./script.py
), any syntax errors will cause
it to fail without an error message. To see such messages, it can
be invoked indirectly (e.g., py ./script.py
).
For full traceback messages, the debugger module can be invoked
(e.g., py -m pdb ./script.py
).
pip
:python -m pip install moduleName
pip install moduleName
Under MS Windows it is (may be?) necessary to run the
Command Prompt
as Administrator (right click on
and choose ).
Simple example of using NumPy:
>>> import numpy as np
| |
>>> x1 = np.arange(9.0).reshape((3, 3))
| Create a 3×3 array with range 0 to 8 |
>>> x2 = np.arange(3.0)
| Create a 1-D array with range 0 to 2 |
>>> np.multiply(x1, x2)
| Multiply the arrays and display the result |
array([[ 0., 1., 4.],
| |
[ 0., 4., 10.],
| |
[ 0., 7., 16.]])
| |
>>> exit()
|
True matrix multiplication (as opposed to element-wise multiplication
of arrays) can be invoked using the *
operator with the
matrix data type,
but it is deprecated. The recommended method is to use regular
array objects and
matmul or, more recently, the
@
operator introduced in
Python 3.5 and NumPy 1.10.