aburgasser / splat

SpeX Prism Spectral Analysis Toolkit
MIT License
28 stars 46 forks source link

FileNotFound Error when importing splat.Splat #147

Open matthewD-AVI opened 5 years ago

matthewD-AVI commented 5 years ago

I am trying to import splat and am having some issues

I currently have from splat.SPLAT import SPLAT and I am receiving this error

importing SPLAT... Traceback (most recent call last): File "blather.py", line 2, in from splat.SPLAT import SPLAT # splat is 'SPLAT-library' in PyPI File "/usr/local/lib/python3.7/site-packages/splat/init.py", line 7, in from .core import * File "/usr/local/lib/python3.7/site-packages/splat/core.py", line 67, in DB_SOURCES = ascii.read(SPLAT_PATH+DB_FOLDER+DB_SOURCES_FILE) File "/usr/local/lib/python3.7/site-packages/astropy/io/ascii/ui.py", line 373, in read dat = _guess(table, new_kwargs, format, fast_reader) File "/usr/local/lib/python3.7/site-packages/astropy/io/ascii/ui.py", line 530, in _guess dat = reader.read(table) File "/usr/local/lib/python3.7/site-packages/astropy/io/ascii/core.py", line 1154, in read self.lines = self.inputter.get_lines(table) File "/usr/local/lib/python3.7/site-packages/astropy/io/ascii/core.py", line 303, in get_lines encoding=self.encoding) as fileobj: File "/usr/local/lib/python3.7/contextlib.py", line 112, in enter return next(self.gen) File "/usr/local/lib/python3.7/site-packages/astropy/utils/data.py", line 192, in get_readable_fileobj fileobj = io.FileIO(name_or_obj, 'r') FileNotFoundError: [Errno 2] No such file or directory: './/splat/db/source_data.txt'

I can confirm that source_data.txt exists

Tianxing-Sky-Zhou commented 3 years ago

same issue here at 2021 lol!!! How did you solve it?

aburgasser commented 3 years ago

Sorry for the not-quite-one-year response ;)

It looks like you may have imported splat from pip (i.e., pip splat install); unfortunately that version won't work because pip won't store the accessory data - catalog of spectra. Hence it's not finding that file. Try installing directly from github (which is also more up to date) and see if that resolves the issue.

Alternately (and possibly additionally!) it looks like you haven't set the SPLAT_PATH, so it's looking in your home directory for the splat code (the "./" in the './/splat/db/source_data.txt' in the last line). You want to set that as an environment variable; see http://pono.ucsd.edu/~adam/browndwarfs/splat/installation.html, and if that doesn't make sense (or fix the problem), let me know.

Tianxing-Sky-Zhou commented 3 years ago

Sorry for the not-quite-one-year response ;)

It looks like you may have imported splat from pip (i.e., pip splat install); unfortunately that version won't work because pip won't store the accessory data - catalog of spectra. Hence it's not finding that file. Try installing directly from github (which is also more up to date) and see if that resolves the issue.

Alternately (and possibly additionally!) it looks like you haven't set the SPLAT_PATH, so it's looking in your home directory for the splat code (the "./" in the './/splat/db/source_data.txt' in the last line). You want to set that as an environment variable; see http://pono.ucsd.edu/~adam/browndwarfs/splat/installation.html, and if that doesn't make sense (or fix the problem), let me know.

I found a way to solve that and make it work!! It is a relative path and absolute path problem, at least for mine. I get the error when I’m at C:\Users\20130\, open python, import splat shows FileNotFoundError: [Errno 2] No such file or directory: './/splat/db/source_data.txt' However, if i switched to C:\Users\20130\Desktop\SPLAT\splat-master>, which is the absolute path for my splat package, i can import it properly. Also I found that doing it once allows me to even import it when I'm at C:\Users\20130. This works in my anaconda prompt, which also works in jupyter notebook image

Here's what I searched that helped me: https://stackoverflow.com/questions/22282760/filenotfounderror-errno-2-no-such-file-or-directory https://stackoverflow.com/questions/12201928/python-open-gives-filenotfounderror-ioerror-errno-2-no-such-file-or-directory

Tianxing-Sky-Zhou commented 3 years ago

Sadly I can't use gitclone because I'm in China and the downloading will be interruped (its too slow and stops automatically) I tried installing directly from github. I downloaded the zip file and unzipped it, downloaded all dependencies and used "python setup.py install" install to do it. I even created a virutal enviroment with python3.5, because the setup.py file seems to only support up to python3.5. However, it eventually leads me to this FileNotFound problem again. (I don't know if it is because I already have downloaded using pip in another conda environment)