-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete installation script for Ubuntu 20.04 #242
Comments
You can reuse the |
Good to know about |
Oh, I think that's a pending issue: Abseil has dropped support for C++11, so I think we need to do the same here. |
We need to add a Dockerfile to this project. |
Would love an official dockerfile but you can pretty easily adapt this installation script to work with docker:
|
Updated instal script for Ubuntu 22 (it assumes to be inside a Python 3 https://gist.github.com/danijar/ca6ab917188d2e081a8253b3ca5c36d3 Usage in Dockerfile: RUN wget -O - https://gist.github.com/danijar/ca6ab917188d2e081a8253b3ca5c36d3/raw/install-dmlab.sh | sh Unfortunately, I think DMLab is not compatible with Numpy 2, so you'll also need |
(What does it take to make DMLab compatible with Numpy 2?) |
My understanding is that Numpy's C API has changed a bit, so if that's used inside DMLab it would have to be update to the new API. I'm guessing Numpy is only used for the interface to Python so it shouldn't be that much work? |
I encountered issues with deprecated Python 2 (PY2) support and If others face similar problems, it may be worth raising this as a standalone issue. #!/bin/bash
set -e # Exit on any error
echo "=== DeepMind Lab Initial Setup Script ==="
# Step 1: Install dependencies
echo "Installing dependencies..."
sudo apt update
sudo apt install -y build-essential libosmesa6-dev libgl1-mesa-dev \
libxi-dev libxcursor-dev libxinerama-dev libxrandr-dev libopenal-dev \
mesa-utils python3-dev python3-venv git wget unzip zlib1g-dev g++ pip
# Step 2: Install Bazelisk
echo "Installing Bazelisk..."
wget https://github.com/bazelbuild/bazelisk/releases/download/v1.17.0/bazelisk-linux-amd64 -O bazelisk
chmod +x bazelisk
sudo mv bazelisk /usr/local/bin/bazel
# Verify Bazel installation
bazel --version
# Step 3: Clone DeepMind Lab
echo "Cloning DeepMind Lab repository..."
git clone https://github.com/google-deepmind/lab.git
cd lab
# Step 4: Configure bazelrc
echo "Configuring .bazelrc..."
echo "build --enable_workspace" > .bazelrc
echo "build --python_version=PY3" >> .bazelrc
echo "build --action_env=PYTHON_BIN_PATH=$(which python3)" >> .bazelrc
# Step 5: Modify BUILD file
echo "Modifying BUILD file..."
sed -i '/\[py_binary(/,/\]]/c\
py_binary(\
name = "python_game_py3",\
srcs = ["examples/game_main.py"],\
data = ["//:deepmind_lab.so"],\
main = "examples/game_main.py",\
python_version = "PY3",\
srcs_version = "PY3",\
tags = ["manual"],\
deps = ["@six_archive//:six"],\
)' BUILD
# Step 6: Replace content of python_system.bzl
echo "Replacing python_system.bzl content..."
cat > python_system.bzl << 'EOL'
# Copyright 2021 DeepMind Technologies Limited.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# ============================================================================
"""Generates a local repository that points at the system's Python installation."""
_BUILD_FILE = '''# Description:
# Build rule for Python
exports_files(["defs.bzl"])
cc_library(
name = "python_headers",
hdrs = glob(["python3/**/*.h", "numpy3/**/*.h"]),
includes = ["python3", "numpy3"],
visibility = ["//visibility:public"],
)
'''
_GET_PYTHON_INCLUDE_DIR = """
import sys
from distutils.sysconfig import get_python_inc
from numpy import get_include
sys.stdout.write("{}\\n{}\\n".format(get_python_inc(), get_include()))
""".strip()
def _python_repo_impl(repository_ctx):
"""Creates external/<reponame>/BUILD, a python3 symlink, and other files."""
repository_ctx.file("BUILD", _BUILD_FILE)
result = repository_ctx.execute(["python3", "-c", _GET_PYTHON_INCLUDE_DIR])
if result.return_code:
fail("Failed to run local Python3 interpreter: %s" % result.stderr)
pypath, nppath = result.stdout.splitlines()
repository_ctx.symlink(pypath, "python3")
repository_ctx.symlink(nppath, "numpy3")
python_repo = repository_rule(
implementation = _python_repo_impl,
configure = True,
local = True,
attrs = {"py_version": attr.string(default = "PY3", values = ["PY3"])},
)
EOL
echo "Initial setup complete! Now run build_venv.sh to create virtual environment and build the project." #!/bin/bash
set -e # Exit on any error
# Configuration variables
CREATE_TEST=${CREATE_TEST:-false}
VENVPATH=${VENVPATH:-"$HOME/project/venv"}
# Check if lab directory exists
if [ ! -d "lab" ]; then
echo "Error: 'lab' directory not found. Please run setup_lab.sh first."
exit 1
fi
cd lab
echo "=== DeepMind Lab Virtual Environment Setup ==="
echo "Using virtual environment path: $VENVPATH"
# Create and activate virtual environment
echo "Setting up Python virtual environment at $VENVPATH..."
python3 -m venv "$VENVPATH"
source "$VENVPATH/bin/activate"
# Install required packages
pip install --upgrade pip setuptools wheel
pip install numpy dm_env opencv-python
# Export Python path
export PYTHON_BIN_PATH=$(which python3)
# Build the project
echo "Building the project..."
bazel clean --expunge
bazel build -c opt //python/pip_package:build_pip_package
# Generate wheel file
echo "Generating wheel file..."
./bazel-bin/python/pip_package/build_pip_package /tmp/dmlab_pkg
# Install package
echo "Installing package..."
pip install --force-reinstall /tmp/dmlab_pkg/deepmind_lab-*.whl
# Move files to correct locations
echo "Moving files to correct locations..."
SITE_PACKAGES="$VENVPATH/lib/python3.10/site-packages/deepmind_lab"
mv "$SITE_PACKAGES/_main/"* "$SITE_PACKAGES/"
# Create test file if requested
if [ "$CREATE_TEST" = true ]; then
echo "Creating test file..."
cat > test_dmlab.py << 'EOL'
import deepmind_lab
import numpy as np
import cv2
# Create environment
env = deepmind_lab.Lab(
level='seekavoid_arena_01',
observations=['RGB_INTERLEAVED'],
config={
'width': '640',
'height': '480',
'fps': '60'
},
renderer='hardware'
)
# Reset the environment
env.reset()
try:
while True:
if not env.is_running():
print("Episode ended, resetting...")
env.reset()
continue
# Generate a random action
action = np.zeros(7, dtype=np.intc)
action[0] = np.random.randint(-10, 11) # Look left/right
action[1] = np.random.randint(-10, 11) # Look up/down
action[2] = np.random.randint(-1, 2) # Strafe
action[3] = np.random.randint(-1, 2) # Forward/backward
action[4] = np.random.randint(0, 2) # Fire
action[5] = np.random.randint(0, 2) # Jump
action[6] = np.random.randint(0, 2) # Crouch
# Step the environment
reward = env.step(action, num_steps=4)
if env.is_running():
obs = env.observations()
frame = obs['RGB_INTERLEAVED']
cv2.imshow('DeepMind Lab', cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))
if cv2.waitKey(1) & 0xFF == ord('q'):
break
except Exception as e:
print(f"An error occurred: {e}")
finally:
cv2.destroyAllWindows()
env.close()
print("Environment closed successfully")
EOL
fi
echo "Installation complete!"
if [ "$CREATE_TEST" = true ]; then
echo "To test, activate the environment and run test_dmlab.py:"
echo "source $VENVPATH/bin/activate"
echo "python3 test_dmlab.py"
fi |
Not an issue, just thought I'd share a full installation script for the DMLab Python package because it took a while to put all the pieces together and might be helpful for others. Tested on Ubuntu 20.04, might also work on newer versions:
The text was updated successfully, but these errors were encountered: