安装后 CentOs 上的 Python 2.6 问题

标签 python compilation installation

我最近一直在自学 python,遇到了一个例子,其中 str.endswith 将一个元组作为它的第一个参数,2.4 不支持。我决定尝试在我的机器上安装更新版本的 Python,以便了解最新情况。机器是CentOs5。

作为机器上的用户(不是 root),我从这里提取了软件包:http://www.python.org/ftp/python/2.6.7/ ,解压缩它,执行 ./configure --prefix=/home/myusername/python/compiler/Python-2.6.7-installed ,然后运行 ​​make,make test (一切都好),然后最后进行 altinstall 以达到良好的效果(我知道不需要执行 altinstall,因为我指定了前缀,但确实不想破坏这台机器上的常规 python)。当它第一次不起作用时,我也尝试以 root 身份进行 make altinstall,但没有什么区别。

当我尝试针对二进制文件运行脚本时,我只是得到一堆像这样的乱码:

./compiler/Python-2.6.7/Lib/test/test_re.pyc :   onXtd}|iti|iddddgdS(Nsu"     [\u002E\u3002\uFF0E\uFF61]"sa.b.cR$RHRX(R0RÑRÚR        RRY(R                                                                                                                                             R7((s@/home/yspendiff/python/compiler/Python-2.6.7/Lib/test/test_re.pyttest_bug_931848as
Cstidd}|i|iid|it|itidd}|i|i     id|i|i  ddS(Ns\ssa bii(ii(ii(
StopIterationRºRR(R                                          RRÓR       tnextRR4t
Rº((s@/home/yspendiff/python/compiler/Python-      2.6.7/Lib/test/test_re.pyttest_bug_581080js
 cCsatidd}|i|iid|i|iid|it|idS(Ns.*tasdfii(ii(ii(RRÓR     RÝRR4RÞ(R

也许更相关的是很多像这样的行:

./compiler/Python-2.6.7/Lib/test/test_unicode.py :           self.assert_(u'asdf' not in '')
./compiler/Python-2.6.7/Lib/test/test_unicode.py :           self.assert_('asdf' not in u'')
./compiler/Python-2.6.7/Lib/test/test_unicode.py :           self.assert_(u'asdf' not in u'')
./compiler/Python-2.6.7/Lib/test/test_re.py :           iter = re.finditer(r".*", "asdf")
./compiler/Python-2.6.7/Lib/test/string_tests.py :           self.checkequal(True,  'asdf', '__contains__', 'asdf')
./compiler/Python-2.6.7-installed/lib/python2.6/test/test_unittest.py :               loader.loadTestsFromNames(['sdasfasfasdf'])
./compiler/Python-2.6.7-installed/lib/python2.6/test/test_unittest.py :               self.assertEqual(str(e), "No module named sdasfasfasdf")

这只是数百行中的几行。我没有搞乱任何默认选项,我是否下拉过一个有趣的版本或指定了一些有趣的编译选项。我如何将其关闭,以便我可以安静地编码!

如果有人感兴趣的话,代码如下。我只是用 ./Findword.py asdf 调用它:

#!/home/myusername/python/compiler/Python-2.6.7-installed/bin/python2.6

### FindWord.py

import os                                 # for curdir()            #(A)
import os.path                            # for join(), isfile()    #(B)
import sys                                # for argv[], exit()      #(C)


if len( sys.argv ) != 2:                                            #(D)
    print "need a word or a single-quoted phrase to search for"     #(E)
    sys.exit(1)                                                     #(F)

def searchInFile( pattern, dirname, filenames ):                    #(G)
    for name in filenames:                                          #(H)
        name = os.path.join( dirname, name )                        #(I)
        if os.path.isfile( name ) and not name.endswith(('.pdf','.pl')):   #(J)
            FH = open( name, 'r' )                                  #(K)
            for eachline in FH:                                     #(L)
                if ( eachline.find( pattern ) != -1 ):              #(M)
                    print name, ':  ', eachline                     #(N)

os.path.walk( os.curdir, searchInFile, sys.argv[1] )                #(O)

最佳答案

几乎正是您要求 Python 做的事情正在发生。你告诉它从当前目录中查找单词“asdf”,它在二进制文件中查找它。

关于安装后 CentOs 上的 Python 2.6 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8888035/

相关文章:

c - 这个 "c(.text+0x7): relocation truncated to fit: 8 .data"是什么类型的错误

ruby - 如何下载特定库 Ruby、Gems 和 Rails 并在 Ubuntu 中安装它们

haskell - 安装 zlib 时 ghc.exe 无法执行 ld.exe

c# - 如何编写我也可以作为 winforms 程序运行的 c# 服务?

python - 在hadoop python中处理多个文件

gwt - 大型 GWT 项目和编译时间问题

python - 如何提取之间的文本 <br> python

c++ - 为什么我会收到此错误消息 : "undefined reference to ` PerformChat(char*, char*, char*, char*, char* )'"

python - Python如何从一个函数返回多个值?

python - matplotlib 无法在 OS X 中运行,错误为 ' TKApplication is implemented in both'