首先将carla自带的agents文件夹放到目标文件夹下

from agents.navigation.basic_agent import BasicAgent  # 引用一下
import glob
import sys
import os
import numpy as np
import pygame
from numpy import random
import math
from datetime import datetime
from agents.navigation.basic_agent import BasicAgent
from agents.navigation.behavior_agent import BehaviorAgent 
try:
    sys.path.append('D:/carla/CARLA_0.9.13/WindowsNoEditor/PythonAPI/carla/dist/carla-0.9.13-py3.7-win-amd64.egg')#改成你自己的环境
except IndexError:
    pass
import time
import carla
import csv
import argparse
import logging
import argparse

client = carla.Client('localhost', 2000)
client.set_timeout(10.0)  
world = client.get_world()
blueprint_library = world.get_blueprint_library()
model_3 = blueprint_library.filter('model3')[0]

actor_list = []
transform = world.get_map().get_spawn_points()[85] #spwan_points共265个点,选第一个点作为初始化小车的位置
#random.choice(self.world.get_map().get_spawn_points())
vehicle = world.spawn_actor(model_3 , transform)
spawn_points = world.get_map().get_spawn_points()
start_location = spawn_points[0]
destination = spawn_points[38]
#agent = BasicAgent(world.player)
agent = BasicAgent(vehicle)
global_route_trace = agent.set_destination(destination.location, start_location=start_location)

spectator = world.get_spectator()
transform = carla.Transform()
bv_transform = carla.Transform(transform.location + carla.Location(z=250,x=0), carla.Rotation(yaw=0, pitch=-90))
spectator.set_transform(bv_transform)

world.debug.draw_string(destination.location, str("destination"), life_time=100)
world.debug.draw_arrow(destination.location, destination.location + destination.get_forward_vector(), life_time=100)
clock = pygame.time.Clock()
while True:
            clock.tick()
            if agent.done():
                    print("The target has been reached, stopping the simulation")
                    break

            control = agent.run_step()
            control.manual_gear_shift = False
            vehicle.apply_control(control)
03-01 22:57