Differences between revisions 3 and 17 (spanning 14 versions)
Revision 3 as of 2017-10-05 12:12:25
Size: 8748
Editor: embray
Comment: Just wanted to note that this is being worked on...
Revision 17 as of 2024-03-04 00:22:08
Size: 3981
Editor: mkoeppe
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
= SageMath Windows = = SageMath on Windows =
Line 3: Line 3:
As of SageMath 8.0 a native Windows binary installer is available for 64-bit versions of Windows 7 and up. The latest releases of the Windows installer can be found [[https://github.com/sagemath/sage-windows/releases|here]]. Most users will find this to be better-integrated with their native system than the old [[SageAppliance|VirtualBox appliance]]; however, the appliance is still available for those who prefer it. To run Sage on Windows, use Windows Subsystem for Linux as documented in the [[https://deploy-livedoc--sagemath.netlify.app/html/en/installation/index.html|Sage Installation Guide]].
Line 5: Line 5:
== Installation == ==== Viewing 2D/3D plots from the WSL command line in a Windows browser ====
Line 7: Line 7:
To install Sage on Windows, first download the latest binary release from the [[https://github.com/sagemath/sage-windows/releases|releases on GitHub]] (these may later be placed on the official [[http://www.sagemath.org/mirrors.html|SageMath mirrors]] as well). If you want to use your Windows browser to view 2D/3D plots produced from the Sage command-line in WSL, you will need to first create a small wrapper script to translate a WSL path into a Windows path and open it with the appropriate Windows app:
Line 9: Line 9:
Running the installer currently requires elevated permissions--you must be able to run the installer as Administrator (a pop-up will appear asking if you wish to elevate permissions for the installer, if you are able). This will be possible on most users' personal machines. (In the future a future version of the installer a "single-user" install that does not require Administrator privileges will also be available.)

The installer itself is a typical install wizard which can be completed in a few clicks:

{{attachment:installer1.png}}

The file installation portion can take several minutes, as there are many thousands of files to unpack and the installer is highly compressed--feel free to walk away and get coffee or something:

{{attachment:installer2.png}}

Upon completion you are given the option to install desktop icons, start menu icons, or both. At least one is highly recommended; however, the shortcuts that are installed can also be found in the install location (e.g. `C:\Program Files\SageMath <Version>`).

== Usage ==

A normal installation includes three desktop and/or start menu shortcuts for starting Sage:

{{attachment:icons.png}}

=== SageMath ===

The first, most basic, is labeled simply `SageMath <Version>`. This launches a terminal emulator that goes straight to the standard '''`sage:`''' command-line prompt:

{{attachment:console.png}}

This works just like the '''`sage:`''' prompt on most any other system.

{{{#!wiki note
'''Note'''

Start-up time for the prompt can sometimes take up to a few seconds, especially when starting Sage for the first time. Typically the Sage version banner comes up quickly, but then there is a delay before the '''`sage:`''' prompt appears. Just be patient. Meanwhile, efforts are in progress to reduce start-up time.
{{{#!highlight bash
#!/bin/bash
# wslview_wslpath.sh
wslview $(wslpath -w $1)
Line 41: Line 15:
Commands that output graphics, such as `plot()`, will typically open images in your system's default image viewer: Make sure it is executable. Assuming you placed it in your home folder:
Line 43: Line 17:
{{attachment:console2.png}}

If a default viewer for the file has not been assigned yet in the Windows shell, the standard Windows program selection menu will come up.

{{{#!wiki warning
''Warning''

There is a [[https://github.com/sagemath/sage-windows/issues/2|known issue]] that the console crashes if you click the normal exit icon on the window. Instead, to exit the console, type `exit` and press `Enter`. This will be fixed in a future version.
{{{#!highlight bash
chmod +x /home/<username>/wslview_wslpath.sh
Line 53: Line 21:
=== SageMath Notebook === Now, add the following to your [[https://doc.sagemath.org/html/en/reference/repl/startup.html#the-init-sage-script|init.sage]]:
Line 55: Line 23:
The icon titled `SageMath <Version> Notebook` starts a Jupyter Notebook server with the ability to run notebooks in the Sage kernel (i.e. Sage in Jupyter). Running this shortcut launches a Jupyter server in a terminal window: {{{#!highlight python
# Open 2D/3D plots in Windows browser.
wslview_wslpath = '/home/<username>/wslview_wslpath.sh'
from sage.misc.viewer import viewer
viewer.browser(wslview_wslpath) # for 3D plots
viewer.png_viewer(wslview_wslpath) # for 2D plots
Line 57: Line 30:
{{attachment:notebook.png}} # Uncomment these lines to also open DVIs and PDFs in Windows.
#viewer.dvi_viewer(wslview_wslpath)
#viewer.pdf_viewer(wslview_wslpath)
Line 59: Line 34:
Once the server is running, the Notebook should open in your default browser. If it does not, you can copy and paste the URL from the output in the terminal Window. The URL begins with `http://localhost:8888?token=`. The token portion is important as well on newer versions of Jupyter, as a security measure.

{{{#!wiki important
''Important''

This window ''must'' be kept open in order to keep the Jupyter Notebook server running--it may be minimized, but closing it will shut down the server.

In a future version we hope to be able to run the Notebook server in the background.
# The Windows browser will be unable to access the threejs library installed
# in WSL, so you will need to use the online version of threejs.
sage.plot.plot3d.base.SHOW_DEFAULTS['online'] = True
Line 69: Line 39:
=== SageMath Shell === ==== Launching Jupyter/JupyterLab from WSL in the Windows browser ====
Line 71: Line 41:
This shortcut launches straight into a `bash` shell in the Sage environment (e.g. `sage` and all other software included in the Sage distribution can be run from the command-line) which includes many other common shell utilities. This is generally for more advanced users already accustomed to using Sage in a UNIX-like environment, or those who would like to learn. If you want to launch Jupyter/JupyterLab in your Windows browser, you will need to make a small config change. First, [[https://jupyter-notebook.readthedocs.io/en/stable/config.html|generate a config file]] if you haven't already done so using one of:
Line 73: Line 43:
This environment is based on [[https://www.cygwin.com/|Cygwin]], so all documentation in the [[https://cygwin.com/cygwin-ug-net/cygwin-ug-net.html|Cygwin User's Guide]] is applicable. However, for most common tasks, it is not necessary to know much or anything about Cygwin.

== Caveats ==

=== Optional and pip packages ===

The major known caveat to the current version of the SageMath Windows install is that it is not currently possible to install Sage optional packages. Any attempt to do so will simply fail:

{{{
$ sage -i libhomfly
make: *** No rule to make target 'all-toolchain'. Stop.
{{{#!highlight bash
sage --jupyter notebook --generate-config
sage --jupyter lab --generate-config
Line 86: Line 48:
This is in part because the build toolchain for Sage packages is not included by the installer, and in part because not all optional packages are supported yet. Then, open the config file and make sure the option `use_redirect_file` is set to `False`:
Line 88: Line 50:
Additionally, any attempt to install new Python packages with `pip` will fail with a permission error. E.g.,

{{{
$ pip install surface_dynamics
Collecting surface_dynamics
  Downloading surface_dynamics-0.3.2.tar.gz (11.0MB)
    100% |████████████████████████████████| 11.0MB 113kB/s
Installing collected packages: surface-dynamics
  Running setup.py install for surface-dynamics ... error
    Complete output from command /opt/sagemath-8.0/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-c8xB0d/surface-dynamics/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-q8Gm6v-record/install-record.txt --single-version-externally-managed --compile:
...
    running install_lib
    creating /opt/sagemath-8.0/local/lib/python2.7/site-packages/surface_dynamics
    error: could not create '/opt/sagemath-8.0/local/lib/python2.7/site-packages/surface_dynamics': Permission denied

    ----------------------------------------
Command "/opt/sagemath-8.0/local/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-c8xB0d/surface-dynamics/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-q8Gm6v-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-c8xB0d/surface-dynamics/
{{{#!highlight python
c.NotebookApp.use_redirect_file = False
Line 107: Line 54:
This fails because SageMath is installed as Administrator, so any attempt to change files in the installation or add new ones will fail. It is possible to work around this by right-clicking the SageMath Shell icon and, if available to you, run it with "Run as administrator": === CoCalc ===
Line 109: Line 56:
{{attachment:run-as-admin.png}} [[https://cocalc.com/|CoCalc]] (formerly SageMathCloud) is a collaborative cloud-based computing environment, originally designed for using Sage in the cloud. Through CoCalc you can run Sage either in its command-line interface, or in a Jupyter Notebook, all through your web browser on a cloud-hosted environment, meaning you don't have to install any software (other than a web browser), but that you also need an internet connection.
Line 111: Line 58:
This will allow most `pip install` packages to be installed (however it will do nothing for Sage optional packages since the build toolchain for them is missing). This usage generally works but is not ''supported'', so use at your own risk. CoCalc was originally designed by William Stein, the creator of Sage, to run Sage in the cloud (back when it was called SageMathCloud), but it was quickly realized that all the infrastructure needed to run Sage on the cloud can also be used for a more generic scientific computing environment, which the re-branded CoCalc now provides. You can see some of the software provided by a CoCalc environment [[https://cocalc.com/doc/software.html|here]].
Line 113: Line 60:
In the meantime different optional are being explored for better supporting installation of optional packages. You can create an unlimited account for free, though the free accounts are limited in the amount of disk space they provide, and the amount of RAM they provide. They also do not allow direct internet access from within the CoCalc environment (but you are allowed to upload your data files through the CoCalc interface). See https://cocalc.com/policies/pricing.html for more details. Sometimes William will also provide discounts for specific academic purposes, or for people who are willing to contribute to CoCalc's [[https://github.com/sagemathinc/cocalc|development]], though we cannot speak for him here.
Line 115: Line 62:
=== Hidden files ===

One caveat of both the shell, and other software (such as the Jupyter Notebook file browser) that lists files is that UNIX-based software does not distinguish Windows' notion of "hidden files" from non-hidden files. In other words, files that are "hidden" in the Windows explorer/DOS are visible by default, which can be surprising. In particular, the home directory listing (where the default "home" directory is your Windows user directory; e.g. `C:\Users\<Your Name>`) can contain some clutter you wouldn't normally see in Windows:

{{{
$ ls
 AppData
'Application Data'
 Contacts
 Cookies
 Desktop
 Documents
 dot_sage
 Downloads
 Favorites
 Links
'Local Settings'
 Music
'My Documents'
 NetHood
 NTUSER.DAT
 ntuser.dat.LOG1
 ntuser.dat.LOG2
 NTUSER.DAT{8aa7ab87-923b-11e7-86d1-c4af8d0d0d61}.TM.blf
 NTUSER.DAT{8aa7ab87-923b-11e7-86d1-c4af8d0d0d61}.TMContainer00000000000000000001.regtrans-ms
 NTUSER.DAT{8aa7ab87-923b-11e7-86d1-c4af8d0d0d61}.TMContainer00000000000000000002.regtrans-ms
 ntuser.ini
 OneDrive
 ...
}}}

Examples of this include the `AppData` folder, and the `NTUSER.DAT` files.

We would like to include an alternative `ls` that keeps such files hidden by default, but for now it's best just to ignore this and work around it.
As long as you have reasonably reliable internet connection, CoCalc is a great way to just try out Sage, and other open-source mathematics software, without having to go to the trouble of installing anything on your local machine. However, with a flaky or overloaded internet connection, it can sometimes be slow and frustrating.

SageMath on Windows

To run Sage on Windows, use Windows Subsystem for Linux as documented in the Sage Installation Guide.

Viewing 2D/3D plots from the WSL command line in a Windows browser

If you want to use your Windows browser to view 2D/3D plots produced from the Sage command-line in WSL, you will need to first create a small wrapper script to translate a WSL path into a Windows path and open it with the appropriate Windows app:

   1 #!/bin/bash
   2 # wslview_wslpath.sh
   3 wslview $(wslpath -w $1)

Make sure it is executable. Assuming you placed it in your home folder:

   1 chmod +x /home/<username>/wslview_wslpath.sh

Now, add the following to your init.sage:

   1 # Open 2D/3D plots in Windows browser.
   2 wslview_wslpath = '/home/<username>/wslview_wslpath.sh'
   3 from sage.misc.viewer import viewer
   4 viewer.browser(wslview_wslpath)    # for 3D plots
   5 viewer.png_viewer(wslview_wslpath) # for 2D plots
   6 
   7 # Uncomment these lines to also open DVIs and PDFs in Windows.
   8 #viewer.dvi_viewer(wslview_wslpath)
   9 #viewer.pdf_viewer(wslview_wslpath)
  10 
  11 # The Windows browser will be unable to access the threejs library installed
  12 # in WSL, so you will need to use the online version of threejs.
  13 sage.plot.plot3d.base.SHOW_DEFAULTS['online'] = True    

Launching Jupyter/JupyterLab from WSL in the Windows browser

If you want to launch Jupyter/JupyterLab in your Windows browser, you will need to make a small config change. First, generate a config file if you haven't already done so using one of:

   1 sage --jupyter notebook --generate-config
   2 sage --jupyter lab --generate-config

Then, open the config file and make sure the option use_redirect_file is set to False:

   1 c.NotebookApp.use_redirect_file = False

CoCalc

CoCalc (formerly SageMathCloud) is a collaborative cloud-based computing environment, originally designed for using Sage in the cloud. Through CoCalc you can run Sage either in its command-line interface, or in a Jupyter Notebook, all through your web browser on a cloud-hosted environment, meaning you don't have to install any software (other than a web browser), but that you also need an internet connection.

CoCalc was originally designed by William Stein, the creator of Sage, to run Sage in the cloud (back when it was called SageMathCloud), but it was quickly realized that all the infrastructure needed to run Sage on the cloud can also be used for a more generic scientific computing environment, which the re-branded CoCalc now provides. You can see some of the software provided by a CoCalc environment here.

You can create an unlimited account for free, though the free accounts are limited in the amount of disk space they provide, and the amount of RAM they provide. They also do not allow direct internet access from within the CoCalc environment (but you are allowed to upload your data files through the CoCalc interface). See https://cocalc.com/policies/pricing.html for more details. Sometimes William will also provide discounts for specific academic purposes, or for people who are willing to contribute to CoCalc's development, though we cannot speak for him here.

As long as you have reasonably reliable internet connection, CoCalc is a great way to just try out Sage, and other open-source mathematics software, without having to go to the trouble of installing anything on your local machine. However, with a flaky or overloaded internet connection, it can sometimes be slow and frustrating.

SageWindows (last edited 2024-03-04 00:22:08 by mkoeppe)