Windows rllab环境搭建和运行中报错

存一下自己装的过程,怕忘记了

Windows rllab环境搭建和运行中报错

安装rllab

https://github.com/rll/rllab下载zip,解压后将文件夹rllab放入到anaconda虚拟环境的\Lib\site-packages文件夹中。
但是如果要使用“pickled”模块的话,为了正常运行代码,可能还需要将解压后的文件夹scripts也移动到\Lib\site-packages文件夹中,因为测试代码中用到了run_experiment_lite.py。

rllab在Linux下的安装说明中需要改变pythonpath,我在这里使用了pycharm修改的,不知道对不对,参考

同时安装了swig,参考(不知道不安装可不可以,因为不太明白swig的作用)

安装box2d

参考
直接在box2d下载相应的whl,注意根据自己环境选择相应的whl。我安装的Python是3.7,所以选择
在这里插入图片描述
这里有一个坑:我一开始安装的是2.3.10版本,运行例子,在调用box2d的时候,一直报错“DLL load failed: 找不到指定的模块”。后来改成了2.3.2就没事了。这个报错在网上查到的结果基本都是库可能损坏,重装🤣,我也没弄明白为什么。

测试

用的rllab说明文档中的测试

from rllab.algos.trpo import TRPO
from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline
from rllab.envs.box2d.cartpole_env import CartpoleEnv
from rllab.envs.normalized_env import normalize
from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy

env = normalize(CartpoleEnv())

policy = GaussianMLPPolicy(
    env_spec=env.spec,
    # The neural network policy should have two hidden layers, each with 32 hidden units.
    hidden_sizes=(32, 32)
)

baseline = LinearFeatureBaseline(env_spec=env.spec)

algo = TRPO(
    env=env,
    policy=policy,
    baseline=baseline,
    batch_size=4000,
    whole_paths=True,
    max_path_length=100,
    n_itr=40,
    discount=0.99,
    step_size=0.01,
)
algo.train()
from rllab.algos.trpo import TRPO
from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline
from rllab.envs.box2d.cartpole_env import CartpoleEnv
from rllab.envs.normalized_env import normalize
from rllab.misc.instrument import run_experiment_lite
from rllab.policies.gaussian_mlp_policy import GaussianMLPPolicy


def run_task(*_):
    env = normalize(CartpoleEnv())

    policy = GaussianMLPPolicy(
        env_spec=env.spec,
        # The neural network policy should have two hidden layers, each with 32 hidden units.
        hidden_sizes=(32, 32)
    )

    baseline = LinearFeatureBaseline(env_spec=env.spec)

    algo = TRPO(
        env=env,
        policy=policy,
        baseline=baseline,
        batch_size=4000,
        max_path_length=100,
        n_itr=1000,
        discount=0.99,
        step_size=0.01,
        # Uncomment both lines (this and the plot parameter below) to enable plotting
        # plot=True,
    )
    algo.train()


run_experiment_lite(
    run_task,
    # Number of parallel workers for sampling
    n_parallel=1,
    # Only keep the snapshot parameters for the last iteration
    snapshot_mode="last",
    # Specifies the seed for the experiment. If this is not provided, a random seed
    # will be used
    seed=1,
    # plot=True,
)

报错处理

  • ImportError: cannot import name ‘MemmapingPool’
    解决: 修改源文件,MemmapingPool 改成 MemmappingPool

  • ImportError: cannot import name downsample
    在这里插入图片描述这是由于安装theano是新版,换之前的版本
    解决: pip install --upgrade https://github.com/Lasagne/Lasagne/archive/master.zip
    参考

  • fatal: Not a git repository (or any of the parent directories): .git
    https://blog.csdn.net/s1674521/article/details/71844169
    在代码所在的文件夹中git init

  • 时间格式报错在这里插入图片描述
    解决:https://blog.csdn.net/shomy_liu/article/details/44141483
    将图中的格式变成下面的:

    '%Y-%m-%d %H:%M:%S %f'
    
  • 参数不正确
    在这里插入图片描述
    这里可能是源码在参数处理的时候不太好,我直接修改函数源码,找到run_experiment_lite.py文件(在rllab解压缩后的scripts中)的to_local_command函数,加了一个elif

        for k, v in params.items():
            if isinstance(v, dict):
                for nk, nv in v.items():
                    if str(nk) == "_name":
                        command += "  --%s %s" % (k, _to_param_val(nv))
                    else:
                        command += \
                            "  --%s_%s %s" % (k, nk, _to_param_val(nv))
            elif isinstance(v, int):
                command += "  --%s %d" % (k,v)
            else:
                command += "  --%s %s" % (k, _to_param_val(v))
    
  • OSError: [WinError 123] 文件名、目录名或卷标语法不正确。: “'C:”
    这个问题在函数os.makedirs中,没弄明白是为什么,好像这个函数的参数必须是绝对路径,或者是传进去的参数不对?而rllab中,参数是虚拟环境安装的相对路径。
    解决方法:直接在调用run_experiment_lite函数的时候,传入log的地址。

    run_experiment_lite(
        run_task,
        # Number of parallel workers for sampling
        n_parallel=1,
        # Only keep the snapshot parameters for the last iteration
        snapshot_mode="last",
        # Specifies the seed for the experiment. If this is not provided, a random seed
        # will be used
        seed=1,
        # plot=True,
        log_dir = './data',
    )
    
    

    测试之后还是有点问题,最后生成的文件夹如下图:(还是没明白这个问题在哪)
    在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值