Unable to import traversal

1,461 views
Skip to first unread message

DCody

unread,
Jan 27, 2019, 12:07:42 AM1/27/19
to Gremlin-users
Hello, I want to start experimenting with a Python application that uses TinkerPop and Gremlin but I am unable to achieve a basic set-up.

I downloaded and unzipped the latest TinkerPop:

installed the corresponding Gremlin Python:
     pip install gremlinpython==3.4.0

and created the extensions for Gremlin with:
     bin/gremlin-server.sh install org.apache.tinkerpop gremlin-python 3.4.0

I start the Gremlin server with:
   bin/gremlin-server.sh conf/gremlin-server-modern-py.yaml

and it appears to start and run normally without any error messages:

[INFO] GremlinServer - Configuring Gremlin Server from conf/gremlin-server-modern-py.yaml

[INFO] MetricManager - Configured Metrics Slf4jReporter configured with interval=180000ms and loggerName=org.apache.tinkerpop.gremlin.server.Settings$Slf4jReporterMetrics

[INFO] DefaultGraphManager - Graph [graph] was successfully configured via [conf/tinkergraph-empty.properties].

[INFO] ServerGremlinExecutor - Initialized Gremlin thread pool.  Threads in pool named with pattern gremlin-*

[INFO] ServerGremlinExecutor - Initialized GremlinExecutor and preparing GremlinScriptEngines instances.

[INFO] ServerGremlinExecutor - Initialized gremlin-groovy GremlinScriptEngine and registered metrics

[INFO] ServerGremlinExecutor - Initialized gremlin-jython GremlinScriptEngine and registered metrics

[INFO] ServerGremlinExecutor - Initialized gremlin-python GremlinScriptEngine and registered metrics

[INFO] ServerGremlinExecutor - A GraphTraversalSource is now bound to [g] with graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]

[INFO] OpLoader - Adding the standard OpProcessor.

[INFO] OpLoader - Adding the session OpProcessor.

[INFO] OpLoader - Adding the traversal OpProcessor.

[INFO] TraversalOpProcessor - Initialized cache for TraversalOpProcessor with size 1000 and expiration time of 600000 ms

[INFO] GremlinServer - Executing start up LifeCycleHook

[INFO] Logger$info - Loading 'modern' graph data.

[INFO] GremlinServer - idleConnectionTimeout was set to 0 which resolves to 0 seconds when configuring this value - this feature will be disabled

[INFO] GremlinServer - keepAliveInterval was set to 0 which resolves to 0 seconds when configuring this value - this feature will be disabled

