简体   繁体   English

如何在CentOS上安装python 2.6模块?

[英]How to install a module for python 2.6 on CentOS?

After I install python 2.6 on CentOS by: 我在CentOS上安装python 2.6之后:

 wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
 sudo rpm -ivh epel-release-5-4.noarch.rpm
 yum install python26

Then I install pyPdf by: 然后我通过以下方式安装pyPdf

 yum install pyPdf

However, the pyPdf is only available to the old python 2.4: 但是, pyPdf只适用于旧的python 2.4:

# python
Python 2.4.3 (#1, Jan  9 2013, 06:49:54) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyPdf
>>> import sys
>>> print sys.path
['', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/Numeric', '/usr/lib/python2.4/site-packages/gtk-2.0']

it's not available to the newly install python 2.6: 它不适用于新安装的python 2.6:

# python26
Python 2.6.8 (unknown, Nov  7 2012, 14:47:34) 
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages']
>>> import pyPdf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named pyPdf

How can I install pyPdf for python 2.6? 如何为python 2.6安装pyPdf

How about creating a virtualenv and install pyPdf with pip 如何创建virtualenv并使用pip安装pyPdf

$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-X.X.tar.gz
$ tar xvfz virtualenv-X.X.tar.gz
$ cd virtualenv-X.X
$ python26 virtualenv.py myVirtualenv
$ source myVirtualenv/bin/activate
$ pip install pyPdf

Read more about virtualenv here 在这里阅读更多关于virtualenv的信息

Not sure how you're doing it. 不确定你是怎么做的。 I have recently installed pyPdf on CentOS for Python 2.7. 我最近在CentOS for Python 2.7上安装了pyPdf。 A simple yum worked for me. 一个简单的yum为我工作。

yum install pyPdf yum安装pyPdf

pyPdf is also available for newer versions. pyPdf也适用于较新版本。 Check here 点击这里

Edit: 编辑:

May be having two different versions of Python is causing this issue for you. 可能有两个不同版本的Python导致此问题。 CentOS comes with default installation of v2.4. CentOS附带v2.4的默认安装。 Remove all the previous versions and install again. 删除所有以前的版本并重新安装。

For CentOS version lower than 6, python 2.4 comes by default. 对于低于6的CentOS版本,默认情况下是python 2.4。 For version 6 and above its python2.6 . 对于版本6及更高版本的python2.6。

Now I would strictly advise not to upgrade the base Python installation ie python2.4 in the earlier versions, as that would break lot of system level funcationalities that expect default python to be 2.4. 现在我严格建议不要在早期版本中升级基础Python安装,即python2.4,因为这会破坏许多系统级功能,这些功能期望默认python为2.4。

Your question can be solved in multiple ways : 您的问题可以通过多种方式解决:

  1. yum install always does an installation for default python. yum install总是安装默认的python。 If its 2.4 it will install the package for 2.4. 如果它的2.4将安装2.4的包。
  2. To install package for 2.6, download easy_install for 2.6 or PIP for 2.6 and then simply do easy_install {{package_name}} or pip install {{package_name}} 要安装2.6的软件包,请下载easy_install for 2.6或PIP for 2.6,然后只需执行easy_install {{package_name}}或pip install {{package_name}}
  3. To keep your environments different, as suggested by @Dikei install a virtual-env and then install your packages. 为了保持环境的不同,请按照@Dikei的建议安装虚拟环境,然后安装软件包。 This is method is one of the best practices for maintaining multiple python environments. 这种方法是维护多个python环境的最佳实践之一。

Quick installation of Python !!! 快速安装Python !!!

Get the latest verion of Python 2.6.9 获取Python 2.6.9的最新版本

wget https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tar.xz   

Extract thae package 提取包装

tar xf Python-2.6.9.tar.xz  

Configure them 配置它们

cd Python-2.6.9
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"

Install them 安装它们

make && make altinstall

Check Version: 检查版本:

python --version
Python 2.6.9

Credits : https://danieleriksson.net 致谢https//danieleriksson.net

Hope this helps !!! 希望这可以帮助 !!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM