How to assign bz2 to altinstall python?

I am using redhat 5.8, which comes with python 2.4 installed automatically, but I am using a python package that requires python 2.6 or higher. SO, I installed python 2.7 next to 2.4 so as not to step on the version of the system.

Now I am trying to install the package via pip and get the following error:

CompressionError: bz2 module is not available 

However, I have a module on my machine, as evidenced when I do this, the server version gives:

 [~]$ python -c "import bz2; print bz2.__doc__" 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. 

and 2.7 set the errors this way:

 [~]$ python2.7 -c "import bz2; print bz2.__doc__" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named bz2 

So, I read the following questions: Already installed and this one is very good , but none of them seems to be quite suitable. In the first case, we advise you to install the missing part, and the second question is to remove (or terminate the link) an additional python installation.

What I want to do is put in a symbolic link or some of them, so installing python 2.7 knows where bz2 is, so I can use pip to install the python package.

Thank you in


EDIT: additional information

So, after much research, it turned out that the way the variable paths are set has changed a lot in python 2.5 (maybe why the red hat hasn't been updated).

So, in python 2.7 you can add PYTHONPATH to the variable by adding a file with the extension .pth in this folder:

 /usr/local/lib/python2.7/site-packages/ 

I tried 2 ways to make this work correctly.

At first, I just uploaded a few python 2.4 path files to 2.7. This caused a different type of error:

 [~]$ python2.7 -c "import bz2; print bz2.__doc__" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: /usr/lib64/python2.4/lib-dynload/bz2.so: undefined symbol: Py_InitModule4 

So this is something.

I also tried to specify the path to the libbz2.so file in / usr / lib /, which led to a known error:

 [~]$ python2.7 -c "import bz2; print bz2.__doc__" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: No module named bz2 

I'm still at a dead end, but I feel like I'm closing.

I really could use some data from someone who has more experience setting up a programming environment. I am much more comfortable writing code :)

+4
source share
3 answers

Just did it yesterday on the same platform and got her job. Here is what I did:

Set CFLAGS="-I/path/to/bz2/include" and LDFLAGS="-L/path/to/bz2/lib" . Verify that the bz2 library library path is set to LD_LIBRARY_PATH . However, you may have to do make distclean and configure && make && make install .

If this fails, edit setup.py and make a replacement similar to the following:

 # Gustavo Niemeyer bz2 module. if (self.compiler.find_library_file(['/home/someuser/packages/libbz2/lib'], 'bz2')): #lib_dirs, 'bz2')): 

Note that the part of the comment at the end of the second line is the original remainder of the setup.py line.

In addition, I found that I just download and create the latest version of bz2 and point out all of the above to this easier than trying to get a working version of the system.

Despite this, it definitely works. I did it yesterday :)

+7
source

Every time you work with python other than the one installed by the system, I highly recommend using http://pypi.python.org/pypi/virtualenv . He creates a sandbox for you with his own copy of python and reinstalls all the paths, etc., to indicate a new copy. Then you can use pip to install any packages you need.

+1
source

The other answers provided are helpful and helpful, but that is how I got it to work.

The problem was not that Python did not find the files (as I thought), it simply could not use them correctly. So, I went into the Makefile for bzip2, found a line that looked like this:

 CFLAGS= -Wall -Winline -O2 -g $(BIGFILES) 

and added -fPIC to the line as follows:

 CFLAGS=-fPIC -Wall -Winline -O2 -g $(BIGFILES) 

and WHALA! It compiled just fine.

0
source

All Articles