[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v3.0+gryo with org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0

[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v3.0+gryo-stringd with org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV3d0

[INFO] AbstractChannelizer - Configured application/vnd.gremlin-v3.0+json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0

[INFO] AbstractChannelizer - Configured application/json with org.apache.tinkerpop.gremlin.driver.ser.GraphSONMessageSerializerV3d0

[INFO] AbstractChannelizer - Configured application/vnd.graphbinary-v1.0 with org.apache.tinkerpop.gremlin.driver.ser.GraphBinaryMessageSerializerV1

[INFO] GremlinServer$1 - Gremlin Server configured with worker thread pool of 1, gremlin pool of 8 and boss thread pool of 1.

[INFO] GremlinServer$1 - Channel started at port 8182.


My environment is OSX 10.14.2 running Python 3.6.7, and Java is:

java version "1.8.0_171"

Java(TM) SE Runtime Environment (build 1.8.0_171-b11)

Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)


The application file has the imports recommended in the TinkerPop documentation:
from gremlin_python import statics
from gremlin_python.process.anonymous_traversal_source import traversal
from gremlin_python.process.graph_traversal import __
from gremlin_python.process.strategies import *
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
from gremlin_python.process.traversal import T
from gremlin_python.process.traversal import Order
from gremlin_python.process.traversal import Cardinality
from gremlin_python.process.traversal import Column
from gremlin_python.process.traversal import Direction
from gremlin_python.process.traversal import Operator
from gremlin_python.process.traversal import P
from gremlin_python.process.traversal import Pop
from gremlin_python.process.traversal import Scope
from gremlin_python.process.traversal import Barrier
from gremlin_python.process.traversal import Bindings
from gremlin_python.process.traversal import WithOptions

However, the IDE (PyCharm 2018.3) indicates it is unable to resolve 'traversal' from 'gremlin_python.process.anonymous_traversal_source', 
although it is able to resolve 'DriverRemoteConnection' from 'gremlin_python.driver.driver_remote_connection'.

It seems I am missing some basic set-up step, can anyone tell me what it is?
Thanks in advance,
David





Stephen Mallette

unread,
Jan 28, 2019, 6:47:21 AM1/28/19
to gremli...@googlegroups.com
I'm not sure what would cause that problem. Whatever it is it's not related to your server-side setup and as best I can tell is simply an IDE configuration problem. I don't use PyCharm, but IDEA has similar problems sometimes resolving dependencies and a cache clear or dependency refresh usually fixes those things right up. I'm not sure what those steps are for PyCharm though. 

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/84a3f03e-5002-4239-986f-09d9a6641407%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kelvin Lawrence

unread,
Jan 28, 2019, 10:24:24 AM1/28/19
to Gremlin-users
As a sanity check - are you able to connect if you just try in the Python console? I keep a small bootstrap file handy so that I can do something like

python3 -i bootstrap-gremlin.py



and then I have essentially a nice Python console connected to my remote graph endpoint.

If that works it must be something in PyCharm. I have not tried myself from PyCharm but I do have it installed for other reasons. If I can find five minutes I will have a go and report back.

Cheers
Kelvin

DCody

unread,
Jan 28, 2019, 4:18:13 PM1/28/19
to Gremlin-users
I deleted apache.tinkerpop.gremlin.server  and uninstalled gremlinpython (and its dependencies tornado, aenum and six), re-downloaded the code from Apache (the SHA is correct), re-installed gremlinpython with Pip, and rebuilt the Gremlin extensions.
To avoid IDE cache etc problems I opened a Python console and was able to import gremlin_python statics but still not able to import traversal:

Zeus:apache-tinkerpop-gremlin-server-3.4.0 dx$ source activate kb36

(kb36) Zeus:apache-tinkerpop-gremlin-server-3.4.0 dx$ python

Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 14:01:38) 

[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

>>> from gremlin_python import statics

>>> from gremlin_python.process.anonymous_traversal_source import traversal

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

ModuleNotFoundError: No module named 'gremlin_python.process.anonymous_traversal_source'

>>> 


Later today I'll try with the previous version of TinkerPop.
Thank you for the suggestions.
David

DCody

unread,
Jan 28, 2019, 4:26:17 PM1/28/19
to Gremlin-users
Is there a bug in the docs?
When I change the import statement to "from gremlin_python.process.anonymous_traversal import traversal", note the omitted "_source" in the module name, then the import runs cleanly and I am able to create a traversal source with the statement:

g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin', 'g'))


Kelvin Lawrence

unread,
Jan 28, 2019, 6:23:09 PM1/28/19
to Gremlin-users
I guess that explains why I see no issues. I don't use either forms of that import.

The confusion is probably from the fact that the file is called anonymous_traversal.py but the class is called AnonymousTraversalSource

Cheers
Kelvin

DCody

unread,
Jan 28, 2019, 8:30:26 PM1/28/19
to Gremlin-users
Perhaps someone could make the change in http://tinkerpop.apache.org/docs/current/reference/#python-imports.
D.

Stephen Mallette

unread,
Jan 29, 2019, 7:50:17 AM1/29/19
to gremli...@googlegroups.com
sorry - i'll fix that. i didn't notice that naming problem...........that stinks

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages