Update PYTHONPATH and activate the environment in .bashrc for interactive sessions
RUN echo "export PYTHONPATH=/workspace/isuor_kpinst/kpinst/:${PYTHONPATH}" >> ~/.bashrc &&
echo "conda activate kpinst" >> ~/.bashrc
Verify that
init
.py exists
RUN ls -la /mde_toolbox/depth/
Adjust MMCV_MAX version in MDE-Toolbox to prevent version complaints
RUN sed -i "s/MMCV_MAX = '1.5.0'/MMCV_MAX = '1.8.0'/g" /mde_toolbox/depth/init.py
Install yapf to fix configuration printing bug
RUN pip install yapf==0.40.1
Replace memory hook in MMCV to fix GPU context issue
COPY patch/hooks_memory.py $CONDA_DIR/envs/kpinst/lib/python3.9/site-packages/mmcv/runner/hooks/memory.py and conda_env.yml: name: kpinst
channels:
git+
https://github.com/waspinator/pycococreator.git
and i get the followign error:
714.8 self.build_extensions()
714.8 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 485, in build_extensions
714.8 compiler_name, compiler_version = self._check_abi()
714.8 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 869, in _check_abi
714.8 _, version = get_compiler_abi_compatibility_and_version(compiler)
714.8 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 337, in get_compiler_abi_compatibility_and_version
714.8 if not check_compiler_ok_for_platform(compiler):
714.8 File "/opt/conda/envs/kpinst/lib/python3.9/site-packages/torch/utils/cpp_extension.py", line 291, in check_compiler_ok_for_platform
714.8 which = subprocess.check_output(['which', compiler], stderr=subprocess.STDOUT)
714.8 File "/opt/conda/envs/kpinst/lib/python3.9/subprocess.py", line 424, in check_output
714.8 return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
714.8 File "/opt/conda/envs/kpinst/lib/python3.9/subprocess.py", line 528, in run
714.8 raise CalledProcessError(retcode, process.args,
714.8 subprocess.CalledProcessError: Command '['which', 'g++']' returned non-zero exit status 1.
714.8 [end of output]
714.8
714.8 note: This error originates from a subprocess, and is likely not a problem with pip.
714.8 ERROR: Failed building wheel for inplace-abn
714.8 ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (pycocotools, inplace-abn)
714.8
714.8
714.8 failed
714.8
714.8 CondaEnvException: Pip failed
714.8
Dockerfile:41
40 | # Create Conda environment with mamba
41 | >>> RUN mamba env create -f /tmp/conda_env.yml -p /opt/conda/envs/kpinst &&
42 | >>> conda clean -afy &&
43 | >>> conda env list
44 |
ERROR: failed to solve: process "/bin/sh -c mamba env create -f /tmp/conda_env.yml -p /opt/conda/envs/kpinst && conda clean -afy && conda env list" did not complete successfully: exit code: 1
The error you’re encountering indicates that the g++ compiler is missing from your Docker environment. This compiler is essential for building certain Python packages that include C++ extensions, such as inplace-abn and pycocotools. To resolve this, you need to install the necessary build tools in your Docker image.
Here's how you can modify your Dockerfile to include the build-essential package, which provides g++ and other essential build tools:
Install Build Tools:
Modify the apt-get install command to include build-essential. This package includes g++, gcc, make, and other tools necessary for compiling software.
Some packages might require additional system libraries. It’s a good practice to review the dependencies of the Python packages you’re installing. For instance, pycocotools might require liblapack-dev or similar libraries. If you encounter further compilation issues, consider adding those specific libraries.
Full Revised Dockerfile:
Here's the revised Dockerfile with the necessary changes incorporated:
# Use base CUDA image
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
# Update NVIDIA GPG key
RUN rm -f /etc/apt/sources.list.d/cuda.list && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends wget && \
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb && \
dpkg -i cuda-keyring_1.0-1_all.deb
# Preseed tzdata and install dependencies
RUN truncate -s0 /tmp/preseed.cfg && \
echo "tzdata tzdata/Areas select Europe" >> /tmp/preseed.cfg && \
echo "tzdata tzdata/Zones/Europe select Berlin" >> /tmp/preseed.cfg && \
debconf-set-selections /tmp/preseed.cfg && \
rm -f /etc/timezone /etc/localtime && \
apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
tzdata \
sudo \
nano \
git \
ffmpeg \
libsm6 \
libxext6 \
build-essential && \ # Added build-essential
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Install Miniconda
ENV CONDA_DIR=/opt/conda
ENV PATH="$CONDA_DIR/bin:$PATH"
RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \
/bin/bash ~/miniconda.sh -b -p $CONDA_DIR && \
rm ~/miniconda.sh && \
$CONDA_DIR/bin/conda clean -afy && \
ln -s $CONDA_DIR/etc/profile.d/conda.sh /etc/profile.d/conda.sh && \
echo ". $CONDA_DIR/etc/profile.d/conda.sh" >> ~/.bashrc
# Update conda, set channel priority to strict, and install mamba
RUN conda update -n base -c defaults conda -y && \
conda config --set channel_priority flexible && \
conda install -n base -c conda-forge mamba -y
# Copy your conda environment file
COPY conda_env.yml /tmp/conda_env.yml
# Create Conda environment with mamba
RUN mamba env create -f /tmp/conda_env.yml -p /opt/conda/envs/kpinst && \
conda clean -afy && \
conda env list
# Set environment variables to use the new environment
ENV CONDA_DEFAULT_ENV=kpinst
ENV PATH="$CONDA_DIR/envs/kpinst/bin:$PATH"
# Initialize conda
RUN conda init bash
RUN conda run -p /opt/conda/envs/kpinst pip install openmim && \
conda run -p /opt/conda/envs/kpinst mim install mmcv-full==1.7.1
# Verify that mim is installed
RUN ls /opt/conda/envs/kpinst/bin/
# Activate the environment
ENV PATH /opt/conda/envs/kpinst/bin:$PATH
# Set PYTHONPATH to include the 'iSUOR_toolbox' directory
ENV PYTHONPATH="/workspace/isuor_kpinst/kpinst:${PYTHONPATH}"
# Install MMDetection from source
RUN git clone https://github.com/open-mmlab/mmdetection.git /mmdet && \
cd /mmdet && \
git checkout 94afcdc && \
pip install -v -e .
# Install Monocular-Depth-Estimation-Toolbox from source
RUN git clone https://github.com/zhyever/Monocular-Depth-Estimation-Toolbox.git /mde_toolbox && \
cd /mde_toolbox && \
git checkout 7c0c89c && \
pip install -v -e .
# Update PYTHONPATH and activate the environment in .bashrc for interactive sessions
RUN echo "export PYTHONPATH=/workspace/isuor_kpinst/kpinst/:${PYTHONPATH}" >> ~/.bashrc && \
echo "conda activate kpinst" >> ~/.bashrc
# Verify that init.py exists
RUN ls -la /mde_toolbox/depth/
# Adjust MMCV_MAX version in MDE-Toolbox to prevent version complaints
RUN sed -i "s/MMCV_MAX = '1.5.0'/MMCV_MAX = '1.8.0'/g" /mde_toolbox/depth/init.py
# Install yapf to fix configuration printing bug
RUN pip install yapf==0.40.1
# Replace memory hook in MMCV to fix GPU context issue
COPY patch/hooks_memory.py $CONDA_DIR/envs/kpinst/lib/python3.9/site-packages/mmcv/runner/hooks/memory.py
# Set default command
CMD ["bash"]
Additional Recommendations:
Consolidate RUN Commands: To optimize Docker layer caching and reduce the number of layers, consider combining related RUN commands using && \.
Use Specific Versions: Ensure that all packages, especially those installed via pip, specify versions to maintain consistency and reproducibility.
Cache Dependencies: Where possible, arrange the Dockerfile to take advantage of Docker's caching mechanism. For example, copy conda_env.yml before installing dependencies to reuse cached layers if the environment file hasn’t changed.
Verify Installations: After installing build tools and dependencies, you can add verification steps like RUN g++ --version to ensure they are correctly installed.
Rebuild the Docker Image:
After making these changes, rebuild your Docker image:
docker build -t your-image-name:tag .
Replace your-image-name:tag with your desired image name and tag.
Troubleshooting:
Check for Additional Missing Dependencies: If you encounter further errors related to missing libraries or tools, identify the missing components from the error messages and install them using apt-get.
Network Issues: Ensure that your Docker build has access to the internet to download packages and repositories.
By installing the build-essential package, you provide the necessary tools for compiling C++ extensions, which should resolve the g++ not found error and allow your Docker build to proceed successfully.