python沒刪干凈安裝之后報錯,python2.7安裝報錯_python2.7源碼安裝方式

 2023-10-04 阅读 29 评论 0

摘要:安裝python2.7python沒刪干凈安裝之后報錯?下載Python 2.7, 下載地址解壓安裝python源碼分享網站。tar -xzvf Python-2.7.15.tgzcd Python-2.7.15./configure --prefix=/opt/local/python --enable-sharedmake && make install配置環境變量vim ~/.bash_profile編

安裝python2.7

python沒刪干凈安裝之后報錯?下載Python 2.7, 下載地址

解壓安裝

python源碼分享網站。tar -xzvf Python-2.7.15.tgz

cd Python-2.7.15

./configure --prefix=/opt/local/python --enable-shared

make && make install

配置環境變量

vim ~/.bash_profile

編輯內容

PYHOME=/opt/local/python

export PATH=$PYHOME/bin:$PATH

導入變量

source ~/.bash_profile

查看版本號

python --version

安裝setuptools

下載setuptools 安裝包, 下載地址

tar -xzvf setuptools-39.2.0.tgz

cd setuptools-39.2.0

python setup.py install

安裝pip

下載pip 安裝包, 下載地址

tar -xzvf pip-10.0.1.tgz

cd pip-10.0.1

python setup.py install

FAQ

提示readline找不到

報錯信息

Python 2.7.15 (default, May 29 2018, 13:09:02)

[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2

Type "help", "copyright", "credits" or "license" for more information.

Traceback (most recent call last):

File "/etc/pythonstart", line 7, in

import readline

ImportError: No module named readline

解決方法

安裝readline,從pipy網站下載源碼

tar -xzvf readline-6.2.4.1.tgz

cd readline-6.2.4.1

python setup.py install

執行python setup.py 提示md5找不到

報錯信息

kwe1000570040:/opt/local/soft/python/setuptools-39.2.0 # python setup.py install

ERROR:root:code for hash md5 was not found.

Traceback (most recent call last):

File "/opt/local/python/lib/python2.7/hashlib.py", line 147, in

globals()[__func_name] = __get_hash(__func_name)

File "/opt/local/python/lib/python2.7/hashlib.py", line 97, in __get_builtin_constructor

raise ValueError('unsupported hash type ' + name)

ValueError: unsupported hash type md5

ERROR:root:code for hash sha1 was not found.

解決方法

該錯誤是由于python找不到openssl導致,如果openssl安裝位置有變化可能會導致該問題。

python2.7依賴于openssl_1.0.0,需要下載源碼安裝:

wget https://www.openssl.org/source/openssl-1.0.2o.tar.gz

tar -xzvf openssl-1.0.2o

cd openssl-1.0.2o

./config shared

make && make install

openssl默認會安裝到 /usr/local/ssl目錄中,其中lib目錄存放了libssl.so.1.0.0動態鏈接庫。

接下來是將lib目錄添加到ldconfig路徑:

echo "/usr/local/ssl/lib" >> /etc/ld.so.conf

ldconfig

再次執行python程序,問題解決。

如果希望更改openssl的安裝路徑,可以執行prefix參數(安裝目錄)、openssldir參數(配置、證書路徑)

./config shared --prefix=/usr/local/openssl --openssldir=/usr/local/openssl

更多參數可參考這里

提示libpython2.7.so.1.0 找不到

在import 某些庫的時候報錯:

ImportError: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

解決方法

需要讓ldconfig找到libpython動態鏈接庫

echo "/opt/local/python/lib" >> /etc/ld.so.conf

ldconfig

參考文檔

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/111989.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息