KrisH
KrisH

Reputation: 95

python: Importing mayavi.mlab produces syntax error

Im trying to use mayavi to create 3d plots but when running my python script I get the following error:

 Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import mayavi.mlab
  File "C:\Python37\lib\site-packages\mayavi\mlab.py", line 15, in <module>
    from mayavi.core.common import process_ui_events
  File "C:\Python37\lib\site-packages\mayavi\core\common.py", line 16, in <module>
    from apptools.persistence.state_pickler import create_instance
  File "C:\Python37\lib\site-packages\apptools\persistence\state_pickler.py", line 1210

    ^
SyntaxError: invalid syntax

The function i'm trying to test:

  def create_3D(dataset):
    #Extract the x, y ,z and von mises data from the numpy dataset and create an array for each.
    xs = dataset[:,1]
    ys = dataset[:,2]
    zs = dataset[:,3]
    v = dataset[:,4]

    # Define the points in 3D space
    # including color code based on value v
    pts = mlab.points3d(xs, ys, zs , v)

    # Triangulate based on X, Y with Delaunay 2D algorithm.
    # Save resulting triangulation.
    mesh = mlab.pipeline.delaunay2d(pts)

    # Remove the point representation from the plot
    pts.remove()

    # Draw a surface based on the triangulation
    surf = mlab.pipeline.surface(mesh)

    # Simple plot.
    mlab.xlabel("x")
    mlab.ylabel("y")
    mlab.zlabel("z")
    mlab.show()

Any idea how I could fix this? I followed the installation procedure suggested here $ pip install mayavi

$ pip install PyQt5

I am using a 64bit version of python 3.7

Upvotes: 1

Views: 3364

Answers (3)

Hernan
Hernan

Reputation: 41

For Windows 10, Python 3.7.4 (Anaconda 2019.10)

How Rem says: "On Windows it does have that many lines; somehow all the newlines are doubled. The syntax error comes from lines continued after a backslash, because on Windows there is an empty line between the backslash and the continuation of the line."

In windows, i only find the file "state_pickler.py" and removed the empty lines after the "\", saved it and all works fine.

Upvotes: 4

Ben
Ben

Reputation: 51

I experienced the same problem but solved it. seems in the state_pickler.py file, in a few places (where the error message tells, it has \ in in the "if .... \ and " (used to split the and conditions in multiple lines), just to remove the \ to make all the " and " conditions in one line. There are a few places with the issue, then amazingly it work!

Upvotes: 5

phd
phd

Reputation: 94502

state_pickler.py is only 1022 lines long, it doesn't have line 1210.

Remove the directory C:\Python37\lib\site-packages\apptools\persistence\__pycache__ and try again.

Try to reinstall apptools:

pip install -U apptools

Upvotes: 1

Related Questions