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 GaussianMLPPolicyenv = 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 GaussianMLPPolicydef 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 samplingn_parallel=1,# Only keep the snapshot parameters for the last iterationsnapshot_mode="last",# Specifies the seed for the experiment. If this is not provided, a random seed# will be usedseed=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 samplingn_parallel=1,# Only keep the snapshot parameters for the last iterationsnapshot_mode="last",# Specifies the seed for the experiment. If this is not provided, a random seed# will be usedseed=1,# plot=True,log_dir = './data',
    )

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


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部