jacksonllee / pycantonese

Cantonese Linguistics and NLP
https://pycantonese.org
MIT License
354 stars 38 forks source link

unable to run file directly #31

Closed lawrence124 closed 2 years ago

lawrence124 commented 2 years ago

Describe the bug running in python environment is ok but not when it is in a py file

To reproduce running "python cantonese.py" will result in error/crash, while cantonese.py only has 2 lines:

import pycantonese pycantonese.characters_to_jyutping('香港人講廣東話') # Hongkongers speak Cantonese

image

but directly running in python environment was ok: image

Expected behavior A clear and concise description of what you expected to happen instead.

Screenshots If applicable, add screenshots to help explain your problem.

System (please complete the following information):

Additional context Add any other context about the problem here.

jacksonllee commented 2 years ago

Hello, the first screenshot did not show the complete stack trace to include the error. Would you be able to post the stack trace?

If I have to guess, for Windows you'd have to put your code under the if __name__ == "__main__": idiom when you run code from a .py file (due to parallelization -- see the "Caution" note at the top of the Quickstart page):

import pycantonese

if __name__ == "__main__":
    print(pycantonese.characters_to_jyutping('香港人講廣東話'))

Let me know if this resolves the issue.

lawrence124 commented 2 years ago

it solved the problem, sorry for not reading the quickstart page thoroughly/