Rename a *.db file

I’m trying to rename a *.db file with the os.rename() method.

This db file is not in use and it’s been created with sqlite.

Wat I want is to rename the file with the name that the user is giving, so I take the original directory and replace the name of the file with the new name given by the user in a GUI.

The problem is that it keeps returning the followin error: PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:’C:\Users\Aitor Cantero Crespo\Desktop\GUI_py\TRES.db’ -> ‘C:\Users\Aitor Cantero Crespo\Desktop\GUI_py\tes.db’

Hrere is the code:

”’

    def Modificar(NombreDelProyecto, NombreDelCliente, Descripcion, LetraRevision, FechaRevision, LetraFuerza, LetraMedida,                                                      LetraControl, LetraComunicacion, MargenEnOrigen, MargenEnDestino):         global Directorio          Info =  [NombreDelProyecto, NombreDelCliente, Descripcion, LetraRevision, FechaRevision,                              LetraFuerza, LetraMedida, LetraControl, LetraComunicacion, MargenEnOrigen, MargenEnDestino]         Conexion = connect('{}'.format(Directorio))                                                                                   with Conexion:                                                                                                                    Seleccion = Conexion.cursor()             Seleccion.execute("""SELECT NombreDelProyecto FROM InfProy""")             Nombre = Seleccion.fetchone()[0]              Seleccion.execute("""UPDATE InfProy SET NombreDelCliente='{}', Descripcion='{}', LetraRevision='{}', FechaRevision='{}',                              LetraFuerza='{}', LetraMedida='{}', LetraControl='{}', LetraComunicacion='{}', MargenEnOrigen='{}', MargenEnDestino='{}'""".format(                             Info[1], Info[2], Info[3], Info[4], Info[5], Info[6], Info[7], Info[8], Info[9], Info[10]))          if Nombre != Info[0]:             with Conexion:                                                                                                                       Seleccion = Conexion.cursor()                 Seleccion.execute("""UPDATE InfProy SET NombreDelProyecto='{}'""".format(Info[0]))              print(Directorio)             print(Nombre)             print(Info[0])             Directorio_N = Directorio.replace(str(Nombre), str(Info[0]))             print(Directorio_N)              Dir = path.normpath(Directorio_N)             Direct = path.normpath(Directorio)              rename(Direct, Dir) 

”’

I imagine this is due to the replace method, but I can’t understand why.