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
|
.. _installing-astropy:
************
Installation
************
Overview
========
The first step to installing ``astropy`` is to ensure that you have a Python
environment which is **isolated** from your system Python installation. This is
important because ``astropy`` has many dependencies, and you do not want to accidentally
break your system by installing incompatible versions of these dependencies.
For this installation guide we use the `conda <https://docs.conda.io/en/latest/>`_
package manager provided by `miniforge <https://github.com/conda-forge/miniforge>`_.
This is a popular choice and works well, especially for newcomers. It is easy to install
and use on all platforms and it makes it easy to install the latest Python version. If
you already have a ``miniforge``-based Python environment then you can skip to
:ref:`installing-astropy-with-pip`.
Another option for more experienced users is a virtual environment manager such as the
Python standard library `venv <https://docs.python.org/3/library/venv.html>`_ module.
There are numerous resources available to help you set up a virtual environment in this
manner if you choose this option.
.. note::
We **do not recommend** using ``astropy`` with an existing `miniconda
<https://docs.anaconda.com/miniconda/>`_ or `Anaconda Python
<https://www.anaconda.com/download/>`_ distribution. The ``astropy`` package provided
by Anaconda Inc. in the ``defaults`` channel can be outdated and these distributions
can require a license for use at a large organisation. Instead, use ``miniforge`` as
described below.
Once you have a Python environment set up, you will install ``astropy`` using |pip| or
|conda|. Here we document using |pip| because it is easier to install the optional
dependencies, but feel free to use |conda| if you prefer.
Install ``miniforge``
=====================
You will install Python by first installing `miniforge
<https://github.com/conda-forge/miniforge/#miniforge>`__. This provides the `conda
package manager <https://docs.conda.io/en/latest/>`_ with the default remote package
repository set to the community-led `conda-forge <https://conda-forge.org>`_ channel.
In a new terminal (miniforge Prompt on Windows) run ``conda list`` to test that the
install has worked.
Create Python Environment
=========================
To create a new Python environment for ``astropy`` and other packages, start by
launching a terminal (under a UNIX-like system) or the miniforge Prompt (under Windows).
Now we will create and activate a new virtual environment to install ``astropy`` into:
.. code-block:: bash
$ conda create --channel conda-forge --name astropy python
$ conda activate astropy
In this case the environment we have created is named ``astropy`` but you can use any
name you like.
In the future when you make a new terminal, you will need to run ``conda activate
astropy`` to activate this environment.
.. _installing-astropy-with-pip:
Install ``astropy``
===================
You can install ``astropy`` and the rest of your dependencies using either |pip| or
|conda|. Both methods are fully supported and will work well.
.. warning::
Once you have created your base Python environment with |conda|, you should try to
stick with one method for installing new packages in your environment. In particular,
|conda| is not aware of packages installed with |pip| and may overwrite them.
Using pip
---------
To install ``astropy`` and your choice of :ref:`dependencies <astropy-main-req>`, run
one of the following commands::
python -m pip install astropy # Minimum required dependencies
python -m pip install "astropy[recommended]" # Recommended dependencies
python -m pip install "astropy[all]" # All optional dependencies
python -m pip install "astropy[dev_all]" # All optional and test dependencies
In most cases, this will install a pre-compiled version of ``astropy`` (called a
*wheel*). However, if you are installing astropy on an uncommon platform, astropy will be
installed from a source file. In this unusual case you will need a C compiler to be
installed (see `Build from source`_ below) for the installation to succeed.
.. warning:: Do **not** install ``astropy`` or other packages using ``sudo`` or any
elevated privilege.
Using conda
-----------
To install ``astropy`` and the minimal set of required dependencies, run::
conda install --channel conda-forge astropy
Install the recommended dependencies with::
conda install --channel conda-forge scipy matplotlib
Install the optional dependencies with::
conda install --channel conda-forge ipython jupyter dask h5py pyarrow \
beautifulsoup4 html5lib bleach pandas sortedcontainers pytz jplephem mpmath \
asdf-astropy bottleneck fsspec s3fs certifi
Testing
-------
You can test that your newly installed version of ``astropy`` is working via the
`documentation on how to test your installed version of astropy
<https://docs.astropy.org/en/latest/development/testguide.html#running-tests-installed-astropy>`_.
.. _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| |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.
- `ipydatagrid <https://pypi.org/project/ipydatagrid/>`_: Used in
:meth:`astropy.table.Table.show_in_notebook` to display the Astropy table
in Jupyter notebook for ``backend="ipydatagrid"``.
- `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.
- `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 <https://mpmath.org/>`_: Used for the 'kraft-burrows-nousek'
interval in `~astropy.stats.poisson_conf_interval`.
- `asdf-astropy <https://github.com/astropy/asdf-astropy>`_ |minimum_asdf_astropy_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.
Build from Source
=================
If you want to build the code from source, follow the instructions for
:ref:`contributing_environment`. Note that instead of cloning from your fork, you can
choose to clone from the main repository::
git clone https://github.com/astropy/astropy.git
cd astropy
Building the documentation is typically not necessary unless you are
developing code or documentation or do not have internet access, because
the stable, latest, and archived versions of Astropy's documentation are
available at `docs.astropy.org <https://docs.astropy.org>`_ . The process
is described in `Building the Documentation from Source <https://docs.astropy.org/en/latest/development/docguide.html#builddocs>`_.
.. _sourcebuildtest:
Test Source Code Build
----------------------
{% 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 `latest documentation on how to run the tests in a source
checkout of astropy <https://docs.astropy.org/en/latest/install.html#testing-a-source-code-build-of-astropy>`_.
{%endif%}
.. _install_astropy_nightly:
Install Pre-built Development Version
=====================================
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``::
python -m pip install --upgrade --extra-index-url 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).
You can test this installation by running the tests as described in the section
`Running tests on an installed astropy <https://docs.astropy.org/en/latest/development/testguide.html#running-tests-installed-astropy>`_.
|