Python2.7安装cleverhans==3.0.1的解决办法

一、前提说明

        笔者最近正在复现对抗样本检测论文的实验代码,如下Detecting Adversarial Samples Using Influence Functions and Nearest Neighborsicon-default.png?t=M85Bhttps://arxiv.org/abs/1909.06872       

        其中有个最主要的包cleverhans==3.0.1,该包是用于对抗样本生成的库,尝试了多种常规方法后最终找到了python2.7成功安装cleverhans==3.0.1的方法。复现该篇论文时,还有许多其它的坑,笔者也会通过另一篇博文进行分享并提供解决办法。

二、python2.7安装cleverhans==3.0.1的解决办法

        按顺序执行以下指令,其中涉及的包的版本号尽量不要替换,因为本人其他版本未测过。      

pip install dm-tree==0.1.1

pip install cleverhans

        安装完成后,进行包查看,如下成功安装。

 

三、python2.7安装cleverhans==3.0.1报过的错(可不看)

        3.1 通过pip安装cleverhans报错

$ pip install cleverhans==3.0.1

Collecting dm-tree
  Using cached https://files.pythonhosted.org/packages/1c/ed/a9848a5d3dff0fc5c9c6f5120ae98c152ff47700a731958ff034a576ee27/dm-tree-0.1.7.tar.gz
    ERROR: Command errored out with exit status 1:
     command: /home/ljd_XUT/anaconda3/envs/tf1_py2/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-H_Ks75/dm-tree/setup.py'"'"'; __file__='"'"'/tmp/pip-install-H_Ks75/dm-tree/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-install-H_Ks75/dm-tree/pip-egg-info
         cwd: /tmp/pip-install-H_Ks75/dm-tree/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-H_Ks75/dm-tree/setup.py", line 81
        f'CMake must be installed to build the following extensions: {ext_names}'
                                                                                ^
    SyntaxError: invalid syntax
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

        报错原因很明显,安装cleverhans包需安装支持包dm-tree-0.1.7,正是支持包dm-tree安装失败导致cleverhans包无法正常安装。于是笔者转向先单独安装dm-tree-0.1.7包,进行了如下尝试(均以失败告终,记下也是希望能被其它复现论文的博友看到)

        3.2 通过pip安装dm-tree报错

        3.3 通过python setup.py install安装dm-tree报错

        该法需要先下载dm-tree-0.1.7.tar.gz,解压后会有setup.py文件,再通过该文件安装dm-tree

        3.4 通过 pip install git+git://github.com/deepmind/tree.git报错

        该法是dm-tree-0.1.7.tar.gz解压后的README.md中提供安装方法。

 综上报错,我们可以怀疑是dm-tree-0.1.7包本身存在问题,故替换dm-tree包版本解决了该问题。

 


版权声明:本文为qq_39940390原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
THE END
< <上一篇
下一篇>>