Closed drdhaval2785 closed 7 years ago
run source sourceme
from the sanskrit_parser root directory. That'll setup your PYTHONPATH so all subdirectories are visible.
This will probably not be the final directory structure - as Vishvas requested, we'll probably break this up and so that it'll be easier to reuse parts. For now, since this changes by the minute, let the current structure be.
I did source sourceme, but the problem still lingers
python SanskritLexicalAnalyzer.py astyuttarasyAMdishi --split
Traceback (most recent call last):
File "SanskritLexicalAnalyzer.py", line 12, in <module>
import base.SanskritBase as SanskritBase
ImportError: No module named base.SanskritBase
Anything to do with windows machine ? I run it in git bash terminal.
@drdhaval2785
Updated README.md
Can you run echo $PYTHONPATH
and cut-paste your output here?
Also cd sanskrit_parser
, and see if you can do the following
sanskrit_parser (master)*$ python -i
Python 2.7.13 |Anaconda custom (64-bit)| (default, Dec 20 2016, 23:09:15)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import base
>>> import base.SanskritBase
$ echo $PYTHONPATH
:/e/c_drive/xampp/htdocs/sanskrit_parser:/e/c_drive/xampp/htdocs/sanskrit_parser/../inriaxmlwrapper:/e/c_drive/xampp/htdocs/sanskrit_parser:/e/c_drive/xampp/htdocs/sanskrit_parser/../inriaxmlwrapper:/e/c_drive/xampp/htdocs/sanskrit_parser:/e/c_drive/xampp/htdocs/sanskrit_parser/../inriaxmlwrapper
$ python -i
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import base
>>> import base.SanskritBase
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "base\SanskritBase.py", line 2, in <module>
from indic_transliteration import sanscript
ImportError: No module named indic_transliteration
>>> exit()
installed indic_transliteration via pip. That error is now gone.
Great! Let me know what you think. I'm closing this issue, please reopen if you face more trouble.
importing base via python -i works. But the error in terminal still remains the same.
dell user@dell MINGW64 /e/c_drive/xampp/htdocs/sanskrit_parser/lexical_analyzer (master)
$ python SanskritLexicalAnalyzer.py astyuttarasyAMdiSi --split
Traceback (most recent call last):
File "SanskritLexicalAnalyzer.py", line 12, in <module>
import base.SanskritBase as SanskritBase
ImportError: No module named base.SanskritBase
How did you install indic_transliteration? Did you use pip?
Yes. pip install indic_transliteration
Try importing base using python -i
but from the lexical_analyzer directory. If that works, please try import SanskritLexicalAnalyzer
and dump the output here.
Not possible to import base from lexical_analyzer directory
dell user@dell MINGW64 /e/c_drive/xampp/htdocs/sanskrit_parser/lexical_analyzer (master)
$ python -i
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import base
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named base
This indicates a PYTHONPATH problem. If you have the same PYTHONPATH as mentioned in an earlier comment, this should not happen. Possibly a Windows issue.
This is what should happen - the sanskrit_parser directory should be on PYTHONPATH, so import base
will work (the base subdirectory will be visible to python, and it can see a __init__.py
there). Somehow that's not happening for you. Please see if you can think of something based on this.
I will look into this further once I have access to a Windows machine later in the day.
It indeed seems to be an windows+bash issue. Works as described in my ubuntu machine.
Works for me on windows + git bash. I did essentially what dhaval did: cd to sanskrit_parser export PYTHONPATH=$PWD cd to inriaxmlwrapper export PYTHONPATH=$PYTHONPATH:$PWD $ echo $PYTHONPATH /c/Users/ALVARNA/Documents/personal/samskritam/research/sanskrit_parser:/c/Users/ALVARNA/Documents/personal/samskritam/research/inriaxmlwrapper $ python lexical_analyzer/SanskritLexicalAnalyzer.py astyuttarasyAMdishi --split Parsing of XMLs started at 2017-07-05 14:47:18.853000 666994 forms cached for quick search Parsing of XMLs completed at 2017-07-05 14:47:24.909000 Input String: astyuttarasyAMdishi Input String in SLP1: astyuttarasyAMdiSi Start split: 2017-07-05 14:47:27.659000 End split: 2017-07-05 14:47:27.659000 [[u'asti', u'ut', u'tara', u'syAm', u'diSi'], [u'asti', u'ut', u'taras', u'yAm', u'diSi'], [u'asti', u'uttas', u'asyAm', u'diSi'], [u'asti', u'uttara', u'syAm', u'diSi'], [u'asti', u'uttaras', u'yAm', u'diSi'], [u'asti', u'uttarasyAm', u'diSi']]
@avinashvarna Can you try running in the lexical_analyzer directory? That's when @drdhaval2785 saw the error.
By following the steps delineated by @avinashvarna above, I am now able to run both in sanskrit_parser and lexical_analyzer directories. It seems that the generic sourceme method does not apply in windows machine.
And it seems that the method shown above is stored in only session. Whenever I reopen git bash, it is forgotten. I need to rerun the above code over again whenever I close and open git bash.
@drdhaval2785 Once you follow the above steps and get it set up correctly, run this command to add the environment variable setup into your bashrc echo "export PYTHONPATH=\${PYTHONPATH}\${PYTHONPATH:+:}$PYTHONPATH" >> ~/.bashrc
Next time you start git bash, the environment variable should be setup correctly to run the scripts.
I already have a .bashrc working for some SSH key. Tried adding this to that .bashrc file, but to no avail. But at least now I am able to run the code on windows laptop. So not have to stick myself on my ubuntu desktop at fixed place. @kmadathil may like to create something for windows which is a bit easier.
The command that I posted "appends (>>)" that export line to your .bashrc, so it should not impact your existing setup. If you are manually modifying your .bashrc, did you add export PYTHONPATH=${PYTHONPATH}${PYTHONPATH:+:}$PYTHONPATH to it? Strange that it doesn't work.
I saw your impressive speed up. So just wanted to run SanskritLexicalAnalyzer.py as shown in the comment. But it gave me error No module named base.SanskritBase
Maybe a line or two of setup would be in order.
Maybe I am not able to setup the directory structure as it should have been.