README.rst 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. Pythran
  2. #######
  3. https://pythran.readthedocs.io
  4. What is it?
  5. -----------
  6. Pythran is an ahead of time compiler for a subset of the Python language, with a
  7. focus on scientific computing. It takes a Python module annotated with a few
  8. interface descriptions and turns it into a native Python module with the same
  9. interface, but (hopefully) faster.
  10. It is meant to efficiently compile **scientific programs**, and takes advantage
  11. of multi-cores and SIMD instruction units.
  12. Until 0.9.5 (included), Pythran was supporting Python 3 and Python 2.7.
  13. It now only supports Python **3**.
  14. Installation
  15. ------------
  16. Pythran sources are hosted on https://github.com/serge-sans-paille/pythran.
  17. Pythran releases are hosted on https://pypi.python.org/pypi/pythran.
  18. Pythran is available on conda-forge on https://anaconda.org/conda-forge/pythran.
  19. Debian/Ubuntu
  20. =============
  21. Using ``pip``
  22. *************
  23. 1. Gather dependencies:
  24. Pythran depends on a few Python modules and several C++ libraries. On a debian-like platform, run::
  25. $> sudo apt-get install libatlas-base-dev
  26. $> sudo apt-get install python-dev python-ply python-numpy
  27. 2. Install with ``pip``::
  28. $> pip install pythran
  29. Using ``mamba`` or ``conda``
  30. ****************************
  31. 1. Using ``mamba`` (https://github.com/conda-forge/miniforge#mambaforge) or ``conda`` (https://github.com/conda-forge/miniforge)
  32. 2. Run::
  33. $> mamba install -c conda-forge pythran
  34. or::
  35. $> conda install -c conda-forge pythran
  36. Mac OSX
  37. =======
  38. Using brew (https://brew.sh/)::
  39. $> pip install pythran
  40. $> brew install openblas
  41. $> printf '[compiler]\nblas=openblas\ninclude_dirs=/usr/local/opt/openblas/include\nlibrary_dirs=/usr/local/opt/openblas/lib' > ~/.pythranrc
  42. Depending on your setup, you may need to add the following to your ``~/.pythranrc`` file::
  43. [compiler]
  44. CXX=g++-4.9
  45. CC=gcc-4.9
  46. ArchLinux
  47. =========
  48. Using ``pacman``::
  49. $> pacman -S python-pythran
  50. Fedora
  51. ======
  52. Using ``dnf``::
  53. $> dnf install pythran
  54. Windows
  55. =======
  56. Windows support is on going and only targets Python 3.5+ with either Visual Studio 2017 or, better, clang-cl::
  57. $> pip install pythran
  58. Note that using ``clang-cl.exe`` is the default setting. It can be changed
  59. through the ``CXX`` and ``CC`` environment variables.
  60. Other Platform
  61. ==============
  62. See MANUAL file.
  63. Basic Usage
  64. -----------
  65. A simple pythran input could be ``dprod.py``
  66. .. code-block:: python
  67. """
  68. Naive dotproduct! Pythran supports numpy.dot
  69. """
  70. #pythran export dprod(int list, int list)
  71. def dprod(l0,l1):
  72. """WoW, generator expression, zip and sum."""
  73. return sum(x * y for x, y in zip(l0, l1))
  74. To turn it into a native module, run::
  75. $> pythran dprod.py
  76. That will generate a native dprod.so that can be imported just like the former
  77. module::
  78. $> python -c 'import dprod' # this imports the native module instead
  79. Documentation
  80. -------------
  81. The user documentation is available in the MANUAL file from the doc directory.
  82. The developer documentation is available in the DEVGUIDE file from the doc
  83. directory. There is also a TUTORIAL file for those who don't like reading
  84. documentation.
  85. The CLI documentation is available from the pythran help command::
  86. $> pythran --help
  87. Some extra developer documentation is also available using pydoc. Beware, this
  88. is the computer science incarnation for the famous Where's Waldo? game::
  89. $> pydoc pythran
  90. $> pydoc pythran.typing
  91. $> pydoc -b # in the browser
  92. Examples
  93. --------
  94. See the ``pythran/tests/cases/`` directory from the sources.
  95. Contact
  96. -------
  97. Praise, flame and cookies:
  98. - pythran@freelists.org -- register at https://www.freelists.org/list/pythran first!
  99. - #pythran on OFTC, https://oftc.net
  100. - serge.guelton@telecom-bretagne.eu
  101. The mailing list archive is available at https://www.freelists.org/archive/pythran/.
  102. Citing
  103. ------
  104. If you need to cite a Pythran paper, feel free to use
  105. .. code-block:: bibtex
  106. @article{guelton2015pythran,
  107. title={Pythran: Enabling static optimization of scientific python programs},
  108. author={Guelton, Serge and Brunet, Pierrick and Amini, Mehdi and Merlini,
  109. Adrien and Corbillon, Xavier and Raynaud, Alan},
  110. journal={Computational Science \& Discovery},
  111. volume={8},
  112. number={1},
  113. pages={014001},
  114. year={2015},
  115. publisher={IOP Publishing}
  116. }
  117. Authors
  118. -------
  119. See AUTHORS file.
  120. License
  121. -------
  122. See LICENSE file.