Home > Blockchain >  Why python program run fine on pycharm, but showing syntax error on ubuntu terminal after changing f
Why python program run fine on pycharm, but showing syntax error on ubuntu terminal after changing f

Time:08-08

I have some python script, which working fine on ubuntu default bash terminal. When i changed terminal to zsh, python file.py giving following syntax error

  File "file.py", line 17
    file_dir: str = ''
            ^
SyntaxError: invalid syntax

The same file working fine on pycharm build-in run

CodePudding user response:

That error looks like you're running it under python 2 rather than python 3. The reason it works in bash but not zsh is probably that your PATH is different, which traces back to a difference in the shell's initialization files (i.e. ~/.bash_profile and ~/.bashrc vs ~/.zprofile and ~/.zshrc etc).

You can compare your PATH in the two shells by running echo "$PATH" in each, and see what python executables each is finding with type -a python (it may list several different executables; the first on the list is the one that'll actually be used). When you've found the critical difference, you'll need to edit your zsh init file(s) to get your PATH set up the way it needs to be.

  • Related