kuanb / peartree

peartree: A library for converting transit data into a directed graph for sketch network analysis.
MIT License
201 stars 23 forks source link

KeyError: 'GRAPH_TOOL_DIR' #129

Closed patsotoe closed 5 years ago

patsotoe commented 5 years ago

i have the following error, i´m using python 3.6.


KeyError Traceback (most recent call last)

in () 1 from peartree.graph_tool import nx_to_gt 2 ----> 3 gtG = nx_to_gt(G.copy()) ~/anaconda3/lib/python3.6/site-packages/peartree/graph_tool.py in nx_to_gt(nxG) 103 """ 104 # First, attempt to import graph-tool --> 105 gt = _import_graph_tool() 106 107 # Phase 0: Create a directed or undirected graph-tool Graph ~/anaconda3/lib/python3.6/site-packages/peartree/graph_tool.py in _import_graph_tool() 19 # If we fail to import it the first time, check to see if it 20 # has been downloaded in its default apt-get install directory ---> 21 sys.path.append(os.environ['GRAPH_TOOL_DIR']) 22 23 # Now retry with the new system path appended ~/anaconda3/lib/python3.6/os.py in __getitem__(self, key) 667 except KeyError: 668 # raise KeyError with the original key value --> 669 raise KeyError(key) from None 670 return self.decodevalue(value) 671 KeyError: 'GRAPH_TOOL_DIR'
kuanb commented 5 years ago

Thanks @patsotoe

Do you have graph tool up and running? I do not work in an Anaconda environment, so I have not set up graph-tool within that context specifically. I do have a docker image that has it and Jupyter notebook available if that is useful.

The error that is occurring is that peartree is trying to find out where graph-tool is installed. Because of the particularities with how it's installed, I use an environment variable to indicate where the python wrapper for it is installed. You can see this being implemented in the tests: https://github.com/kuanb/peartree/blob/eed90a9083d88b63ab6011302b22a4410052ff7c/.travis.yml#L32

You can see where that error is being thrown by looking here: https://github.com/kuanb/peartree/blob/accbb27a5a1c522b0da49fd0fdd7d79d9d7e6fbe/peartree/graph_tool.py#L21

It's trying to pull the path to graph-tool from that environment variable (via os.environ).

By the way, I recognize this is an inelegant solution - if you have suggestions for better patterns to help with graph-tool importing, I am open to them.

Thanks!

patsotoe commented 5 years ago

First all, thanks for your awesome work in your blog i read the most of your articles.

Yes, in that moment i was running graph tool up and running in anaconda, when you answer me i decide change to docker because i see in the future is better enviroment for work with datascience, changing my enviroment the problem was solved.

I approach the oportunity of ask you how you see the route straightness is related with accesibility and have a doubt in your post of Calculating Route Straightness why you use the value TURN_DEGREES_THRESHOLD= 30.

Thanks.

kuanb commented 5 years ago

Hi @patsotoe

Thanks for the follow up. Sounds like this issue has been resolved. If you can, please post your question in the blog that you are talking about. If you scroll down to the bottom of the blog, there should be a Disqus comments section. If you post your question there, then others who have the same question will also be able to see the answer!

Thanks again!

patsotoe commented 5 years ago

Thanks for take the time to respond our questions, i already post in your blog.