carla: spawn_npc.py -n 80 not working

I am trying to run Carla 0.9.2 on Ubuntu 16.04 (Python 3.6.8 :: Anaconda, Inc.) following the documentation.

I downloaded the latest release from the GitHub page. I unzipped the CARLA_0.9.2.tar.gz file. My folder structure looks like.

|- (Folder) CarlaUE4
|- (Folder) Engine
|- (Folder) PythonAPI
|- automatic_control.py
|- CarlaUE4.sh
|- CHANGELOG
|- core
|- Dockerfile
|- dynamic_weather.py
|- LICENSE
|- manual_control.py
|- python_api.md
|- README
|- spawn_npc.py
|- tutorial.py
|- vehicle_gallery.py

Then I opened a terminal inside the folder to run ./CarlaUE4.shwhich works. I can fly through the city without any problems. Then I tried to run spawn_npc.py -n 80 (also tried ./spawn_npc.py -n 80 still inside the folder. But I get the following error:

dom@dom:~/carla-test$ ./spawn_npc.py -n 80
Traceback (most recent call last):
  File "./spawn_npc.py", line 23, in <module>
    import carla
ModuleNotFoundError: No module named 'carla'

I tried to follow https://github.com/carla-simulator/carla/issues/121 and ‘https://github.com/carla-simulator/imitation-learning/issues/2’ but I think these posts are related to an older version.

Then I went download the GitHub page https://github.com/carla-simulator/carla. I took this folder and copied it into the folder which does have the CarlaUE4.sh and the spawn_npc.py -n 80 (the release download) and renamed the folder from carla-master to carla and tried spawn_npc.py -n 80 but that gave me the output and error

destroying 0 actors

done.
Traceback (most recent call last):
  File "./spawn_npc.py", line 123, in <module>
    main()
  File "./spawn_npc.py", line 66, in main
    client = carla.Client(args.host, args.port)
AttributeError: module 'carla' has no attribute 'Client'

Then I found out that inside Depracated/PythonClient a folder named carla was there. I renamed the carla folder back to carla-master and copied the carla folder from the Depracated/PythonClient into the main folder from the release to subsequently run spawn_npc.py -n 80 but that gave me the same error as in the previous step.

Can someone tell me what exactly is going wrong? How should my folder structure look like and what do I need to download into the folder?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17

Most upvoted comments

For the error ModuleNotFoundError: No module named 'carla' many people having this issue. The solution is:

sudo easy_install <path to .egg file>

Also you can modify the python path

export PYTHONPATH=$PYTHONPATH:<path/to/carla/>/PythonAPI/<your_egg_file>

This is not properly documented

I am on release 0.9.1, but I think there may not be much difference. The carla module is included in the directory ‘PythonAPI’, in which you can see two .egg files. And in spawn_npc.py, take a look at the lines before ‘import carla’. There is a sys.path.append() call, and this is used to indicate the path of the egg files. I think the problem may be your sys.version_info is not consistent with that in the name of the egg files. Maybe you can hardcode the path in sys.path.append() and try again?

I had a similar issue in a conda enviroment. This was my solution:

  • locate .egg-files in Carla/PythonAPI/carla/dist/
  • change/install python version in conda enviroment which fits closest to an .egg-file (for me carla-0.9.6-py3.5-linux-x86_64.egg -> 3.5)
  • delete all other .egg-files (just for tidiness)
  • extract your .egg-file, e.g. carla-0.9.6-py3.5-linux-x86_64
  • create setup.py inside the folder (carla-0.9.6-py3.5-linux-x86_64) with the following content:
from distutils.core import setup
setup(name='carla',
      version='0.9.6', #doesn't matter I guess
      py_modules=['carla'],
      )
  • then you can install the carla-python-package via pip: pip install -e ~/Carla/PythonAPI/carla/dist/carla-0.9.6-py3.5-linux-x86_64

That solved it for me. I don’t even need the egg-path-appending-stuff, which is happening at the beginning of every python-script, just import carla.

At the moment we only compile the carla module for Python 2.7 and 3.5, either run it with one of those versions or compile it from source for the Python in your environment.