Skip to content

Commit 9cc87c2

Browse files
author
Release Manager
committed
gh-37261: `README.md`: Improve PyPI install instructions <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> Based on https://groups.google.com/g/sage-devel/c/1viBzw- ZaoQ/m/ZBbjHXGEAAAJ, we improve the section on installation from PyPI. We also improve **sage_conf** so that `python3 -m sage_conf` is equivalent to `sage-config`. After the next stable release is out, we can use this to simplify these installation instructions. Blocker because we need this to go in the 10.3 stable release. <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #37261 Reported by: Matthias Köppe Reviewer(s):
2 parents cf2fcc8 + 41ad0b5 commit 9cc87c2

File tree

3 files changed

+50
-18
lines changed

3 files changed

+50
-18
lines changed

README.md

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,16 +420,47 @@ in the Installation Guide.
420420
Alternative Installation using PyPI
421421
---------------
422422

423-
For installation of `sage` in python using `pip` you need to install `sagemath-standard`. First, activate your python virtual environment and follow these steps:
423+
For installing Sage in a Python environment from PyPI, Sage provides the
424+
`pip`-installable package [sagemath-standard](https://pypi.org/project/sagemath-standard/).
424425

425-
$ python3 -m pip install sage_conf
426-
$ ls $(sage-config SAGE_SPKG_WHEELS)
427-
$ python3 -m pip install $(sage-config SAGE_SPKG_WHEELS)/*.whl sage_setup
428-
$ python3 -m pip install --no-build-isolation sagemath-standard
426+
Unless you need to install Sage into a specific existing environment, we recommend
427+
to create and activate a fresh virtual environment, for example `~/sage-venv/`:
429428

430-
You need to install `sage_conf`, a wheelhouse of various python packages. You can list the wheels using `ls $(sage-config SAGE_SPKG_WHEELS)`. After manual installation of these wheels, you can install the sage library, `sagemath-standard`.
429+
$ python3 -m venv ~/sage-venv
430+
$ source ~/sage-venv/bin/activate
431431

432-
**NOTE:** You can find `sage` and `sagemath` pip packages but with these packages, you will encounter `ModuleNotFoundError`.
432+
As the first installation step, install [sage_conf](https://pypi.org/project/sage-conf/),
433+
which builds various prerequisite packages in a subdirectory of `~/.sage/`:
434+
435+
(sage-venv) $ python3 -m pip install -v sage_conf
436+
437+
After a successful installation, a wheelhouse provides various Python packages.
438+
You can list the wheels using the command:
439+
440+
(sage-venv) $ ls $(sage-config SAGE_SPKG_WHEELS)
441+
442+
If this gives an error saying that `sage-config` is not found, check any messages
443+
that the `pip install` command may have printed. You may need to adjust your `PATH`,
444+
for example by:
445+
446+
$ export PATH="$(python3 -c 'import sysconfig; print(sysconfig.get_path("scripts", "posix_user"))'):$PATH"
447+
448+
Now install the packages from the wheelhouse and the [sage_setup](https://pypi.org/project/sage-conf/)
449+
package, and finally install the Sage library:
450+
451+
(sage-venv) $ python3 -m pip install $(sage-config SAGE_SPKG_WHEELS)/*.whl sage_setup
452+
(sage-venv) $ python3 -m pip install --no-build-isolation -v sagemath-standard
453+
454+
The above instructions install the latest stable release of Sage.
455+
To install the latest development version instead, add the switch `--pre` to all invocations of
456+
`python3 -m pip install`.
457+
458+
**NOTE:** PyPI has various other `pip`-installable packages with the word "sage" in their names.
459+
Some of them are maintained by the SageMath project, some are provided by SageMath users for
460+
various purposes, and others are entirely unrelated to SageMath. Do not use the packages
461+
`sage` and `sagemath`. For a curated list of packages, see the chapter
462+
[Packages and Features](https://doc.sagemath.org/html/en/reference/spkg/index.html) of the
463+
Sage Reference Manual.
433464

434465
SageMath Docker images
435466
----------------------

pkgs/sage-conf/_sage_conf/__main__.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
# Entry point 'sage-config'. It does not depend on any packages.
22

3-
from sage_conf import *
4-
53
def _main():
64
from argparse import ArgumentParser
75
from sys import exit, stdout
8-
parser = ArgumentParser()
6+
7+
import sage_conf
8+
9+
parser = ArgumentParser(prog='sage-config')
910
parser.add_argument('--version', help="show version", action="version",
10-
version='%(prog)s ' + VERSION)
11+
version='%(prog)s ' + sage_conf.VERSION)
1112
parser.add_argument("VARIABLE", nargs='?', help="output the value of VARIABLE")
1213
args = parser.parse_args()
13-
d = globals()
1414
if args.VARIABLE:
15-
stdout.write('{}\n'.format(d[args.VARIABLE]))
15+
stdout.write('{}\n'.format(getattr(sage_conf, args.VARIABLE)))
1616
else:
17-
for k, v in d.items():
17+
for k in dir(sage_conf):
1818
if not k.startswith('_'):
19-
stdout.write('{}={}\n'.format(k, v))
20-
21-
if __name__ == "__main__":
22-
_main()
19+
stdout.write('{}={}\n'.format(k, getattr(sage_conf, k)))

pkgs/sage-conf/sage_conf.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
from _sage_conf._conf import *
22
from _sage_conf.__main__ import _main
3+
4+
5+
if __name__ == "__main__":
6+
_main()

0 commit comments

Comments
 (0)