Ubuntu 18.04 LTS编译doom_py出现编译错误求助
Hey there, let's work through this build error you're hitting with doom_py. Looking at your error logs, the root cause is clear:
/tmp/pip-build-fqKs1A/doom-py/doom_py/src/lib/ViZDoomGame.cpp:743:22: error: ‘cerr’ is not a member of ‘std’
This happens because the ViZDoomGame.cpp source file uses std::cerr (for warning messages) but doesn't include the required <iostream> header file that defines it. Here's how to fix this step by step:
Step 1: Verify Dependencies are Installed
First, make sure you've got all the required system libraries installed (as hinted in the error message):
sudo apt-get install -y python-numpy cmake zlib1g-dev libjpeg-dev libboost-all-dev gcc libsdl2-dev wget unzip
Step 2: Fix the Missing Header in Source Code
You'll need to edit the problematic C++ file to add the missing include:
- Navigate to the directory containing
ViZDoomGame.cpp(from your log, this is/tmp/pip-build-fqKs1A/doom-py/doom_py/src/lib/— if you're building from a local clone, use that path instead) - Open
ViZDoomGame.cppin a text editor (like nano or vim) - At the very top of the file, add this line to the list of
#includestatements:#include <iostream> - Save the file and close the editor
- Re-run the build command:
python setup.py build
Step 3: Fallback Options if the Fix Above Doesn't Work
If you still run into issues, it's likely due to version compatibility between your old doom-py version (0.0.14) and Ubuntu 18.04's default GCC (version 7.x, which uses newer C++ standards). Try these alternatives:
Option A: Use a Pre-compiled Wheel (if available)
Try installing doom-py directly with pip, skipping the local build:
pip install doom-py==0.0.14 --no-cache-dir
Option B: Downgrade GCC for Compatibility
Ubuntu 18.04 allows installing older GCC versions. Install GCC 5 and set it as the default for the build:
sudo apt-get install gcc-5 g++-5 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 10 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 10
Then re-run the build command. After building, you can switch back to the default GCC if needed:
sudo update-alternatives --remove gcc /usr/bin/gcc-5 sudo update-alternatives --remove g++ /usr/bin/g++-5
Option C: Upgrade to a Newer doom-py Version
If your OpenAI Gym version (0.9.5) supports it, try upgrading doom-py to a more recent release (note: you may need to adjust other dependencies):
pip install --upgrade doom-py
内容的提问来源于stack exchange,提问作者Abbas

