Python installation, failing to find bz2 module

Kyle Simpson

OK, I have an old Debian VM. Package managers are useless. No, I'm not going to update the OS.

I have the bzip2 lib and development headers installed correctly on my system (those actually came from a package).

I start with absolutely NO Python on the system. I removed everything manually. I downloaded the Python 2.7.5 source, and configured with ./configure --prefix=/usr. It configures fine. I run make, and it compiles fine. I try ./python -c "import bz2; print bz2.__doc__", it works, and says:

The python bz2 module provides a comprehensive interface for the bz2 compression library. It implements a complete file interface, one shot (de)compression functions, and types for sequential (de)compression.

I then run make test and the whole test suite progresses fine, and notably the "test_bz2" test passes.

I then run make install, which installs my new Python binary into /usr/bin/ like I wanted.

I try /usr/bin/python -c "import bz2; print bz2.__doc__", and it fails with:

Traceback (most recent call last): File "", line 1, in ImportError: No module named bz2

I've tried a bunch of different things, including building Python as --enable-shared and not, no luck. I've tried at least 10 times (each time totally cleaning out everything, running make distclean, etc.). No luck.

I tried: PYTHONPATH="/usr/lib/python2.7"; export PYTHONPATH. Still no luck.

HOWEVER, if I delete the symlink that make install creates for /usr/bin/python, and instead do: ln -s /path/to/my/python/compile/python python, NOW it magically works.

So, what the heck? Why is this Python binary I'm getting created only able to find stuff when the binary exists in the compile directory, and not when it's put into normal production install location? What am I missing?

I am root during the entire process, from configure to make to make install to trying to test the Python import call.

I have started from scratch again (this time compiling with --enable-shared btw), and verified that not only in the compile directory is there build/lib.linux-x86_64-2.7/bz2.so, but once I run make install, that file is put into /usr/lib/python2.7/lib-dynload/bz2.so.

I've tried to do some reading on lib-dynload, but haven't been able to determine if there's something else a Python program (like default configuration for the CLI or whatever) would need to be able to tell it to pull module imports from lib-dynload, or if there's some other place or option to tell the make install where it should be putting it instead of dynload.

Still I have no explanation why the /path/to/compilation/python binary can find and load bz2.so fine, but the /usr/bin/python binary can't find (or load) /usr/lib/python2.7/lib-dynload/bz2.so.

I thought maybe it was something to do with the fact that the installation doesn't create like a /usr/lib/python symlink to point at /usr/lib/python2.7 directory. But I created the symlink and still no go.

I am still lost here.

Kyle Simpson

It would appear that a sort of non-answer answer was arrived at accidentally via a long string of Twitter conversation(s).

I've filed another Stack Overflow question here to ask WHY what we found was the solution to this problem: https://stackoverflow.com/questions/17662091/python-installation-prefix-not-being-persisted-in-config

For posterity sake, right now the solution is that I have to set the PYTHONHOME environment variable to /usr, and everything starts working. The puzzling part is that the documentation says PYTHONHOME should default to {prefix}, which I was clearly setting as default during configure to /usr. So why should I have to manually set it?

Running python-config --prefix reveals that the {prefix} default is in fact /usr/bin, NOT /usr like I specified, which leads to me needing to override the default back to the default, bizarrely.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

'bz2 is module not available' when installing Pandas with pip in python virtual environment

From Dev

tarfile compressionerror bz2 module is not available

From Dev

pythonbrew importing bz2 yields: ImportError: No module named '_bz2'

From Dev

Codecept installation gives me an fatal error (bz2 extension)

From Dev

Reading first lines of bz2 files in python

From Dev

How to decompress BZ2 directly into Popen stdin in Python 2.7?

From Dev

Simple encryption and decryption of strings by using bz2 in Python

From Dev

unpack bz2 url without temporary file in python

From Dev

Ansible playbook failing to find custom module

From Dev

Installation of re2 module in Python failed

From Dev

Installation of python's numpy keeps failing

From Dev

Python serial module failing to configure port

From Dev

Python Find Method in Strings Seems To Be Failing

From Dev

Python3 csv DictWriter: writing through bz2 fails (TypeError: 'str'/buffer interface)

From Dev

bz2 decompress with Python 3.4 - TypeError: 'str' does not support the buffer interface

From Dev

Uncompress an tar.bz2 file with Python tarfile module

From Dev

Python cant find module

From Dev

Python requests module - POST failing - invalid character 'o'

From Dev

Rasterio installation failing

From Dev

Git Installation is failing on Jenkins

From Dev

Visual Studio Installation Failing

From Dev

Parsing a large .bz2 file (40 GB) with lxml iterparse in python. Error that does not appear with uncompressed file

From Dev

Failing to import properties of a module

From Dev

AngularJS Failing to Instantiate Module

From Dev

module loading failing with ngRoute

From Dev

Failing to load an angular module

From Dev

Can't find module in python

From Dev

Module installed but Python cannot find it

From Dev

How to find the path of a module in python

Related Related

  1. 1

    'bz2 is module not available' when installing Pandas with pip in python virtual environment

  2. 2

    tarfile compressionerror bz2 module is not available

  3. 3

    pythonbrew importing bz2 yields: ImportError: No module named '_bz2'

  4. 4

    Codecept installation gives me an fatal error (bz2 extension)

  5. 5

    Reading first lines of bz2 files in python

  6. 6

    How to decompress BZ2 directly into Popen stdin in Python 2.7?

  7. 7

    Simple encryption and decryption of strings by using bz2 in Python

  8. 8

    unpack bz2 url without temporary file in python

  9. 9

    Ansible playbook failing to find custom module

  10. 10

    Installation of re2 module in Python failed

  11. 11

    Installation of python's numpy keeps failing

  12. 12

    Python serial module failing to configure port

  13. 13

    Python Find Method in Strings Seems To Be Failing

  14. 14

    Python3 csv DictWriter: writing through bz2 fails (TypeError: 'str'/buffer interface)

  15. 15

    bz2 decompress with Python 3.4 - TypeError: 'str' does not support the buffer interface

  16. 16

    Uncompress an tar.bz2 file with Python tarfile module

  17. 17

    Python cant find module

  18. 18

    Python requests module - POST failing - invalid character 'o'

  19. 19

    Rasterio installation failing

  20. 20

    Git Installation is failing on Jenkins

  21. 21

    Visual Studio Installation Failing

  22. 22

    Parsing a large .bz2 file (40 GB) with lxml iterparse in python. Error that does not appear with uncompressed file

  23. 23

    Failing to import properties of a module

  24. 24

    AngularJS Failing to Instantiate Module

  25. 25

    module loading failing with ngRoute

  26. 26

    Failing to load an angular module

  27. 27

    Can't find module in python

  28. 28

    Module installed but Python cannot find it

  29. 29

    How to find the path of a module in python

HotTag

Archive