EtienneCmb / visbrain

A multi-purpose GPU-accelerated open-source suite for brain data visualization
http://visbrain.org
Other
241 stars 65 forks source link

Issues importing data_url.json with pyenv virtual environments #40

Closed elijahc closed 5 years ago

elijahc commented 5 years ago

I use pyenv to manage my python virtual environments.

I'm having trouble executing your example for loading an edf file

Here's the stacktrace I get:

Traceback (most recent call last):
  File "load_edf.py", line 28, in <module>
    Sleep(data=dfile, hypno=hfile, config_file=cfile).show()
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/gui/sleep/sleep.py", line 157, in __init__
    Visuals.__init__(self)
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/gui/sleep/visuals/visuals.py", line 1103, in __init__
    parent=self._topoCanvas.wc.scene)
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/gui/sleep/visuals/visuals.py", line 752, in __init__
    TopoMesh.__init__(self, **kwargs)
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/visuals/topo_visual.py", line 196, in __init__
    auto = self._get_channel_coordinates(xyz, channels, system, unit)
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/visuals/topo_visual.py", line 382, in _get_channel_coordinates
    xyz, keeponly = self._get_coordinates_from_name(channels)
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/visuals/topo_visual.py", line 437, in _get_coordinates_from_name
    path = download_file('eegref.npz', astype='topo')
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/io/download.py", line 99, in download_file
    filename, url = name, get_data_url(name, astype)
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/io/download.py", line 35, in get_data_url
    urls = load_config_json(get_data_url_path())[astype]
  File "/Users/elijahc/.pyenv/versions/aether/lib/python3.5/site-packages/visbrain/io/rw_config.py", line 47, in load_config_json
    with open(filename) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/elijahc/.pyenv/vers/data_url.json'

I think this is due to the way that you find where the visbrain module has been installed in get_data_url_path()

currently you're doing this by walking back the path from where visbrain.io.path is installed but I think using inspect might get you the information more directly and also work better with other python virtual environment managers?

Thoughts?

I can submit a PR for this if that helps

EtienneCmb commented 5 years ago

GitMate.io thinks possibly related issues are https://github.com/EtienneCmb/visbrain/issues/12 (Brain import error), and https://github.com/EtienneCmb/visbrain/issues/24 (topo code issue).

EtienneCmb commented 5 years ago

Hi @elijahc ,

Thanks for reporting this issue. Yes, inspect is probably going to be better. Can you make the PR?

elijahc commented 5 years ago

Turns out pkg_resources is a better module for this.

see this SO post: https://stackoverflow.com/questions/779495/python-access-data-in-package-subdirectory

I'll submit a PR shortly