BestSithInEU
BestSithInEU

Reputation: 81

OSError: [WinError 126] The specified module could not be found?

Firstly sorry, my grammer might be bad. And if I missed any solutions in here, you can give me url, but I did not find any proper one for this case.

I'm taking a course about deep learning, and they provide us to this code. However there was an error which I encounter only. This is the main.py;

from __future__ import print_function
import os
import torch
import torch.multiprocessing as mp
from envs import create_atari_env
from model import ActorCritic
from train import train
from testt import test
import my_optim

# Gathering all the parameters (that we can modify to explore)
class Params():
    def __init__(self):
        self.lr = 0.0001
        self.gamma = 0.99
        self.tau = 1.
        self.seed = 1
        self.num_processes = 16
        self.num_steps = 20
        self.max_episode_length = 10000
        self.env_name = 'Breakout-v0'

# Main run
os.environ['OMP_NUM_THREADS'] = '1'
params = Params()
torch.manual_seed(params.seed)
env = create_atari_env(params.env_name)
shared_model = ActorCritic(env.observation_space.shape[0], env.action_space)
shared_model.share_memory()
optimizer = my_optim.SharedAdam(shared_model.parameters(), lr=params.lr)
optimizer.share_memory()
processes = []
p = mp.Process(target=test, args=(params.num_processes, params, shared_model))
p.start()
processes.append(p)
for rank in range(0, params.num_processes):
    p = mp.Process(target=train, args=(rank, params, shared_model, optimizer))
    p.start()
    processes.append(p)
for p in processes:
    p.join()

Is it caused by "from envs import create_atari_env". Because after install create_atari_env, after I install it. And also I do not use any paths in scripts.

Error;

****\lib\ctypes_init_.py line 426 in LoadLibrary self._handle = _dlopen(self._name, mode) OSError: [WinError 126] The specified module could not be found

Upvotes: 2

Views: 1777

Answers (2)

Andrew L
Andrew L

Reputation: 1

It looks like the owner of the repository removed this module and hasn't replaced it with an alternative. Looks like a simple function that might have become obsolete after the forking of gym by OpenAI to gymnasium (Farama Foundation). gymnasium has a slightly different API but can be wrapped to mimic gym. The most obvious difference is that env.step() returns a 4-tuple in gym and a 5-tuple in gymnasium.
Recommend first installing gymnasium with the Atari environment mod (see their website). The standard atari preprocessing wrapper (as recommended in the 2013/14 Deep Mind paper, like automatically downsizing the observation space from 210x160xRGB to 84x84 greyscale. And others.

Your solution will look roughly like this:

import gymnasium as gym
from gymnasium.wrappers import atari_preprocessing
def create_atari_env(env_name):
   env = gym.make(params.env_name)
   env = atari_preprocessing(
        env: gym.Env = env,
        # assuming defaults: 
        noop_max: int = 30,
        frame_skip: int = 4,
        screen_size: int = 84,
        terminal_on_life_loss: bool = False,
        grayscale_obs: bool = True,
        grayscale_newaxis: bool = False,
        scale_obs: bool = False,)
    return env

Good luck.

Upvotes: 0

AzyCrw4282
AzyCrw4282

Reputation: 7744

This error is often caused in relation to path, for example, which requires the correct use of double-slashes, forward-slashes or raw-strings but since you mentioned this wasn't your case I believe the root cause of this error is by

import torch

There are known cases of PyTorch breaking DLL loading on specific Python and PyTorch versions (applies to PyTorch 1.5.0 on Python 3.7 specifically). Once you run import torch, any further DLL loads will fail. So if you're using PyTorch and loading your own DLLs you'll have to rearrange your code to import all DLLs first and then import torch.

Upvotes: 1

Related Questions