![](/img/trans.png)
[英]Python: AttributeError: 'module' object has no attribute 'socketpair'
[英]AttributeError: 'module' object has no attribute python
我是python的新手,並嘗試按照此處描述的步驟安裝python 2.7.9。 安裝失敗,並出現以下錯誤:
python make: *** [libinstall] Error 1
我嘗試重新安裝以前版本的python:
sudo apt-get install --reinstall python2.7-dev
安裝正常進行。 但是,現在,當嘗試導入hashlib時,我收到以下錯誤:
Traceback (most recent call last):
File "./server.py", line 5, in <module>
import hashlib
File "/usr/lib/python2.7/hashlib.py", line 138, in <module>
_hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
我也無法使用pip安裝任何軟件包,因為提供的唯一輸出如下:
Traceback (most recent call last):
File "/usr/bin/pip", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
我安裝了python-setuptools :
sudo apt-get install python-setuptools
無論輸入如何, pip仍然提供相同的輸出。 跟着這個問題我跑了:
curl -O https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
chmod +x ez_setup.py
python ez_setup.py
輸出是:
Traceback (most recent call last):
File "ez_setup.py", line 19, in <module>
import tempfile
File "/usr/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
File "/usr/lib/python2.7/random.py", line 49, in <module>
import hashlib as _hashlib
File "/usr/lib/python2.7/hashlib.py", line 138, in <module>
_hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
問題在哪里?
編輯#1:
sudo apt-get install --reinstall python2.7-dev的輸出似乎正常:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libjs-sphinxdoc linux-headers-generic linux-image-generic
Use 'apt-get autoremove' to remove them.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 310 not upgraded.
Need to get 0 B/269 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 219657 files and directories currently installed.)
Preparing to unpack .../python2.7-dev_2.7.6-8_amd64.deb ...
Unpacking python2.7-dev (2.7.6-8) over (2.7.6-8) ...
Processing triggers for man-db (2.6.7.1-1) ...
Setting up python2.7-dev (2.7.6-8) ...
編輯#2:
我發現這個問題解決了類似的問題。 它指向此線程使用checkinstall來檢索所有寫入的文件並從中創建.deb包:
sudo apt-get install checkinstall # install the checkinstall package
cd /home/user/Python-2.7.9
sudo checkinstall -D --fstrans=no make install # make the deb package
運行最后一個命令后,提供的輸出與make install給出的輸出相同:
...
Listing /usr/lib/python2.7/xml/parsers ...
Compiling /usr/lib/python2.7/xml/parsers/__init__.py ...
Compiling /usr/lib/python2.7/xml/parsers/expat.py ...
Listing /usr/lib/python2.7/xml/sax ...
Compiling /usr/lib/python2.7/xml/sax/__init__.py ...
Compiling /usr/lib/python2.7/xml/sax/_exceptions.py ...
Compiling /usr/lib/python2.7/xml/sax/expatreader.py ...
Compiling /usr/lib/python2.7/xml/sax/handler.py ...
Compiling /usr/lib/python2.7/xml/sax/saxutils.py ...
Compiling /usr/lib/python2.7/xml/sax/xmlreader.py ...
Compiling /usr/lib/python2.7/xmllib.py ...
Compiling /usr/lib/python2.7/xmlrpclib.py ...
Compiling /usr/lib/python2.7/zipfile.py ...
make: *** [libinstall] Error 1
編輯#3:
似乎所有腳本都無法運行。 我正在研究簽名算法(用於比特幣), 這里提到的工具(bu,tx)都輸出相同的錯誤:
Traceback (most recent call last):
File "/usr/local/bin/bu", line 5, in <module>
from pkg_resources import load_entry_point
ImportError: No module named pkg_resources
編輯#4:
我也試過這里提到的方法。 python get-pip.py的輸出如下:
Traceback (most recent call last):
File "get-pip.py", line 28, in <module>
import tempfile
File "/usr/lib/python2.7/tempfile.py", line 35, in <module>
from random import Random as _Random
File "/usr/lib/python2.7/random.py", line 49, in <module>
import hashlib as _hashlib
File "/usr/lib/python2.7/hashlib.py", line 138, in <module>
_hashlib.openssl_md_meth_names)
AttributeError: 'module' object has no attribute 'openssl_md_meth_names'
如果我評論該行:
import tempfile
然后執行繼續到第141行:
Traceback (most recent call last):
File "get-pip.py", line 19892, in <module>
main()
File "get-pip.py", line 141, in main
tmpdir = tempfile.mkdtemp()
NameError: global name 'tempfile' is not defined
意思是導入以下庫:
import os.path
import pkgutil
import shutil
import sys
import struct
# import tempfile
成功。 這讓我相信python2.7.9的安裝只是部分完成(正如在這個問題的評論中明智地建議的那樣)。
編輯#5:
我已經重新配置了配置和編譯步驟:
./configure --prefix=/usr \
--enable-shared \
--with-system-expat \
--with-system-ffi \
--enable-unicode=ucs4 &&
make
構建終止於:
Python build finished, but the necessary bits to build these modules were not found:
bsddb185 dl imageop
sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
running build_scripts
這些模塊必不可少?
這是一個老話題,但我的答案可能在將來幫助其他人。
步驟1.通過以下方法檢查_hashlib.openssl_md_meth_names,並且不會顯示錯誤。
$ python
Python 2.7.9 (default, Oct 20 2016, 07:39:46)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import _hashlib
>>> _hashlib.openssl_md_meth_names
frozenset(['SHA256', 'SHA512', 'dsaWithSHA', 'md4', 'sha256', 'sha512', 'RIPEMD160', 'md5', 'whirlpool', 'SHA1', 'SHA224', 'SHA', 'SHA384', 'ecdsa-with-SHA1', 'MD4', 'DSA', 'sha1', 'DSA-SHA', 'sha224', 'dsaEncryption', 'ripemd160', 'sha', 'MD5', 'sha384'])
>>>
第2步:
改變以下行:
File "/usr/lib/python2.7/random.py", line 49, in <module>
import hashlib as _hashlib
成:
import _hashlib
然后它完成了。
文件“/usr/lib/python2.7/hashlib.py”,第138行,在_hashlib.openssl_md_meth_names中)AttributeError:'module'對象沒有屬性'openssl_md_meth_names'
可以通過運行修復:
pip install hashlib
要么
easyinstall hashlib
要么
easy_install-2.7 hashlib
在我的情況下,我使用virtualenv只是將virtualenv文件夾從舊機器復制到新...在我新的時候,當我嘗試安裝pip包時,它拋出了這個錯誤..
我通過再次創建新的virtualenv重新安裝的pip包解決了這個問題...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.