rll / rllab

rllab is a framework for developing and evaluating reinforcement learning algorithms, fully compatible with OpenAI Gym.
Other
2.89k stars 802 forks source link

Running experiments in PyCharm: run_experiment_lite.py cannot locate rllab #101

Closed joistick11 closed 7 years ago

joistick11 commented 7 years ago

Hi guys.

I am using Linux and trying to run rllab experiments using PyCharm. I've selected interpreter from anacondas envs and PyCharm locates rllab and I am able to use auto-complete as well. But when I am trying to run the program, the following error occurs:

Traceback (most recent call last):
  File "..../anaconda2/envs/rllab3/lib/python3.5/site-packages/rllab-0.1.0-py3.5.egg/scripts/run_experiment_lite.py", line 5, in <module>
    from rllab.misc.ext import is_iterable, set_seed
ImportError: No module named rllab.misc.ext

So, the run_experiment_lite.py cannot locate the rllab lib. The code of experiment:

from rllab.algos.trpo import TRPO
from rllab.baselines.linear_feature_baseline import LinearFeatureBaseline
from rllab.envs.gym_env import GymEnv
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(GymEnv("Pendulum-v0"))

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

    baseline = LinearFeatureBaseline(env_spec=env.spec)

    algo = TRPO(
        env=env,
        policy=policy,
        baseline=baseline,
        batch_size=4000,
        max_path_length=env.horizon,
        n_itr=50,
        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,
)

When I run the same using terminal, it works fine.

dementrock commented 7 years ago

Hi,

You need to add your project folder to your PYTHONPATH inside pycharm.

joistick11 commented 7 years ago

Thank you, that works.

FranzLewis commented 7 years ago

@joistick11 I'm having the same problem. But did you copy some files from the git repo to the rllab-0.1.0-py3.5.egg directory in the conda environment? I copied all files from the first rllab directory, chose the interpreter in rllab3 env, added rllab-0.1.0-py3.5.egg to the PYTHONPATH in Pycharm (Add Content Root), and to the interpreter path as well. It now runs in terminal, but still throws the same ImportError in Pycharm. Any idea what went wrong here? Thanks!

joistick11 commented 7 years ago

Hi @FranzLewis Is the problem still actual for you?