4

Hello everybody reading this message,

Since I set PYTHONPATH on my desktop, whenever I try to use commands like gdb, or yum, which I think not related to python, I have this "SyntaxError: invalid syntax" slapping my face. I have tried several thing to debug the shell prompt, to figure out what the heck was going on, but so far I stucked with this problem.

I goes like this:

[charly@sn04 ~]$ gdb
  File "/opt/anaconda3/lib/python3.5/site.py", line 176
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

This seems to be related to PYTHONPATH. When I unset this, everything works fine.

My PYTHONPATH:

export PYTHONPATH=/opt/anaconda3/lib/python3.5/

I have tried to debug the shell with -x and -v, but the debug information is not helpful:

[charly@sn04 ~]$ gdb
gdb
+ gdb
  File "/opt/anaconda3/lib/python3.5/site.py", line 176
    file=sys.stderr)
        ^
SyntaxError: invalid syntax

I tried as well to set a trap:

trap "PARENT_COMMAND=\"$(ps -o comm= $PPID)\"" ERR
[charly@sn04 ~]$ gdb
gdb
+ gdb
  File "/opt/anaconda3/lib/python3.5/site.py", line 176
    file=sys.stderr)
        ^
SyntaxError: invalid syntax
PARENT_COMMAND="xterm"
++ PARENT_COMMAND=xterm

, to see which process was calling this error, but so far I was unable to figure out how to solve this problem.

Thank you in advance for any clue or hint.

Dyrl
  • 41
  • 1

2 Answers2

2
export PYTHONPATH=

solved my problem (Git Bash, Windows 10)

PJ127
  • 986
  • 13
  • 23
0

Check what version of python is used by gdb (gdb uses Python for scripting)

$ (which gdb) | grep python

or

$ which gdb | xargs grep -a python

If gdb uses a different version than that in your current PYTHONPATH, then you should either change your Python path to the version supported by gdb or re-build gdb

See also:

gdb uses wrong python, AttributeError: 'module' object has no attribute 'pydebug', and How to change the Python Interpreter that gdb uses?.

user2314737
  • 27,088
  • 20
  • 102
  • 114
  • Thank you for your answer! I had better checked before if internaly these commands called python or not. I couldn't think a reason why gdb would do so, but anyway it does. To complement your answer, I would re-write the command like this: which gdb | xargs grep -a python – Dyrl Jan 19 '18 at 10:32
  • @Dyrl I added this to my answer. But did it help to fix the issue? – user2314737 Jan 19 '18 at 10:54
  • Yes, but the solution is to completly remove the PYTHONPATH from my .bashrc, because it was pointing to python3.5, and gdb python2.7.I will set it inside the application I am developing, so system tools will not be affected. – Dyrl Jan 19 '18 at 10:58