Forum Navigation
You need to log in to create posts and topics.

ImportError: cannot import name 'ExpressionSelectionModifier' from 'ovito.modifiers'

Dear all,

When I was running ovito on our lab's host (Ubuntu 16.04.4) this afternoon, an error occurred:

liuliuli@amax:~$ ovitos --nthreads 1
Traceback (most recent call last):
File "/home/liuliuli/ovito-3.0.0-dev608-x86_64/bin/../lib/ovito/plugins/python/ovito/", line 37, in <module>
for _, _name, _ispkg in pkgutil.walk_packages(_package_source_path, __name__ + '.'):
File "/home/liuliuli/ovito-3.0.0-dev608-x86_64/lib/python3.7/", line 87, in walk_packages
for info in iter_modules(path, prefix):
File "/home/liuliuli/ovito-3.0.0-dev608-x86_64/lib/python3.7/", line 130, in iter_modules
for name, ispkg in iter_importer_modules(i, prefix):
File "/home/liuliuli/ovito-3.0.0-dev608-x86_64/lib/python3.7/", line 149, in _iter_file_finder_modules
import inspect
File "/home/liuliuli/ovito-3.0.0-dev608-x86_64/lib/python3.7/", line 35, in <module>
import dis
File "/home/liuliuli/", line 5, in <module>
from ovito.modifiers import ExpressionSelectionModifier, DeleteSelectedModifier, \
ImportError: cannot import name 'ExpressionSelectionModifier' from 'ovito.modifiers' (/home/liuliuli/ovito-3.0.0-dev608-x86_64/bin/../lib/ovito/plugins/python/ovito/modifiers/
ERROR: The Python script has exited with an error.
ERROR: Error during Python script execution.

A fold named __pycache__ was auto-generated containing a binary file dis.cpython-37.pyc. This is puzzling as ovito worked well just several hours ago. Another user on our host also found the same problem, although we used different packages. This error also happened on a super computer clusters. I've tried to re-unzip the package as well as downloaded the latest version,  but the problem still existed.  In my test, is seemed that all Modifiers in ovito.modifiers suddenly became unavailable; and the error massage appeared even when I just executed a simple command ovitos.  

The script:

  1. #ovito.3.0.0.
  2. from import *
    from import *
    from ovito.modifiers import ExpressionSelectionModifier, DeleteSelectedModifier, \
    ClusterAnalysisModifier, ColorCodingModifier, CalculateDisplacementsModifier
    from ovito.pipeline import *
    from ovito.vis import Viewport, TachyonRenderer, PythonViewportOverlay, ParticlesVis
    import numpy as np
    import math
  3. pipeline = import_file('/data1/liuliuli/')
    pipeline.modifiers.append(ExpressionSelectionModifier(expression = 'ParticleType == 1'))
    pipeline.modifiers.append(ClusterAnalysisModifier(cutoff = 2.48, sort_by_size = True))
    pipeline.modifiers.append(ColorCodingModifier(property = 'Cluster', start_value=10, end_value=1))
    modifier = CalculateDisplacementsModifier()
    modifier.vis.enabled = True
    modifier.use_frame_offset = True
    pipeline.modifiers.append(ColorCodingModifier(property = 'Displacement Magnitude', operate_on = 'vectors', end_value=2))
  4. vp = Viewport(type = Viewport.Type.Perspective,
    camera_dir = (-0.440753, -0.596303, -0.670939),
    camera_pos = (125-40*i, 78-40*j, 122-10*k))
    vp.fov = math.radians(60)
    vis_element =
    vis_element.radius = 0.6
    size=(320, 240),
Uploaded files:


Yes indeed, this is a very surprising change in behavior, given that you did not touch the OVITO installation directory in any way and the OVITO Python module was loading normally before.

From the error message it appears as if your script imports the ovito module, which in turn tries to import your script also as a module. I have no explanation for this behavior yet. Normally, the ovito module will automatically scan the directory tree under the root folder ${OVITO_ROOT}/lib/ovito/plugins/python/ovito/ for sub-modules and import them automatically. This is what line 37 in does.

For some reason reason, the recursive module search also finds your own script, which resides in a completely different file system location, I assume. To further diagnose the problem, it would be helpful if you could do the following. Please edit the file ${OVITO_ROOT}/lib/ovito/plugins/python/ovito/ and insert the statement print(_package_source_path) after line 15. I would like to know the value of this variable on your local system.

Another thing you can do is check if there are any Python-related environment variables set on your system, which could affect where the Python interpreter searches for modules.

Hi Alexander,

Yes, the script is in a different fold from ovito package. I added the  statement print(_package_source_path) as you told, the value is ['/home/liuliuli/ovito-3.0.0-dev608-x86_64/bin/../lib/ovito/plugins/python/ovito']. As far as I know, we didn't change any python-related environment variables. But before ovito broke down, I did use an environment variable to deliver an address in python to shell in a script, I wonder if this could be the reason. Here are the first several lines of the script:

from import *
from import *
from ovito.modifiers import ExpressionSelectionModifier, DeleteSelectedModifier, ClusterAnalysisModifier, WignerSeitzAnalysisModifier
from ovito.pipeline import *
import numpy as np
import os

pipeline = import_file('/data1/liuliuli/')
addr= '/data1/liuliuli/'
os.environ['addr']=str(addr) #Deliver python variable to shell