trackmania-rl/tmrl

TmrlData Folder disappeared

Closed this issue · 3 comments

I tried to cleanly install TMRL again, and deleted the folder and ran the pip command as per the instructions. The pip command worked fine, but there was no TmrlData folder created.
How do I get it back?

Weird, this is the second time someone encounters this issue.

I suppose we can create a script to solve this when this happens, but I would like to understand why this happens, as I could not reproduce the issue on my end.

Can you provide more information please?

  • Is it version 0.6.1 specifically that fails to recreate TmrlData?
  • Did 0.6.1 install properly before or do you come from an older version and could you never install 0.6.1 on your machine?
  • What is your OS?
  • What is your python version?
  • Are you using anaconda or another type of python installation?

In the meantime, you can basically manually execute the first part of setup.py, it should recreate the TmrlData folder:

import os
import platform
import sys
from pathlib import Path
from shutil import copy2
from zipfile import ZipFile
import urllib.request
import urllib.error
import socket

if sys.version_info < (3, 7):
    sys.exit('Sorry, Python < 3.7 is not supported.')


RESOURCES_URL = "https://github.com/trackmania-rl/tmrl/releases/download/v0.6.0/resources.zip"


def url_retrieve(url: str, outfile: Path, overwrite: bool = False):
    """
    Adapted from https://www.scivision.dev/python-switch-urlretrieve-requests-timeout/
    """
    outfile = Path(outfile).expanduser().resolve()
    if outfile.is_dir():
        raise ValueError("Please specify full filepath, including filename")
    if overwrite or not outfile.is_file():
        outfile.parent.mkdir(parents=True, exist_ok=True)
        try:
            urllib.request.urlretrieve(url, str(outfile))
        except (socket.gaierror, urllib.error.URLError) as err:
            raise ConnectionError(f"could not download {url} due to {err}")


# destination folder:
HOME_FOLDER = Path.home()
TMRL_FOLDER = HOME_FOLDER / "TmrlData"

# download relevant items IF THE tmrl FOLDER DOESN'T EXIST:
if not TMRL_FOLDER.exists():
    CHECKPOINTS_FOLDER = TMRL_FOLDER / "checkpoints"
    DATASET_FOLDER = TMRL_FOLDER / "dataset"
    REWARD_FOLDER = TMRL_FOLDER / "reward"
    WEIGHTS_FOLDER = TMRL_FOLDER / "weights"
    CONFIG_FOLDER = TMRL_FOLDER / "config"
    CHECKPOINTS_FOLDER.mkdir(parents=True, exist_ok=True)
    DATASET_FOLDER.mkdir(parents=True, exist_ok=True)
    REWARD_FOLDER.mkdir(parents=True, exist_ok=True)
    WEIGHTS_FOLDER.mkdir(parents=True, exist_ok=True)
    CONFIG_FOLDER.mkdir(parents=True, exist_ok=True)

    # download resources:
    RESOURCES_TARGET = TMRL_FOLDER / "resources.zip"
    url_retrieve(RESOURCES_URL, RESOURCES_TARGET)

    # unzip downloaded resources:
    with ZipFile(RESOURCES_TARGET, 'r') as zip_ref:
        zip_ref.extractall(TMRL_FOLDER)

    # delete zip file:
    RESOURCES_TARGET.unlink()

    # copy relevant files:
    RESOURCES_FOLDER = TMRL_FOLDER / "resources"
    copy2(RESOURCES_FOLDER / "config.json", CONFIG_FOLDER)
    copy2(RESOURCES_FOLDER / "reward.pkl", REWARD_FOLDER)
    copy2(RESOURCES_FOLDER / "SAC_4_LIDAR_pretrained.tmod", WEIGHTS_FOLDER)
    copy2(RESOURCES_FOLDER / "SAC_4_imgs_pretrained.tmod", WEIGHTS_FOLDER)

    # on Windows, look for OpenPlanet:
    if platform.system() == "Windows":
        OPENPLANET_FOLDER = HOME_FOLDER / "OpenplanetNext"

        if OPENPLANET_FOLDER.exists():
            # copy the OpenPlanet script:
            try:
                # remove old script if found
                OP_SCRIPTS_FOLDER = OPENPLANET_FOLDER / 'Scripts'
                if OP_SCRIPTS_FOLDER.exists():
                    to_remove = [OP_SCRIPTS_FOLDER / 'Plugin_GrabData_0_1.as',
                                 OP_SCRIPTS_FOLDER / 'Plugin_GrabData_0_1.as.sig',
                                 OP_SCRIPTS_FOLDER / 'Plugin_GrabData_0_2.as',
                                 OP_SCRIPTS_FOLDER / 'Plugin_GrabData_0_2.as.sig']
                    for old_file in to_remove:
                        if old_file.exists():
                            old_file.unlink()
                # copy new plugin
                OP_PLUGINS_FOLDER = OPENPLANET_FOLDER / 'Plugins'
                OP_PLUGINS_FOLDER.mkdir(parents=True, exist_ok=True)
                TM20_PLUGIN_1 = RESOURCES_FOLDER / 'Plugins' / 'TMRL_GrabData.op'
                TM20_PLUGIN_2 = RESOURCES_FOLDER / 'Plugins' / 'TMRL_SaveGhost.op'
                copy2(TM20_PLUGIN_1, OP_PLUGINS_FOLDER)
                copy2(TM20_PLUGIN_2, OP_PLUGINS_FOLDER)
            except Exception as e:
                print(
                    f"An exception was caught when trying to copy the OpenPlanet plugin automatically. \
                    Please copy the plugin manually for TrackMania 2020 support. The caught exception was: {str(e)}.")
        else:
            # warn the user that OpenPlanet couldn't be found:
            print(f"The OpenPlanet folder was not found at {OPENPLANET_FOLDER}. \
            Please copy the OpenPlanet script and signature manually for TrackMania 2020 support.")

Thanks! That worked.

  1. Yes
  2. It worked the first time (my issues were my fault and came later, thats why I reinstalled)
  3. Windows 11 Home
  4. 3.11
  5. No VM, just running in my home folder.

Thanks for the info.

Hmm maybe this has to do with some weirdness in how Windows manages pip's permissions with the system installation then, personally I always use anaconda.