Ask Your Question
2

Cannot get threejs rendering to work on MacOS

asked 2018-10-21 19:12:04 +0200

TristanWL gravatar image

updated 2019-01-04 11:39:28 +0200

FrédéricC gravatar image

Hey,

I've been trying to get threejs output working for a few days now. My current installation is from Conda-Forge (sage 8.3) and I'm on MacOS High Sierra (10.13.6).

In the sage repl if I run

P = parametric_plot3d([cos(x),sin(x),x/10], (x,0,4*pi))
P.show(viewer='threejs')

sage raises ImportError: cannot import name 'THREEJS_DIR'. Full output: paste2.org/vP4nBZ9A

If I run

P = parametric_plot3d([cos(x),sin(x),x/10], (x,0,4*pi)
P.show(viewer='threejs', online=True)

sage returns Launched html viewer for Graphics3d Object, but nothing actually happens on my machine. No browser opens, nothing noticeable. I have tried changing the default viewer browser, but it has not made a difference. I'm at a loss as to what is going on here.

Finally, if I run it in a jupyter notebook,

p1 = sphere(color='red', opacity='.5')
p2 = sphere((-1,-1,1), color='cyan', opacity='.3')
p3 = sphere((1,-1,-1), color='yellow', opacity='.7')
show(p1 + p2 + p3, viewer='threejs', online=True)

I get TypeError: a bytes-like object is required, not 'str'. Full traceback here: paste2.org/c1VLUmNm

I've tried pretty hard to diagnose exactly what's going on, but I can't seem to find any recent documentation relating to this issue. My best guess is that the paths are getting messed up because I'm running sage through an anaconda environment. Is there any way to fix this? That being said, I was having similar issues before and wanted to integrate with jupyter which lead to me moving to anaconda. I am going to try and reinstall sage outside of anaconda and see if I can get it to work there, but I figured I should post first because I'm pretty stuck, and having everything in anaconda would be much nicer if possible.

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2018-10-22 18:55:19 +0200

eric_g gravatar image

It seems that you are using a version of SageMath built with Python3. Alas, Python3 SageMath is not fully ready yet (see this question for a status update, and in particular the ticket #26212). In particular, the threejs viewer is not Python3 ready.

edit flag offensive delete link more

Comments

The threejs works very well for me with a python3-built sage (on Ubuntu).

FrédéricC gravatar imageFrédéricC ( 2018-10-23 16:30:16 +0200 )edit

In console mode yes, but not in the Jupyter notebook: one gets TypeError: a bytes-like object is required, not 'str' from function displayhook (line 572 of src/sage/repl/rich_output/backend_ipython.py). This is with python3-built Sage 8.4.rc1 on Ubuntu 18.04 (I have not tried Sage 8.5.beta0 yet).

eric_g gravatar imageeric_g ( 2018-10-23 20:35:17 +0200 )edit

I rebuilt using python2.7 and I'm still having the same issues. The one that I understand the least is why it prints Launched html viewer for Graphics3d Object and then doesn't open anything.

TristanWL gravatar imageTristanWL ( 2018-10-23 22:03:42 +0200 )edit

Update: I now have installed Sage8.4 and built using python2.7 without using anaconda. Now I can get the threejs viewer working in a sage notebook, and I no longer get ImportError: cannot import name 'THREEJS_DIR' with Offline=False.

However, I still am getting Launched html viewer for Graphics3d Object without any noticeable activity.

TristanWL gravatar imageTristanWL ( 2018-10-24 04:32:37 +0200 )edit
2

answered 2018-10-24 12:25:33 +0200

saraedum gravatar image

Three.js in conda-forge

The ImportError: cannot import name 'THREEJS_DIR'is happening in conda-forge because there is no three.js packaged in conda yet. You could open an issue at https://github.com/conda-forge/sage-f... so we can work on a fix.

No browser is launched

I don't know why you don't get any visible output with online=True. This seems like something is broken in your local setup. Somewhere in your .sage directory (probably ~/.sage/temp) there should be an HTML file that you could open manually in your browser in the meantime.

To debug what's going on, you could try to run something like

sage: _system = os.system
sage: def system(*args, **kwargs):
....:     print(args, kwargs)
....:     _system(*args, **kwargs)
....:     
sage: os.system = system
sage: P.show(viewer='threejs', online=True)

You should then see the command that sage is trying to run.

Python3 errors

You should probably open a ticket at trac.sagemath.org about this (after checking that no such ticket exists yet.) Python3 support in Sage is very experimental.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-10-21 19:10:46 +0200

Seen: 1,899 times

Last updated: Oct 24 '18