編譯安裝帶ssl 模塊指定版本Python


 

 
出現這個或者fatal error: openssl/名單.h: No such file or directory。都是沒有安裝libssl-dev~
libssl-dev包含libraries, header files and manpages,他是openssl的一部分,而openssl對ssl進行了實現~
解決方案:
要在Debian、Ubuntu或者其他衍生版上安裝OpenSSL:
  1. $ sudo apt-get install libssl-dev
要在FedoraCentOS或者RHEL上安裝OpenSSL開發包:
  1. $ sudo yum install openssl-devel
https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tar.xz wget 下載指定安裝包解壓縮,
tar -xvf Python-2.7.tar.bz2
cd Python-2.7
修改python setup 配置,開啟ssl模塊:
因為編譯 python 的時候沒有把 ssl模塊 編譯進去,只需修改 Modules/Setup文件 重新編譯安裝即可。
進入python安裝包,找到Setup文件,用 vi 打開
  1. cd Python-2.7.11/Modules
  1. vi Setup.dist
找到
  1. # Socket module helper for SSL support; you must comment out the other
  1. # socket line above, and possibly edit the SSL variable:
  1. #SSL=/usr/local/ssl#_ssl _ssl.c \
  1. #       -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
  1. #       -L$(SSL)/lib -lssl -lcrypto
把前面的 # 號去掉,修改為
  1. # Socket module helper for SSL support; you must comment out the other
  1. # socket line above, and possibly edit the SSL variable:
  1. SSL=/usr/local/ssl
  1. _ssl _ssl.c \
  1.        -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \       -L$(SSL)/lib -lssl -lcrypto
保存退出,重新編譯安裝(注意:
安裝python之前,最好確認一下gcc是否安裝。apt-get install -y gcc
如果提示make:command not found則用apt-get -y install gcc automake autoconf libtool make先安裝編譯器
否則./configure 階段就會報錯了)
  1. ./configure --enable-shared       #這里一定要注意,解壓完之后要設置enable-shared參數, 在wsgi.py 在web server中python 才能在apache或者Nginx運行
  1. make && make install
 
  1. sudo apt-get install sqlite
  1. sudo apt-get install libsqlite3-dev
  1. 如果安裝django如果錯誤的最后一行是
  1. django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
  1. 則可以試一下命令
 
 
  1. tar -xzf pysqlite-2.6.3.tar.gz
  1. cd pysqlite
  1. python setup.py install
 
 
 
  1. sudo apt-get install openssl
  1. sudo apt-get install libssl-dev
  1. RedHat、centos才是openssl-devel
完成如果遇到錯誤:
 
python: error while loading shared  libraries: libpython2.7.so.1.0: 
  cannot open shared object file: No such file or
   
解決方案: 
新建下面文件
  vim /etc/ld.so.conf.d/python2.7.conf
  加入內容:
  /usr/local/lib
  保存退出后運行:
  ldconfig
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM