{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "building:index",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "If you are only trying to install NumPy, we recommend using binaries - see "
                },
                {
                  "__type": "Link",
                  "__tag": 4049,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Installation"
                    }
                  ],
                  "url": "https://numpy.org/install",
                  "title": ""
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " for details on that."
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Building NumPy from source requires setting up system-level dependencies (compilers, BLAS/LAPACK libraries, etc.) first, and then invoking a build. The build may be done in order to install NumPy for local usage, develop NumPy itself, or build redistributable binary packages. And it may be desired to customize aspects of how the build is done. This guide will cover all these aspects. In addition, it provides background information on how the NumPy build works, and links to up-to-date guides for generic Python build & packaging documentation that is relevant."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Building from source"
        }
      ],
      "level": 0,
      "target": "building-from-source"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "NumPy uses compiled code for speed, which means you need compilers and some other system-level (i.e, non-Python / non-PyPI) dependencies to build it on your system."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "If you are using Conda, you can skip the steps in this section - with the exception of installing compilers for Windows or the Apple Developer Tools for macOS. All other dependencies will be installed automatically by the "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "mamba env create -f environment.yml"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " command."
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "System-level dependencies"
        }
      ],
      "level": 1,
      "target": "system-level"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If you want to only install NumPy from source once and not do any development work, then the recommended way to build and install is to use "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "pip"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ". Otherwise, conda is recommended."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "note",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "note "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "If you don't have a conda installation yet, we recommend using "
                },
                {
                  "__type": "Link",
                  "__tag": 4049,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Miniforge"
                    }
                  ],
                  "url": "https://github.com/conda-forge/miniforge",
                  "title": ""
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "; any conda flavor will work though."
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Building NumPy from source"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Building from source to use NumPy"
        }
      ],
      "level": 2,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "If you want to build from source in order to work on NumPy itself, first clone the NumPy repository        "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "git clone https://github.com/numpy/numpy.git\ncd numpy\ngit submodule update --init",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Then you want to do the following:"
            }
          ]
        },
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": true,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Create a dedicated development environment (virtual environment or conda    environment),"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Install all needed dependencies ("
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "build"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", and also "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "test"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": ", "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "doc"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " and    "
                    },
                    {
                      "__type": "Emphasis",
                      "__tag": 4047,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "optional"
                        }
                      ]
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " dependencies),"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Build NumPy with the "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "spin"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " developer interface."
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Step (3) is always the same, steps (1) and (2) are different between conda and virtual environments:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To build NumPy in an activated development environment, run      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "spin build",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "This will install NumPy inside the repository (by default in a "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "build-install"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " directory). You can then run tests ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "spin test"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), drop into IPython ("
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "spin ipython"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), or take other development steps like build the html documentation or running benchmarks. The "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "spin"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " interface is self-documenting, so please see "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "spin --help"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " and "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "spin <subcommand> --help"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " for detailed guidance."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "warning",
          "base_type": "warning",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "warning "
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "In an activated conda environment on Windows, the AR, LD, and LDFLAGS environment variables may be set, which will cause the build to fail. These variables are only needed for flang and can be safely unset for build."
                }
              ]
            }
          ]
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "meson-editable-installs"
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "admonition",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "IDE support & editable installs"
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "While the "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "spin"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " interface is our recommended way of working on NumPy, it has one limitation: because of the custom install location, NumPy installed using "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "spin"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " will not be recognized automatically within an IDE (e.g., for running a script via a \"run\" button, or setting breakpoints visually). This will work better with an "
                },
                {
                  "__type": "Emphasis",
                  "__tag": 4047,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "in-place build"
                    }
                  ]
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " (or \"editable install\")."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Editable installs are supported. It is important to understand that "
                },
                {
                  "__type": "Strong",
                  "__tag": 4048,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "you\nmay use either an editable install or"
                    }
                  ]
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "spin"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " "
                },
                {
                  "__type": "Strong",
                  "__tag": 4048,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "in a given repository clone,\nbut not both"
                    }
                  ]
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ". If you use editable installs, you have to use "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "pytest"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " and other development tools directly instead of using "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "spin"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "To use an editable install, ensure you start from a clean repository (run "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "git clean -xdf"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " if you've built with "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "spin"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " before) and have all dependencies set up correctly as described higher up on this page. Then do      "
                }
              ]
            },
            {
              "__type": "Code",
              "__tag": 4050,
              "value": "# Note: the --no-build-isolation is important!\npip install -e . --no-build-isolation\n\n# To run the tests for, e.g., the `numpy.linalg` module:\npytest numpy/linalg",
              "execution_status": null
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "When making changes to NumPy code, including to compiled code, there is no need to manually rebuild or reinstall. NumPy is automatically rebuilt each time NumPy is imported by the Python interpreter; see the "
                },
                {
                  "__type": "Link",
                  "__tag": 4049,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "meson-python"
                    }
                  ],
                  "url": "https://mesonbuild.com/meson-python/",
                  "title": ""
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": " documentation on editable installs for more details on how that works under the hood."
                }
              ]
            },
            {
              "__type": "Paragraph",
              "__tag": 4045,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "When you run "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "git clean -xdf"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": ", which removes the built extension modules, remember to also uninstall NumPy with "
                },
                {
                  "__type": "InlineCode",
                  "__tag": 4051,
                  "value": "pip uninstall numpy"
                },
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "."
                }
              ]
            },
            {
              "__type": "Admonition",
              "__tag": 4056,
              "kind": "warning",
              "base_type": "warning",
              "children": [
                {
                  "__type": "AdmonitionTitle",
                  "__tag": 4055,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "warning "
                    }
                  ]
                },
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": "Note that editable installs are fundamentally incomplete installs. Their only guarantee is that "
                    },
                    {
                      "__type": "InlineCode",
                      "__tag": 4051,
                      "value": "import numpy"
                    },
                    {
                      "__type": "Text",
                      "__tag": 4046,
                      "value": " works - so they are suitable for working on NumPy itself, and for working on pure Python packages that depend on NumPy. Headers, entrypoints, and other such things may not be available from an editable install."
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Building from source for NumPy development"
        }
      ],
      "level": 2,
      "target": "the-spin-interface"
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Compiler selection and customizing a build",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "building:compilers_and_options"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "BLAS and LAPACK",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "building:blas_lapack"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Cross compilation",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "building:cross_compilation"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Building redistributable binaries",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "building:redistributable_binaries"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Customizing builds"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "BulletList",
          "__tag": 4053,
          "ordered": false,
          "start": 1,
          "children": [
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Understanding Meson",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "building:understanding_meson"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Introspecting build steps",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "building:introspecting_a_build"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            },
            {
              "__type": "ListItem",
              "__tag": 4054,
              "children": [
                {
                  "__type": "Paragraph",
                  "__tag": 4045,
                  "children": [
                    {
                      "__type": "CrossRef",
                      "__tag": 4002,
                      "value": "Meson and distutils ways of doing things",
                      "reference": {
                        "__type": "LocalRef",
                        "__tag": 4022,
                        "kind": "docs",
                        "path": "building:distutils_equivalents"
                      },
                      "kind": "exists"
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "Miniforge"
        },
        {
          "__type": "Target",
          "__tag": 4061,
          "label": "meson-python"
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Background information"
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}