1. 程式人生 > >編譯可移植的python

編譯可移植的python

cal pytho 通用 chm 需要 install 16px 執行權 sed

1. 在低版本系統機器上,編譯python:
  cd  Python-2.7.15/Modules
  vim Setup.dist
  修改下述代碼:
  ###########
sed -i s/#SSL=\/usr\/local\/ssl/SSL=\/usr\/local\/ansible_python\/openssl_for_python/g Modules/Setup.dist
sed -i s/#_ssl _ssl.c/_ssl _ssl.c/g Modules/Setup.dist
sed -i s/#\t-DUSE_SSL/\t-DUSE_SSL/g Modules/Setup.dist
sed 
-i s/#\t-L$(SSL)/\t-L$(SSL)/g Modules/Setup.dist sed -i s/#_md5 md5module.c md5.c/_md5 md5module.c md5.c/g Modules/Setup.dist sed -i s/#zlib zlibmodule.c/zlib zlibmodule.c/g Modules/Setup.dist sed -i s/#binascii binascii.c/binascii binascii.c/g Modules/Setup.dist sed -i s/#_sha1 sha1module.c/_sha1 sha1module.c/g
Modules/Setup.dist sed -i s/#_sha256 sha256module.c/_sha256 sha256module.c/g Modules/Setup.dist sed -i s/#_sha512 sha512module.c/_sha512 sha512module.c/g Modules/Setup.dist ############ 2. 指定openssl庫 編譯新的openssl庫 cd openssl-1.0.2o ./configure --prefix=/usr/local/ansible_python/openssl_for_python make make install
3. 由於python編譯的時候需要去/usr/local/ssl/目錄下尋找openssl庫(具體可看setup.py),所以需要創建新編譯openssl的軟鏈接 ln -s /usr/local/ansible_python/openssl_for_python /usr/local/ssl 4. cd Python-2.7.15 ./configure –prefix=/usr/local/ansible_python/python make make install 安裝完成後,可以安裝anshible等模塊,方便移植 5. 將自己編譯的openssl庫放進系統共享庫 echo “/usr/local/ansible_python/openssl_for_ansible/lib” >> /etc/ld.so.conf.d/ansible.conf
ldconfig
6. 壓縮編譯好的python和openssl,以便於移植 tar -cvjf ansible_python.tar.bz2 ansible_python 7. 將壓縮包拷貝到新機器上/tmp目錄後,解壓 /tmp/ansible_python.tar.bz2 tar -xvjf /tmp/ansible_python.tar.bz2 得到 /tmp/ansible_python 8. 拷貝文件 cp -r /tmp/ansible_python /usr/local/ 9. 修改權限,使普通用戶具有執行權限 chown -R ops:ops /usr/local/ansible_python/openssl_for_ansible/ chmod 755 /usr/local/ansible_python/python/bin/* 10. 創建指定的ssl庫的軟鏈 ln -s /usr/local/ansible_python/openssl_for_ansible/ /usr/local/ssl 11. 將指定的ssl庫添加到系統共享庫 echo “/usr/local/ansible_python/openssl_for_ansible/lib” >> /etc/ld.so.conf.d/ansible.conf 12. 執行命令 ldconfig 13. 此時新python已經可以使用 /usr/local/ansible_python/python/bin/python

編譯可移植的python