AttributeError: module 'carla' has no attribute 'Client'

1.5k Views Asked by At

I've been trying to play around with the Carla self-driving car environment but I run into "AttributeError: module 'carla' has no attribute 'Client'" when I try running the code from this tutorial: https://pythonprogramming.net/control-camera-sensor-self-driving-autonomous-cars-carla-python/. I have made a few changes to the code, including changing the .egg file to it's exact file path within my computer.

this is my code...

'''
import glob
import os
import sys

try:
    sys.path.append(glob.glob('C:\Downloads\CARLA_0.9.9.4\WindowsNoEditor\PythonAPI\carla\dist\carla-0.9.9-py3.7-win-amd64.egg'))
except IndexError:
    pass
import carla 

actor_list = []

#try: 
client = carla.Client("localhost", 2000)
client.set_timeout(2.0)
world = client.get_world()
blueprint_library = world.get_blueprint_library()    
    

#finally:
for actor in actor_list:
    actor.destroy()
    print("All cleaned up!")

''' Just for refrence I'm running on a windows 10 that has anaconda3 and python 3.7.7 and I'm using carla version 0.9.9.4. Thanks in advance!

1

There are 1 best solutions below

0
On

Just correct your folder path. Would need to rename path in file structure like this...

Remove all "." from the path.

path = glob.glob('C:\Downloads\CARLA_0994\WindowsNoEditor\PythonAPI\carla\dist\carla-099-py37-win-amd64.egg')[0]
sys.path.append(path)

Full Example:

import glob
import os
import sys

try:
    path = glob.glob('C:\Downloads\CARLA_0994\WindowsNoEditor\PythonAPI\carla\dist\carla-099-py37-win-amd64.egg')[0]
    sys.path.append(path)
except IndexError:
    pass

import carla

actor_list = []

try:
    client = carla.Client("localhost", 2000)
    client.set_timeout(5.0)
    world = client.get_world()
    blueprint_library = world.get_blueprint_library()
    print("Map = ", world.get_map())
finally:
    for actor in actor_list:
        actor.destroy()
        print("All cleaned up!")