How to fix 'UserWarning: Distutils was imported before Setuptools'?

Question:

When I cloned some packages including python tools, an error occured:

Errors     << unique_id:cmake /home/scpark/cps_ws/logs/unique_id/build.cmake.001.log                                              
CMake Warning (dev) at CMakeLists.txt:2 (project):
  Policy CMP0048 is not set: project() command manages VERSION variables.
  Run "cmake --help-policy CMP0048" for policy details.  Use the cmake_policy
  command to set the policy and suppress this warning.

  The following variable(s) would be set to empty:

    CMAKE_PROJECT_VERSION
    CMAKE_PROJECT_VERSION_MAJOR
    CMAKE_PROJECT_VERSION_MINOR
    CMAKE_PROJECT_VERSION_PATCH
This warning is for project developers.  Use -Wno-dev to suppress it.

/opt/ros/noetic/lib/python3/dist-packages/_distutils_hack/__init__.py:18: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the `distutils` module in `sys.modules`. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.
  warnings.warn(
/opt/ros/noetic/lib/python3/dist-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

ERROR: invalid command 'unique_id'
CMake Error at /opt/ros/noetic/share/catkin/cmake/safe_execute_process.cmake:11 (message):

  execute_process(/home/scpark/cps_ws/build/unique_id/catkin_generated/env_cached.sh
  "/usr/bin/python3"
  "/opt/ros/noetic/share/catkin/cmake/interrogate_setup_dot_py.py"
  "unique_id" "/home/scpark/cps_ws/src/unique_identifier/unique_id/setup.py"
  "/home/scpark/cps_ws/build/unique_id/catkin_generated/setup_py_interrogation.cmake")
  returned error code 1
Call Stack (most recent call first):
  /opt/ros/noetic/share/catkin/cmake/catkin_python_setup.cmake:46 (safe_execute_process)
  CMakeLists.txt:8 (catkin_python_setup)


cd /home/scpark/cps_ws/build/unique_id; catkin build --get-env unique_id | catkin env -si  /usr/bin/cmake /home/scpark/cps_ws/src/unique_identifier/unique_id --no-warn-unused-cli -DCATKIN_DEVEL_PREFIX=/home/scpark/cps_ws/devel/.private/unique_id -DCMAKE_INSTALL_PREFIX=/home/scpark/cps_ws/install; cd -

..................................................................................................................................
Failed     << unique_id:cmake                  [ Exited with code 1 ]                                                             
Failed    <<< unique_id                        [ 0.5 seconds ]                                                                    
Abandoned <<< unique_identifier                [ Unrelated job failed ]                                                           
[build] Summary: 1 of 3 packages succeeded.                                                                                       
[build]   Ignored:   None.                                                                                                        
[build]   Warnings:  None.                                                                                                        
[build]   Abandoned: 1 packages were abandoned.                                                                                   
[build]   Failed:    1 packages failed.                                                                                           
[build] Runtime: 0.7 seconds total.

Anyone who knows how to fix it?

/opt/ros/noetic/lib/python3/dist-packages/_distutils_hack/init.py:18: UserWarning: Distutils was imported before Setuptools, but importing Setuptools also replaces the distutils module in sys.modules. This may lead to undesirable behaviors or errors. To avoid these issues, avoid using distutils directly, ensure that setuptools is installed in the traditional way (e.g. not an editable install), and/or make sure that setuptools is always imported before distutils.

Asked By: bigbigpark

||

Answers:

I had the same problem after upgrading my system to 20.04 and ROS Noetic. As suggested in this answer, upgrading setuptools solves the problem.

But I would actually do a user install like this pip3 install --user --upgrade pip setuptools as it avoids conflicts with the system package.

Answered By: Johannes Hackbarth

With your command, I still get the warning: UserWarning: Setuptools is replacing distutils." while building Hue-4.7.1

Answered By: exChao
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.