huawei-noah / SMARTS

Scalable Multi-Agent RL Training School for Autonomous Driving
MIT License
954 stars 190 forks source link

[Help Request] build scenario failed #2125

Closed beark007 closed 11 months ago

beark007 commented 11 months ago

High Level Description

1.install

pip install -e '.[camera_obs,train,test,envision]' --config-settings editable_mode=strict

2.build scenario

scl scenario build scenarios/sumo/loop/

3.problem

Building: scenarios/sumo/loop/
Error processing line 1 of /home/XXX/SMARTS/.venv/lib/python3.8/site-packages/zope.interface-6.1-py3.8-nspkg.pth:

Fatal Python error: init_import_size: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/home/XXX/SMARTS/build/__editable__.smarts-1.4.0-py3-none-any/smarts/__init__.py", line 22, in <module>
    from importlib.metadata import version
  File "/usr/lib/python3.8/importlib/metadata.py", line 3, in <module>
    import re
  File "/usr/lib/python3.8/re.py", line 124, in <module>
    import enum
  File "/usr/lib/python3.8/enum.py", line 2, in <module>
    from types import MappingProxyType, DynamicClassAttribute
ImportError: cannot import name 'MappingProxyType' from partially initialized module 'types' (most likely due to a circular import) (/home/XXX/SMARTS/smarts/sstudio/types/__init__.py)

During handling of the above exception, another exception occurred:

Version

master commit:6ffa83fca9dda7

Operating System

Ubuntu 20.04

Problems

build scenario failed.

No response

Gamenot commented 11 months ago

@beark007, it appears like you may have a python environment issue. The smarts.sstudio.types is somehow overriding the standard python types module.

Would you happen to somehow have added <SMARTS_REPO>/smarts/sstudio to your PYTHONPATH or PATH environment variables?

If you try the python interpreter, does <SMARTS_REPO>/smarts/sstudio somehow show up in sys.path before /usr/lib/python3.8?

python
>>> import sys
>>> sys.path
>>> [os.path.abspath(p) for p in sys.path]
# example output
['/home/dev/repo/SMARTS', '/home/dev/anaconda3/lib/python39.zip', '/home/dev/anaconda3/lib/python3.9', '/home/dev/anaconda3/lib/python3.9/lib-dynload', '/home/dev/repo/SMARTS/.venv/lib/python3.9/site-packages', '/home/dev/repo/SMARTS/__editable__.smarts-1.4.0.finder.__path_hook__']
beark007 commented 11 months ago

@beark007, it appears like you may have a python environment issue. The smarts.sstudio.types is somehow overriding the standard python types module.

Would you happen to somehow have added <SMARTS_REPO>/smarts/sstudio to your PYTHONPATH or PATH environment variables?

If you try the python interpreter, does <SMARTS_REPO>/smarts/sstudio somehow show up in sys.path before /usr/lib/python3.8?

python
>>> import sys
>>> sys.path
>>> [os.path.abspath(p) for p in sys.path]
# example output
['/home/dev/repo/SMARTS', '/home/dev/anaconda3/lib/python39.zip', '/home/dev/anaconda3/lib/python3.9', '/home/dev/anaconda3/lib/python3.9/lib-dynload', '/home/dev/repo/SMARTS/.venv/lib/python3.9/site-packages', '/home/dev/repo/SMARTS/__editable__.smarts-1.4.0.finder.__path_hook__']

print info: Python 3.8.10 (default, Nov 22 2023, 10:22:35) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information.

import sys sys.path ['', '/home/XXX/SMARTS', '/home/XXX/nuplan-devkit', '/home/XXX/carla_0910/PythonAPI/carla/dist/carla-0.9.10-py3.7-linux-x86_64.egg', '/home/XXX/carla_0910/PythonAPI/carla/agents', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/XXX/.local/lib/python3.8/site-packages', '/home/XXX/d4rl', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']

beark007 commented 11 months ago

After installing the environment under a new python, it still fails to build the scenario.

Gamenot commented 11 months ago

I have never seen this error before and have not yet been able to reproduce the error for that commit. The system path is not suggesting anything. I am going to attempt to emulate the error and see if I can force the correct import order.

beark007 commented 11 months ago

I have never seen this error before and have not yet been able to reproduce the error for that commit. The system path is not suggesting anything. I am going to attempt to emulate the error and see if I can force the correct import order.

Many thanks!

Gamenot commented 11 months ago

It appears like it may be related to Pycharm debug:

https://stackoverflow.com/a/68985644

What I might be able to do here is forcefully reload the module if types is smarts.sstudio.types when resolving through smarts.__init__.py. This may not be possible because types is a core module...

I think I am going to have to deprecate and rename smarts/sstudio/types.py.

Gamenot commented 11 months ago

@beark007 I have merged in a fix that should resolve the issue.