1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
|
************
Installation
************
.. _installing-astropy:
Installing ``astropy``
======================
If you are new to Python and/or do not have familiarity with `Python virtual
environments <https://docs.python.org/3/tutorial/venv.html>`_, then we recommend
starting by installing the `Anaconda Distribution
<https://www.anaconda.com/distribution/>`_. This works on all platforms (linux,
Mac, Windows) and installs a full-featured scientific Python in a user directory
without requiring root permissions.
Using pip
---------
.. warning::
Users of the Anaconda Python distribution should follow the instructions
for :ref:`anaconda_install`.
To install ``astropy`` with `pip`_, run::
pip install astropy
If you want to make sure none of your existing dependencies get upgraded, you
can also do::
pip install astropy --no-deps
On the other hand, if you want to install ``astropy`` along with recommended
or even all of the available optional :ref:`dependencies <astropy-main-req>`,
you can do::
pip install astropy[recommended]
or::
pip install astropy[all]
In most cases, this will install a pre-compiled version (called a *wheel*) of
astropy, but if you are using a very recent version of Python, if a new version
of astropy has just been released, or if you are building astropy for a platform
that is not common, astropy will be installed from a source file. Note that in
this case you will need a C compiler (e.g., ``gcc`` or ``clang``) to be installed
(see `Building from source`_ below) for the installation to succeed.
If you get a ``PermissionError`` this means that you do not have the required
administrative access to install new packages to your Python installation. In
this case you may consider using the ``--user`` option to install the package
into your home directory. You can read more about how to do this in the `pip
documentation <https://pip.pypa.io/en/stable/user_guide/#user-installs>`_.
Alternatively, if you intend to do development on other software that uses
``astropy``, such as an affiliated package, consider installing ``astropy``
into a :ref:`virtualenv <astropy-dev:virtual_envs>`.
Do **not** install ``astropy`` or other third-party packages using ``sudo``
unless you are fully aware of the risks.
.. _anaconda_install:
Using Conda
-----------
To install ``astropy`` using conda run::
conda install astropy
``astropy`` is installed by default with the `Anaconda Distribution
<https://www.anaconda.com/distribution/>`_. To update to the latest version run::
conda update astropy
There may be a delay of a day or two between when a new version of ``astropy``
is released and when a package is available for conda. You can check
for the list of available versions with ``conda search astropy``.
If you want to install ``astropy`` along with recommended or all of the
available optional :ref:`dependencies <astropy-main-req>`, you can do::
conda install -c conda-forge -c defaults scipy matplotlib
or::
conda install -c conda-forge -c defaults scipy matplotlib \
h5py beautifulsoup4 html5lib bleach pandas sortedcontainers \
pytz setuptools mpmath bottleneck jplephem asdf pyarrow
To also be able to run tests (see below) and support :ref:`builddocs` use the
following. We use ``pip`` for these packages to ensure getting the latest
releases which are compatible with the latest ``pytest`` and ``sphinx`` releases::
pip install pytest-astropy sphinx-astropy
.. warning::
Attempting to use `pip <https://pip.pypa.io>`__ to upgrade your installation
of ``astropy`` itself may result in a corrupted installation.
.. _testing_installed_astropy:
Testing an Installed ``astropy``
--------------------------------
{% if is_development %}
The easiest way to test if your installed version of ``astropy`` is running
correctly is to use the :ref:`astropy.test()` function::
import astropy
astropy.test()
The tests should run and print out any failures, which you can report at
the `Astropy issue tracker <https://github.com/astropy/astropy/issues>`_.
This way of running the tests may not work if you do it in the ``astropy`` source
distribution. See :ref:`sourcebuildtest` for how to run the tests from the
source code directory, or :ref:`running-tests` for more details.
{%else%}
See the :ref:`latest documentation on how to test your installed version of
astropy <astropy-dev:testing_installed_astropy>`.
{%endif%}
.. _astropy-main-req:
Requirements
============
``astropy`` has the following strict requirements:
- `Python`_ |minimum_python_version| or later
- `Numpy`_ |minimum_numpy_version| or later
- `PyERFA`_ |minimum_pyerfa_version| or later
- `PyYAML <https://pyyaml.org>`_ |minimum_pyyaml_version| or later
- `packaging`_ |minimum_packaging_version| or later
``astropy`` also depends on a number of other packages for optional features.
The following are particularly recommended:
- `scipy`_ |minimum_scipy_version| or later: To power a variety of features
in several modules.
- `matplotlib <https://matplotlib.org/>`_ |minimum_matplotlib_version| or later: To provide plotting
functionality that `astropy.visualization` enhances.
The further dependencies provide more specific features:
- `h5py <http://www.h5py.org/>`_: To read/write
:class:`~astropy.table.Table` objects from/to HDF5 files.
- `BeautifulSoup <https://www.crummy.com/software/BeautifulSoup/>`_: To read
:class:`~astropy.table.table.Table` objects from HTML files.
- `html5lib <https://html5lib.readthedocs.io/en/stable/>`_: To read
:class:`~astropy.table.table.Table` objects from HTML files using the
`pandas <https://pandas.pydata.org/>`_ reader.
- `bleach <https://bleach.readthedocs.io/>`_: Used to sanitize text when
disabling HTML escaping in the :class:`~astropy.table.Table` HTML writer.
- `xmllint <http://www.xmlsoft.org/>`_: To validate VOTABLE XML files.
This is a command line tool installed outside of Python.
- `pandas <https://pandas.pydata.org/>`_: To convert
:class:`~astropy.table.Table` objects from/to pandas DataFrame objects.
Version 0.14 or higher is required to use the :ref:`table_io_pandas`
I/O functions to read/write :class:`~astropy.table.Table` objects.
- `sortedcontainers <https://pypi.org/project/sortedcontainers/>`_ for faster
``SCEngine`` indexing engine with ``Table``, although this may still be
slower in some cases than the default indexing engine.
- `pytz <https://pythonhosted.org/pytz/>`_: To specify and convert between
timezones.
- `jplephem <https://pypi.org/project/jplephem/>`_: To retrieve JPL
ephemeris of Solar System objects.
- `setuptools <https://setuptools.readthedocs.io>`_: Used for discovery of
entry points which are used to insert fitters into `astropy.modeling.fitting`.
- `mpmath <http://mpmath.org/>`_: Used for the 'kraft-burrows-nousek'
interval in `~astropy.stats.poisson_conf_interval`.
- `asdf <https://github.com/spacetelescope/asdf>`_ |minimum_asdf_version| or later: Enables the
serialization of various Astropy classes into a portable, hierarchical,
human-readable representation.
- `bottleneck <https://pypi.org/project/Bottleneck/>`_: Improves the performance
of sigma-clipping and other functionality that may require computing
statistics on arrays with NaN values.
- `certifi <https://pypi.org/project/certifi/>`_: Useful when downloading
files from HTTPS or FTP+TLS sites in case Python is not able to locate
up-to-date root CA certificates on your system; this package is usually
already included in many Python installations (e.g., as a dependency of
the ``requests`` package).
- `pyarrow <https://arrow.apache.org/docs/python/>`_ |minimum_pyarrow_version| or later:
To read/write :class:`~astropy.table.Table` objects from/to Parquet files.
- `fsspec`_ |minimum_fsspec_version| or later: Enables access to :ref:`subsets
of remote FITS files <fits_io_cloud>` without having to download the entire file.
- `s3fs`_ |minimum_s3fs_version| or later: Enables access to files hosted in
AWS S3 cloud storage.
However, note that these packages require installation only if those particular
features are needed. ``astropy`` will import even if these dependencies are not
installed.
The following packages can optionally be used when testing:
- `pytest-astropy`_: See :ref:`sourcebuildtest`
- `pytest-xdist <https://pypi.org/project/pytest-xdist/>`_: Used for
distributed testing.
- `pytest-mpl <https://github.com/matplotlib/pytest-mpl>`_: Used for testing
with Matplotlib figures.
- `objgraph <https://mg.pov.lt/objgraph/>`_: Used only in tests to test for reference leaks.
- `IPython`_ |minimum_ipython_version| or later:
Used for testing the notebook interface of `~astropy.table.Table`.
- `coverage <https://coverage.readthedocs.io/>`_: Used for code coverage
measurements.
- `skyfield <https://rhodesmill.org/skyfield/>`_: Used for testing Solar System
coordinates.
- `sgp4 <https://pypi.org/project/sgp4/>`_: Used for testing satellite positions.
- `tox <https://tox.readthedocs.io/en/latest/>`_: Used to automate testing
and documentation builds.
Building from Source
====================
Prerequisites
-------------
You will need a compiler suite and the development headers for Python in order
to build ``astropy``. You do not need to install any other specific build
dependencies (such as `Cython <https://cython.org/>`_) since these are
declared in the ``pyproject.toml`` file and will be automatically installed into
a temporary build environment by pip.
Prerequisites for Linux
-----------------------
On Linux, using the package manager for your distribution will usually be the
easiest route to making sure you have the prerequisites to build ``astropy``. In
order to build from source, you will need the Python development
package for your Linux distribution, as well as pip.
For Debian/Ubuntu::
sudo apt-get install python3-dev python3-numpy-dev python3-setuptools cython3 python3-pytest-astropy
For Fedora/RHEL::
sudo yum install python3-devel python3-numpy python3-setuptools python3-Cython python3-pytest-astropy
.. note:: Building the developer version of ``astropy`` may require
newer versions of the above packages than are available in
your distribution's repository. If so, you could either try
a more up-to-date distribution (such as Debian ``testing``),
or install more up-to-date versions of the packages using
``pip`` or ``conda`` in a virtual environment.
Prerequisites for Mac OS X
--------------------------
On MacOS X you will need the XCode command line tools which can be installed
using::
xcode-select --install
Follow the onscreen instructions to install the command line tools required.
Note that you do **not** need to install the full XCode distribution (assuming
you are using MacOS X 10.9 or later).
The `instructions for building NumPy from source
<https://numpy.org/doc/stable/user/building.html>`_ are a good
resource for setting up your environment to build Python packages.
Obtaining the Source Packages
-----------------------------
Source Packages
^^^^^^^^^^^^^^^
The latest stable source package for ``astropy`` can be `downloaded here
<https://pypi.org/project/astropy>`_.
Development Repository
^^^^^^^^^^^^^^^^^^^^^^
The latest development version of ``astropy`` can be cloned from GitHub
using this command::
git clone https://github.com/astropy/astropy.git
If you wish to participate in the development of ``astropy``, see the
:ref:`developer-docs`. The present document covers only the basics necessary to
installing ``astropy``.
Building and Installing
-----------------------
To build and install ``astropy`` (from the root of the source tree)::
pip install .
If you install in this way and you make changes to the code, you will need to
re-run the install command for changes to be reflected. Alternatively, you can
use::
pip install -e .
which installs ``astropy`` in develop/editable mode -- this then means that
changes in the code are immediately reflected in the installed version.
Troubleshooting
---------------
If you get an error mentioning that you do not have the correct permissions to
install ``astropy`` into the default ``site-packages`` directory, you can try
installing with::
pip install . --user
which will install into a default directory in your home directory.
.. _external_c_libraries:
External C Libraries
^^^^^^^^^^^^^^^^^^^^
The ``astropy`` source ships with the C source code of a number of
libraries. By default, these internal copies are used to build
``astropy``. However, if you wish to use the system-wide installation of
one of those libraries, you can set environment variables with the
pattern ``ASTROPY_USE_SYSTEM_???`` to ``1`` when building/installing
the package.
For example, to build ``astropy`` using the system's expat parser
library, use::
ASTROPY_USE_SYSTEM_EXPAT=1 pip install -e .
To build using all of the system libraries, use::
ASTROPY_USE_SYSTEM_ALL=1 pip install -e .
The C libraries currently bundled with ``astropy`` include:
- `wcslib <https://www.atnf.csiro.au/people/mcalabre/WCS/>`_ see
``cextern/wcslib/README`` for the bundled version. To use the
system version, set ``ASTROPY_USE_SYSTEM_WCSLIB=1``.
- `cfitsio <https://heasarc.gsfc.nasa.gov/fitsio/fitsio.html>`_ see
``cextern/cfitsio/changes.txt`` for the bundled version. To use the
system version, set ``ASTROPY_USE_SYSTEM_CFITSIO=1``.
- `expat <https://libexpat.github.io/>`_ see ``cextern/expat/README`` for the
bundled version. To use the system version, set ``ASTROPY_USE_SYSTEM_EXPAT=1``.
.. _install_astropy_nightly:
Installing pre-built Development Versions of ``astropy``
--------------------------------------------------------
Most nights a development snapshot of ``astropy`` will be compiled.
This is useful if you want to test against a development version of astropy but
do not want to have to build it yourselves. You can see the
`available astropy dev snapshots page <https://anaconda.org/astropy/astropy/files?type=pypi>`_
to find out what is currently being offered.
Installing these "nightlies" of ``astropy`` can be achieved by using ``pip``::
$ pip install -U -i https://pypi.anaconda.org/astropy/simple astropy --pre
The extra index URL tells ``pip`` to check the ``pip`` index on
pypi.anaconda.org, where the nightlies are stored, and the ``--pre`` command
tells ``pip`` to install pre-release versions (in this case ``.dev`` releases).
.. _builddocs:
Building Documentation
----------------------
.. note::
Building the documentation is in general not necessary unless you are
writing new documentation or do not have internet access, because
the latest (and archive) versions of Astropy's documentation should
be available at `docs.astropy.org <https://docs.astropy.org>`_ .
Dependencies
^^^^^^^^^^^^
Building the documentation requires the ``astropy`` source code and some
additional packages. The easiest way to build the documentation is to use `tox
<https://tox.readthedocs.io/en/latest/>`_ as detailed in
:ref:`astropy-doc-building`. If you are happy to do this, you can skip the rest
of this section.
On the other hand, if you wish to call Sphinx manually to build the
documentation, you will need to make sure that a number of dependencies are
installed. If you use conda, the easiest way to install the dependencies is
with::
conda install -c conda-forge sphinx-astropy
Without conda, you install the dependencies by specifying ``[docs]`` when
installing ``astropy`` with pip::
pip install -e '.[docs]'
You can alternatively install the `sphinx-astropy
<https://github.com/astropy/sphinx-astropy>`_ package with pip::
pip install sphinx-astropy
In addition to providing configuration common to packages in the Astropy
ecosystem, this package also serves as a way to automatically get the main
dependencies, including:
* `Sphinx <http://www.sphinx-doc.org>`_ - the main package we use to build
the documentation
* `astropy-sphinx-theme <https://github.com/astropy/astropy-sphinx-theme>`_ -
the default 'bootstrap' theme used by ``astropy`` and a number of affiliated
packages
* `sphinx-automodapi <https://sphinx-automodapi.readthedocs.io>`_ - an extension
that makes it easy to automatically generate API documentation
* `sphinx-gallery <https://sphinx-gallery.readthedocs.io/en/latest/>`_ - an
extension to generate example galleries
* `numpydoc`_ - an extension to parse
docstrings in NumPyDoc format
* `pillow <https://pillow.readthedocs.io>`_ - used in one of the examples
* `Graphviz <http://www.graphviz.org>`_ - generate inheritance graphs (available
as a conda package or a system install but not in pip)
.. Note::
Both of the ``pip`` install methods above do not include `Graphviz
<http://www.graphviz.org>`_. If you do not install this package separately
then the documentation build process will produce a very large number of
lengthy warnings (which can obscure bona fide warnings) and also not
generate inheritance graphs.
.. _astropy-doc-building:
Building
^^^^^^^^
There are two ways to build the Astropy documentation. The easiest way is to
execute the following tox command (from the ``astropy`` source directory)::
tox -e build_docs
If you do this, you do not need to install any of the documentation dependencies
as this will be done automatically. The documentation will be built in the
``docs/_build/html`` directory, and can be read by pointing a web browser to
``docs/_build/html/index.html``.
Alternatively, you can do::
cd docs
make html
.. note::
If you have a multi-core processor, and wish to leverage this for building
documentation, you can do so as follows::
cd docs
SPHINXOPTS="-j N" make html
where ``N`` is the number of processes over which to distribute the build, as
described in the `sphinx-build Documentation
<https://www.sphinx-doc.org/en/master/man/sphinx-build.html#cmdoption-sphinx-build-j>`_.
The documentation will be generated in the same location. Note that
this uses the installed version of astropy, so if you want to make sure
the current repository version is used, you will need to install it with
e.g.::
pip install -e .[docs]
before changing to the ``docs`` directory.
In the second way, LaTeX documentation can be generated by using the command::
make latex
The LaTeX file ``Astropy.tex`` will be created in the ``docs/_build/latex``
directory, and can be compiled using ``pdflatex``.
Reporting Issues/Requesting Features
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
As mentioned above, building the documentation depends on a number of Sphinx
extensions and other packages. Since it is not always possible to know which
package is causing issues or would need to have a new feature implemented, you
can open an issue in the `core astropy package issue
tracker <https://github.com/astropy/astropy/issues>`_. However, if you wish, you
can also open issues in the repositories for some of the dependencies:
* For requests/issues related to the appearance of the docs (e.g. related to
the CSS), you can open an issue in the `astropy-sphinx-theme issue tracker
<https://github.com/astropy/astropy-sphinx-theme/issues>`_.
* For requests/issues related to the auto-generated API docs which appear to
be general issues rather than an issue with a specific docstring, you can use
the `sphinx-automodapi issue tracker
<https://github.com/astropy/sphinx-automodapi/issues>`_.
* For issues related to the default configuration (e.g which extensions are
enabled by default), you can use the `sphinx-astropy issue tracker
<https://github.com/astropy/sphinx-astropy/issues>`_.
.. _sourcebuildtest:
Testing a Source Code Build of ``astropy``
------------------------------------------
{% if is_development %}
The easiest way to run the tests in a source checkout of ``astropy``
is to use `tox <https://tox.readthedocs.io/en/latest/>`_::
tox -e test-alldeps
There are also alternative methods of :ref:`running-tests` if you
would like more control over the testing process.
{%else%}
See the :ref:`latest documentation on how to run the tests in a source
checkout of astropy <astropy-dev:sourcebuildtest>`
{%endif%}
|