eugenevinitsky / sequential_social_dilemma_games

Repo for reproduction of sequential social dilemmas
MIT License
380 stars 134 forks source link

Some errors when run "python -m pytest" #184

Open Aaricis opened 3 years ago

Aaricis commented 3 years ago


=========================================== test session starts ===========================================
platform linux -- Python 3.6.7, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/zkg/sequential_social_dilemma_games
collected 0 items / 2 errors                                                                              

================================================= ERRORS ==================================================
___________________________________ ERROR collecting tests/test_envs.py ___________________________________
ImportError while importing test module '/home/zkg/sequential_social_dilemma_games/tests/test_envs.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/root/anaconda3/envs/causal/lib/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_envs.py:8: in <module>
    from social_dilemmas.envs.agent import Agent
E   ModuleNotFoundError: No module named 'social_dilemmas'
_________________________________ ERROR collecting tests/test_rollout.py __________________________________
ImportError while importing test module '/home/zkg/sequential_social_dilemma_games/tests/test_rollout.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/root/anaconda3/envs/causal/lib/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_rollout.py:4: in <module>
    from rollout import Controller
E   ModuleNotFoundError: No module named 'rollout'
========================================= short test summary info =========================================
ERROR test_envs.py
ERROR test_rollout.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 2 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!```

I have ` social_dilemmas` folder and `rollout.py`, but I do not know why they cannot be recognized.
eugenevinitsky commented 3 years ago

I suspect you skipped the step of running python setup.py develop?. It looks like the folders aren't in your pythonpath essentially.

Aaricis commented 3 years ago

Thanks for your reply! I have fix this problem by import sys sys.append("..")

Aaricis commented 3 years ago

I have another error when running python -m pytest.


=========================================== test session starts ===========================================
platform linux -- Python 3.6.7, pytest-6.0.2, py-1.9.0, pluggy-0.13.1
rootdir: /home/zkg/sequential_social_dilemma_games
collected 1 item / 1 error                                                                                

================================================= ERRORS ==================================================
___________________________________ ERROR collecting tests/test_envs.py ___________________________________
ImportError while importing test module '/home/zkg/sequential_social_dilemma_games/tests/test_envs.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/root/anaconda3/envs/causal/lib/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_envs.py:16: in <module>
    from social_dilemmas.envs.cleanup import CleanupEnv
../social_dilemmas/envs/cleanup.py:5: in <module>
    from social_dilemmas.envs.map_env import MapEnv, ACTIONS
../social_dilemmas/envs/map_env.py:8: in <module>
    from ray.rllib.env import MultiAgentEnv
/root/anaconda3/envs/causal/lib/python3.6/site-packages/ray/rllib/__init__.py:11: in <module>
    from ray.rllib.evaluation.policy_graph import PolicyGraph
/root/anaconda3/envs/causal/lib/python3.6/site-packages/ray/rllib/evaluation/__init__.py:2: in <module>
    from ray.rllib.evaluation.policy_evaluator import PolicyEvaluator
/root/anaconda3/envs/causal/lib/python3.6/site-packages/ray/rllib/evaluation/policy_evaluator.py:20: in <module>
    from ray.rllib.evaluation.sampler import AsyncSampler, SyncSampler
/root/anaconda3/envs/causal/lib/python3.6/site-packages/ray/rllib/evaluation/sampler.py:15: in <module>
    from ray.rllib.evaluation.tf_policy_graph import TFPolicyGraph
/root/anaconda3/envs/causal/lib/python3.6/site-packages/ray/rllib/evaluation/tf_policy_graph.py:12: in <module>
    import ray.experimental.tf_utils
/root/anaconda3/envs/causal/lib/python3.6/site-packages/ray/experimental/tf_utils.py:4: in <module>
    from ray.rllib.utils import force_list
E   ImportError: cannot import name 'force_list'```
I cannot find `ray.rllib.utils`.
Aaricis commented 3 years ago

I fixed this error by pip install ray==0.6.1

venkatasivaramireddy commented 3 years ago

Thanks for your reply! I have fix this problem by import sys sys.append("..")

were you added this pace if code? i am facing the same error while importing packages

Aaricis commented 3 years ago

@venkatasivaramireddy You should not skip the step of running python setup.py develop. Before running rollout.py, we should run rollout.py firstly. Otherwise, you can added: import sys sys.append("..") at the beginning of rollout.py

venkatasivaramireddy commented 3 years ago

@venkatasivaramireddy You should not skip the step of running python setup.py develop. Before running rollout.py, we should run rollout.py firstly. Otherwise, you can added: import sys sys.append("..") at the beginning of rollout.py

My directory structure is like so features ├── init.py ├── classes ----└── class_features.py (i have class ClassFeatures) └── automation ---- └── test_features.py ( i need to import ClassFeatures into this file) ├── setup.py

In test_features.py, I am importing the class from class_features.py

from features.classes.class_features import ClassFeatures

but getting error,

from features.classes.class_features import ClassFeatures E ModuleNotFoundError: No module named 'features'

venkatasivaramireddy commented 3 years ago

RuntimeError: Working outside of the application context. E
E This typically means that you attempted to use functionality that needed E to interface with the current application object in some way. To solve E this, set up an application context with app.app_context(). See the E documentation for more information.