Skip to content

Commit d3e09c7

Browse files
weiji14seisman
andauthored
Revise pygmt development installation instructions (#865)
Ensure that users can install the development version of PyGMT without getting a `LookupError`. Also update instructions on installing pygmt from conda/pip. Some changes include: - Added a quickstart section so people can get up and running quicker! - Split some things up into subsections to be clearer - Point out what are recommended or optional steps * Set fallback scm version to 0+unknown Co-authored-by: Dongdong Tian <[email protected]>
1 parent 5b80c64 commit d3e09c7

File tree

2 files changed

+99
-33
lines changed

2 files changed

+99
-33
lines changed

doc/install.rst

Lines changed: 98 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,64 @@ Installing
1414
<https://forum.generic-mapping-tools.org/c/questions/pygmt-q-a>`__.
1515

1616

17+
Quickstart
18+
----------
19+
20+
The fastest way to install PyGMT is with the
21+
`conda <https://docs.conda.io/projects/conda/en/latest/user-guide/index.html>`__
22+
package manager which takes care of setting up a virtual environment, as well
23+
as the installation of GMT and all the dependencies PyGMT depends on::
24+
25+
conda create --name pygmt --channel conda-forge pygmt
26+
27+
To activate the virtual environment, you can do::
28+
29+
conda activate pygmt
30+
31+
After this, check that everything works by running the following in a Python
32+
interpreter (e.g. in a Jupyter notebook)::
33+
34+
import pygmt
35+
pygmt.show_versions()
36+
37+
You are now ready to make you first figure!
38+
Start by looking at the tutorials on our sidebar, good luck!
39+
40+
.. note::
41+
42+
The sections below provide more detailed, step by step instructions to
43+
installing and testing PyGMT for those who may have a slightly different
44+
setup.
45+
1746
Which Python?
1847
-------------
1948

20-
You'll need **Python 3.7 or greater** to run PyGMT. Old Python versions may
21-
work, but there is no guarantee that PyGMT will work as expected with old versions.
49+
PyGMT is tested to run on **Python 3.7 or greater**. Older Python versions may
50+
work, but there is no guarantee that PyGMT will behave as expected.
2251

23-
We recommend using the `Anaconda <https://www.anaconda.com/distribution>`__ Python
24-
distribution to ensure you have all dependencies installed and the ``conda``
25-
package manager available.
52+
We recommend using the `Anaconda <https://www.anaconda.com/distribution>`__
53+
Python distribution to ensure you have all dependencies installed and the
54+
``conda`` package manager available.
2655
Installing Anaconda does not require administrative rights to your computer and
2756
doesn't interfere with any other Python installations in your system.
2857

2958

3059
Which GMT?
3160
----------
3261

33-
PyGMT requires Generic Mapping Tools (GMT) version 6 as a minimum, which is the latest
34-
released version that can be found at
62+
PyGMT requires Generic Mapping Tools (GMT) version 6 as a minimum, which is the
63+
latest released version that can be found at
3564
the `GMT official site <https://www.generic-mapping-tools.org>`__.
36-
We need the latest GMT (>=6.1.1) since there are many changes being made to GMT itself in
37-
response to the development of PyGMT, mainly the new
65+
We need the latest GMT (>=6.1.1) since there are many changes being made to GMT
66+
itself in response to the development of PyGMT, mainly the new
3867
`modern execution mode <https://docs.generic-mapping-tools.org/latest/cookbook/introduction.html#modern-and-classic-mode>`__.
3968

40-
Compiled conda packages of GMT for Linux, macOS and Windows are provided through
41-
`conda-forge <https://anaconda.org/conda-forge/gmt>`__.
69+
Compiled conda packages of GMT for Linux, macOS and Windows are provided
70+
through `conda-forge <https://anaconda.org/conda-forge/gmt>`__.
4271
Advanced users can also
4372
`build GMT from source <https://github.com/GenericMappingTools/gmt/blob/master/BUILDING.md>`__
44-
instead, which is not so recommended but we would love to get feedback from anyone who tries.
73+
instead, which is not so recommended but we would love to get feedback from
74+
anyone who tries.
4575

4676
We recommend following the instructions further on to install GMT 6.
4777

@@ -58,61 +88,97 @@ PyGMT requires the following libraries:
5888

5989
The following are optional (but recommended) dependencies:
6090

61-
* `IPython <https://ipython.org/>`__: For embedding the figures in Jupyter notebooks.
91+
* `IPython <https://ipython.org/>`__: For embedding the figures in Jupyter
92+
notebooks.
6293

6394

6495
Installing GMT and other dependencies
6596
-------------------------------------
6697

67-
Before installing PyGMT, we must install GMT itself along with the other dependencies.
68-
The easiest way to do this is using the ``conda`` package manager.
98+
Before installing PyGMT, we must install GMT itself along with the other
99+
dependencies. The easiest way to do this is via the ``conda`` package manager.
69100
We recommend working in an isolated
70101
`conda environment <https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html>`__
71-
to avoid issues with competing versions of its dependencies.
102+
to avoid issues with conflicting versions of dependencies.
72103

73104
First, we must configure conda to get packages from the
74105
`conda-forge channel <https://conda-forge.org/>`__::
75106

76107
conda config --prepend channels conda-forge
77108

78-
Now we can create a new conda environment with Python and all our dependencies installed
79-
(we'll call it ``pygmt`` but you can change it to whatever you want)::
109+
Now we can create a new conda environment with Python and all our dependencies
110+
installed (we'll call it ``pygmt`` but feel free to change it to whatever you
111+
want)::
80112

81113
conda create --name pygmt python=3.9 pip numpy pandas xarray netcdf4 packaging gmt
82114

83-
Activate the environment by running::
115+
Activate the environment by running the following (**do not forget this step!**)::
84116

85117
conda activate pygmt
86118

87-
From now on, all commands will take place inside the conda virtual environment and won't
88-
affect your default installation.
119+
From now on, all commands will take place inside the conda virtual environment
120+
called 'pygmt' and won't affect your default 'base' installation.
89121

90122

91123
Installing PyGMT
92124
----------------
93125

94-
Now that you have GMT installed and your conda environment activated, you can
95-
use ``conda`` to install the latest release of PyGMT from `conda-forge <https://anaconda.org/conda-forge/pygmt>`__::
126+
Now that you have GMT installed and your conda virtual environment activated,
127+
you can install PyGMT using any of the following methods:
128+
129+
Using conda (recommended)
130+
~~~~~~~~~~~~~~~~~~~~~~~~~
131+
132+
This installs the latest stable release of PyGMT from
133+
`conda-forge <https://anaconda.org/conda-forge/pygmt>`__::
96134

97135
conda install pygmt
98136

99-
or use ``pip`` to install from `PyPI <https://pypi.org/project/pygmt>`__::
137+
Using pip
138+
~~~~~~~~~
139+
140+
This installs the latest stable release from
141+
`PyPI <https://pypi.org/project/pygmt>`__::
100142

101143
pip install pygmt
102144

103-
Alternatively, you can install the development version from the GitHub repository::
145+
Alternatively, you can install the latest development version from
146+
`TestPyPI <https://test.pypi.org/project/pygmt>`__::
147+
148+
pip install --pre --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple pygmt
104149

105-
pip install https://github.com/GenericMappingTools/pygmt/archive/master.zip
150+
or from PyGMT's `GitHub repository <https://github.com/GenericMappingTools/pygmt>`__
151+
(slower as it downloads the whole archive)::
106152

107-
This will allow you to use the ``pygmt`` library from Python.
153+
pip install git+https://github.com/GenericMappingTools/pygmt.git#egg=pygmt
154+
155+
Any of the above methods (conda/pip) should allow you to use the ``pygmt``
156+
library from Python.
108157

109158

110159
Testing your install
111160
--------------------
112161

162+
Quick check
163+
~~~~~~~~~~~
164+
165+
To ensure that PyGMT and its depedencies are installed correctly, run the
166+
following in your Python interpreter::
167+
168+
import pygmt
169+
pygmt.show_versions()
170+
171+
Or run this in the command line::
172+
173+
python -c "import pygmt; pygmt.show_versions()"
174+
175+
176+
Full test (optional)
177+
~~~~~~~~~~~~~~~~~~~~
178+
113179
PyGMT ships with a full test suite.
114-
You can run our tests after you install it but you will need a few extra dependencies as
115-
well (be sure to have your conda env activated)::
180+
You can run our tests after you install it but you will need a few extra
181+
dependencies as well (be sure to have your conda environment activated)::
116182

117183
conda install pytest pytest-mpl ipython
118184

@@ -132,9 +198,9 @@ This can happen if you have multiple versions of GMT installed.
132198

133199
You can tell PyGMT exactly where to look for ``libgmt`` by setting the
134200
``GMT_LIBRARY_PATH`` environment variable.
135-
This should be set to the directory where ``libgmt.so``, ``libgmt.dylib`` or ``gmt.dll``
136-
can be found for Linux, macOS and Windows respectively.
137-
e.g. in a terminal run::
201+
This should be set to the directory where ``libgmt.so``, ``libgmt.dylib`` or
202+
``gmt.dll`` can be found for Linux, macOS and Windows respectively.
203+
e.g. on a command line, run::
138204

139205
# Linux/macOS
140206
export GMT_LIBRARY_PATH=$HOME/anaconda3/envs/pygmt/lib

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
INSTALL_REQUIRES = ["numpy", "pandas", "xarray", "netCDF4", "packaging"]
3737
# Configuration for setuptools-scm
3838
SETUP_REQUIRES = ["setuptools_scm"]
39-
USE_SCM_VERSION = {"local_scheme": "node-and-date"}
39+
USE_SCM_VERSION = {"local_scheme": "node-and-date", "fallback_version": "unknown"}
4040

4141
if __name__ == "__main__":
4242
setup(

0 commit comments

Comments
 (0)