Python import os not working

I am doing some stuff with gym retro and the code is not working

import os
SAVE_PATH = os.path.join(OPT_DIR, 'trial_{}_best_model'.format(trial.number))

and the error comes out like this

File "c:\Users\beg32\Desktop\project\", line 1, in <module>
    SAVE_PATH = os.path.join(OPT_DIR, 'trial_{}_best_model'.format(trial.number))
NameError: name 'os' is not defined

I tried importing os.path or importing the module and name the module every time
and it still doesn’t work.

Did you actually save the changes? The error message says SAVE_PATH = ... is the first line.

import os
SAVE_PATH = os.path.join(OPT_DIR, 'trial_{}_best_model'.format(trial.number))

That is not the code you are running. The error message says that SAVE_PATH ... is on line 1, not line 2.

OPT_DIR is not defined either, or trial, so even after the os error is fixed the rest of the line won’t work.

Go to the script that has OPT_DIR and trial defined. Put

import os

at the very beginning of the file, before your code. Save the change (Ctrl-S). Now try running the code. What happens?

Ah it seems to have worked out after i ran it on the script with the OPT_DIR and trial defined but it seems like another part of the code is not working as well

from stable_baselines3.common.monitor import Monitor
LOG_DIR = './logs/'
def optimize_agent(trial):

        model_params =optimize_ppo(trial)
        env = Monitor(env, LOG_DIR)

and the error pop up as such

Exception has occurred: FileNotFoundError
[Errno 2] No such file or directory: './logs/.monitor.csv'

I thought monitor is suppose to make the file for me? Am I missing something?