Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
属性错误:';模块';对象没有属性python_Python_Linux_Ubuntu_Installation_Debian - Fatal编程技术网

属性错误:';模块';对象没有属性python

属性错误:';模块';对象没有属性python,python,linux,ubuntu,installation,debian,Python,Linux,Ubuntu,Installation,Debian,我对python相当陌生,并尝试按照所描述的步骤安装Python2.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",

我对python相当陌生,并尝试按照所描述的步骤安装Python2.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仍然提供相同的输出,而不考虑输入。我问了以下问题:

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'
编辑#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给出的输出相同:

sudo apt-get install python-setuptools
...
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
然后继续执行到第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
成功。这使我相信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
这些模块是必需的吗?

文件“/usr/lib/python2.7/hashlib.py”,第138行,在 _hashlib.openssl\u md\u meth\u名称) AttributeError:“模块”对象没有属性“openssl\u md\u meth\u names”

可以通过运行以下命令进行修复:

pip install hashlib


这是一条古老的线索,但我的回答将来可能会帮助其他人

第一步。通过以下内容检查_hashlib.openssl_md_meth_名称,不会显示任何错误

$ 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

然后就完成了。

在我的例子中,我使用的是virtualenv刚刚将virtualenv文件夹从旧机器复制到新机器中。。。在我的新版本中,当我尝试安装pip软件包时,它抛出了这个错误


我通过再次创建新的virtualenv重新安装的pip包解决了这个问题

@Alex Martelli。是的,已编辑。您的
--重新安装
不会提供2.7.9版本,而是提供Debian repo提供的任何版本,可能是2.7.5版本。该方法实际上是在2.7.9中引入的,您可能会在库中混合安装不同且不兼容的Python和C文件版本。查看第二个答案,了解如何通过不稳定的回购和钉住(棘手)为Debian获得2.7.9。但无论如何,首先要卸载你当前损坏的Python,然后从头开始重新安装。@Alex Martelli。我正在尝试恢复以前的安装(针对Debian)。它正在正确安装。但是,我无法运行任何需要hashlib的脚本,pip似乎已损坏。因此,您可能会有一些
2.7.9
安装尝试:全部卸载,查找所有常见的可疑目录,查找出于任何原因未被连根拔起的散乱部分,然后重新启动。这实际上是一个系统管理问题,而不是编程问题,因此您可能会更幸运地询问ServerFault,sysadm大师往往会在哪里闲逛如果是ubuntu而不是普通的debian,那么可能性很大——更应该在askubuntu.com上询问真正的ubuntu向导在哪里,而不是在这个专注于编程的网站上
./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
pip install hashlib
easyinstall hashlib
easy_install-2.7 hashlib
$ 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'])
>>> 
File "/usr/lib/python2.7/random.py", line 49, in <module>
import hashlib as _hashlib
import _hashlib