Debian Codegraph @

docs/installation.rst

raw
1 .. _installation:
2
3 ==============
4 Installation
5 ==============
6
7 There are two main options for installing Datasette. You can install it directly on to your machine, or you can install it using Docker.
8
9 If you want to start making contributions to the Datasette project by installing a copy that lets you directly modify the code, take a look at our guide to :ref:`devenvironment`.
10
11 .. contents::
12 :local:
13 :class: this-will-duplicate-information-and-it-is-still-useful-here
14
15 .. _installation_basic:
16
17 Basic installation
18 ==================
19
20 .. _installation_datasette_desktop:
21
22 Datasette Desktop for Mac
23 -------------------------
24
25 `Datasette Desktop <https://datasette.io/desktop>`__ is a packaged Mac application which bundles Datasette together with Python and allows you to install and run Datasette directly on your laptop. This is the best option for local installation if you are not comfortable using the command line.
26
27 .. _installation_homebrew:
28
29 Using Homebrew
30 --------------
31
32 If you have a Mac and use `Homebrew <https://brew.sh/>`__, you can install Datasette by running this command in your terminal::
33
34 brew install datasette
35
36 This should install the latest version. You can confirm by running::
37
38 datasette --version
39
40 You can upgrade to the latest Homebrew packaged version using::
41
42 brew upgrade datasette
43
44 Once you have installed Datasette you can install plugins using the following::
45
46 datasette install datasette-vega
47
48 If the latest packaged release of Datasette has not yet been made available through Homebrew, you can upgrade your Homebrew installation in-place using::
49
50 datasette install -U datasette
51
52 .. _installation_pip:
53
54 Using pip
55 ---------
56
57 Datasette requires Python 3.7 or higher. The `Python.org Python For Beginners <https://www.python.org/about/gettingstarted/>`__ page has instructions for getting started.
58
59 You can install Datasette and its dependencies using ``pip``::
60
61 pip install datasette
62
63 You can now run Datasette like so::
64
65 datasette
66
67 .. _installation_advanced:
68
69 Advanced installation options
70 =============================
71
72 .. _installation_pipx:
73
74 Using pipx
75 ----------
76
77 `pipx <https://pipxproject.github.io/pipx/>`__ is a tool for installing Python software with all of its dependencies in an isolated environment, to ensure that they will not conflict with any other installed Python software.
78
79 If you use `Homebrew <https://brew.sh/>`__ on macOS you can install pipx like this::
80
81 brew install pipx
82 pipx ensurepath
83
84 Without Homebrew you can install it like so::
85
86 python3 -m pip install --user pipx
87 python3 -m pipx ensurepath
88
89 The ``pipx ensurepath`` command configures your shell to ensure it can find commands that have been installed by pipx - generally by making sure ``~/.local/bin`` has been added to your ``PATH``.
90
91 Once pipx is installed you can use it to install Datasette like this::
92
93 pipx install datasette
94
95 Then run ``datasette --version`` to confirm that it has been successfully installed.
96
97 Installing plugins using pipx
98 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
100 You can install additional datasette plugins with ``pipx inject`` like so::
101
102 $ pipx inject datasette datasette-json-html
103 injected package datasette-json-html into venv datasette
104 done! ✨ 🌟 ✨
105
106 $ datasette plugins
107 [
108 {
109 "name": "datasette-json-html",
110 "static": false,
111 "templates": false,
112 "version": "0.6"
113 }
114 ]
115
116 Upgrading packages using pipx
117 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
118
119 You can upgrade your pipx installation to the latest release of Datasette using ``pipx upgrade datasette``::
120
121 $ pipx upgrade datasette
122 upgraded package datasette from 0.39 to 0.40 (location: /Users/simon/.local/pipx/venvs/datasette)
123
124 To upgrade a plugin within the pipx environment use ``pipx runpip datasette install -U name-of-plugin`` - like this::
125
126 % datasette plugins
127 [
128 {
129 "name": "datasette-vega",
130 "static": true,
131 "templates": false,
132 "version": "0.6"
133 }
134 ]
135
136 $ pipx runpip datasette install -U datasette-vega
137 Collecting datasette-vega
138 Downloading datasette_vega-0.6.2-py3-none-any.whl (1.8 MB)
139 |████████████████████████████████| 1.8 MB 2.0 MB/s
140 ...
141 Installing collected packages: datasette-vega
142 Attempting uninstall: datasette-vega
143 Found existing installation: datasette-vega 0.6
144 Uninstalling datasette-vega-0.6:
145 Successfully uninstalled datasette-vega-0.6
146 Successfully installed datasette-vega-0.6.2
147
148 $ datasette plugins
149 [
150 {
151 "name": "datasette-vega",
152 "static": true,
153 "templates": false,
154 "version": "0.6.2"
155 }
156 ]
157
158 .. _installation_docker:
159
160 Using Docker
161 ------------
162
163 A Docker image containing the latest release of Datasette is published to Docker
164 Hub here: https://hub.docker.com/r/datasetteproject/datasette/
165
166 If you have Docker installed (for example with `Docker for Mac
167 <https://www.docker.com/docker-mac>`_ on OS X) you can download and run this
168 image like so::
169
170 docker run -p 8001:8001 -v `pwd`:/mnt \
171 datasetteproject/datasette \
172 datasette -p 8001 -h 0.0.0.0 /mnt/fixtures.db
173
174 This will start an instance of Datasette running on your machine's port 8001,
175 serving the ``fixtures.db`` file in your current directory.
176
177 Now visit http://127.0.0.1:8001/ to access Datasette.
178
179 (You can download a copy of ``fixtures.db`` from
180 https://latest.datasette.io/fixtures.db )
181
182 To upgrade to the most recent release of Datasette, run the following::
183
184 docker pull datasetteproject/datasette
185
186 Loading SpatiaLite
187 ~~~~~~~~~~~~~~~~~~
188
189 The ``datasetteproject/datasette`` image includes a recent version of the
190 :ref:`SpatiaLite extension <spatialite>` for SQLite. To load and enable that
191 module, use the following command::
192
193 docker run -p 8001:8001 -v `pwd`:/mnt \
194 datasetteproject/datasette \
195 datasette -p 8001 -h 0.0.0.0 /mnt/fixtures.db \
196 --load-extension=spatialite
197
198 You can confirm that SpatiaLite is successfully loaded by visiting
199 http://127.0.0.1:8001/-/versions
200
201 Installing plugins
202 ~~~~~~~~~~~~~~~~~~
203
204 If you want to install plugins into your local Datasette Docker image you can do
205 so using the following recipe. This will install the plugins and then save a
206 brand new local image called ``datasette-with-plugins``::
207
208 docker run datasetteproject/datasette \
209 pip install datasette-vega
210
211 docker commit $(docker ps -lq) datasette-with-plugins
212
213 You can now run the new custom image like so::
214
215 docker run -p 8001:8001 -v `pwd`:/mnt \
216 datasette-with-plugins \
217 datasette -p 8001 -h 0.0.0.0 /mnt/fixtures.db
218
219 You can confirm that the plugins are installed by visiting
220 http://127.0.0.1:8001/-/plugins
221
222 Some plugins such as `datasette-ripgrep <https://datasette.io/plugins/datasette-ripgrep>`__ may need additional system packages. You can install these by running `apt-get install` inside the container::
223
224 docker run datasette-057a0 bash -c '
225 apt-get update &&
226 apt-get install ripgrep &&
227 pip install datasette-ripgrep'
228
229 docker commit $(docker ps -lq) datasette-with-ripgrep
230
231 .. _installation_extensions:
232
233 A note about extensions
234 =======================
235
236 SQLite supports extensions, such as :ref:`spatialite` for geospatial operations.
237
238 These can be loaded using the ``--load-extension`` argument, like so::
239
240 datasette --load-extension=/usr/local/lib/mod_spatialite.dylib
241
242 Some Python installations do not include support for SQLite extensions. If this is the case you will see the following error when you attempt to load an extension:
243
244 Your Python installation does not have the ability to load SQLite extensions.
245
246 In some cases you may see the following error message instead::
247
248 AttributeError: 'sqlite3.Connection' object has no attribute 'enable_load_extension'
249
250 On macOS the easiest fix for this is to install Datasette using Homebrew::
251
252 brew install datasette
253
254 Use ``which datasette`` to confirm that ``datasette`` will run that version. The output should look something like this::
255
256 /usr/local/opt/datasette/bin/datasette
257
258 If you get a different location here such as ``/Library/Frameworks/Python.framework/Versions/3.10/bin/datasette`` you can run the following command to cause ``datasette`` to execute the Homebrew version instead::
259
260 alias datasette=$(echo $(brew --prefix datasette)/bin/datasette)
261
262 You can undo this operation using::
263
264 unalias datasette
265
266 If you need to run SQLite with extension support for other Python code, you can do so by install Python itself using Homebrew::
267
268 brew install python
269
270 Then executing Python using::
271
272 /usr/local/opt/python@3/libexec/bin/python
273
274 A more convenient way to work with this version of Python may be to use it to create a virtual environment::
275
276 /usr/local/opt/python@3/libexec/bin/python -m venv datasette-venv
277
278 Then activate it like this::
279
280 source datasette-venv/bin/activate
281
282 Now running ``python`` and ``pip`` will work against a version of Python 3 that includes support for SQLite extensions::
283
284 pip install datasette
285 which datasette
286 datasette --version