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

本文提供了在Python 2.7环境下成功安装cleverhans 3.0.1的方法,包括安装所需依赖包dm-tree的具体步骤,以及解决过程中遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、前提说明

        笔者最近正在复现对抗样本检测论文的实验代码,如下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包版本解决了该问题。

 

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值