gdb fails in Ubuntu 14.04 due to PYTHONPATH

1,983 views
Skip to first unread message

Bit_Pusher

unread,
May 11, 2014, 8:50:37 AM5/11/14
to osv...@googlegroups.com
In Ubuntu 14.04 LTS (64-bit) with
> export PYTHONPATH=/usr/lib/python2.7/
gdb fails:

> gdb
Fatal Python error: Py_Initialize: Unable to get the locale encoding
File "/usr/lib/python2.7/encodings/__init__.py", line 123
raise CodecRegistryError,\
^
SyntaxError: invalid syntax
Aborted (core dumped)
>

If I set:
> export PYTHONPATH=/usr/lib/python2.7/dist-packages
then gdb runs as expected:

> gdb
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb)

This behaviour is occurs on 3 different machines: would anyone have any ideas why? Thanks.

Tomasz Grabiec

unread,
May 12, 2014, 11:33:02 AM5/12/14
to Bit_Pusher, Osv Dev
Hi Bit_Pusher,


On Sun, May 11, 2014 at 2:50 PM, Bit_Pusher <ken.w....@gmail.com> wrote:
In Ubuntu 14.04 LTS (64-bit) with
> export PYTHONPATH=/usr/lib/python2.7/

PYTHONPATH is a list of directories relative to which modules are looked up. It is not supposed to point to python's installation directory.
 
gdb fails:

> gdb
Fatal Python error: Py_Initialize: Unable to get the locale encoding
  File "/usr/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax
Aborted (core dumped)
>

If I set:
> export PYTHONPATH=/usr/lib/python2.7/dist-packages
then gdb runs as expected:

This works because "dist-packages" is a base for core modules. 

But you probably shouldn't set PYTHONPATH, python should be able to find its core libraries just fine. Also, IIRC the GDB version you use was linked with python 3, so setting PYTHONPATH to python 2's modules may result in unexpected behavior as python 3 is not backwards compatible with python 2.
 

> gdb
GNU gdb (Ubuntu 7.7-0ubuntu3) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb)

This behaviour is occurs on 3 different machines: would anyone have any ideas why? Thanks.

--
You received this message because you are subscribed to the Google Groups "OSv Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ken.w....@gmail.com

unread,
May 15, 2014, 1:03:48 PM5/15/14
to osv...@googlegroups.com, Bit_Pusher
Thanks Tomasz, this is useful. I did go to the gdb manual at http://www.gnu.org/software/gdb/documentation/ and searched for Python and I couldn't find any information about gdb being linked to Python 3; could you possibly elaborate on this a bit more? I would have thought gdb would have been written in gcc as it's primary purpose is to debug gcc, but I am curious about how Python is used in gdb?

Regarding setting PYTHONPATH; I have not previously read that one should not set PYTHONPATH. At http://stackoverflow.com/questions/18247333/python-pythonpath-in-linux, it indicates that PYTHONPATH should be set to: /usr/lib/python2.7 as in:

PYTHONPATH is an environment variable
Yes (see http://unix.stackexchange.com/questions/24802/on-which-unix-distributions-is-python-installed-as-part-of-the-default-install)
/usr/lib/python2.7 on Ubuntu

etc,

I also looked in the Python documentation, and could not find anything there stating PYTHONPATH should not be set:

PYTHONPATH
Augment the default search path for module files. The format is the same as the shell’s PATH: one or more directory pathnames separated by os.pathsep (e.g. colons on Unix or semicolons on Windows). Non-existent directories are silently ignored.

In addition to normal directories, individual PYTHONPATH entries may refer to zipfiles containing pure Python modules (in either source or compiled form). Extension modules cannot be imported from zipfiles.

The default search path is installation dependent, but generally begins with prefix/lib/pythonversion (see PYTHONHOME above). It is always appended to PYTHONPATH.

An additional directory will be inserted in the search path in front of PYTHONPATH as described above under Interface options. The search path can be manipulated from within a Python program as the variable sys.path.

so the information that PYTHONPATH should not be set, and especially not set to the installation directory is both new and useful, and something I have not seen elsewhere. We have been wanting to move to Python 3.x for quite a while, but unfortunately, we are importing some modules that are not compatible with 3.x and can't move yet. Thank you.
Reply all
Reply to author
Forward
0 new messages