1 问题描述
在构建video_retalking项目过程中,使用命令安装依赖包时,运行依赖安装命令:
pip install -r requirements.txt
出现如下错误:
Building wheels for collected packages: face-alignment, dlib, ffmpy, future
Building wheel for face-alignment (setup.py) ... done
Created wheel for face-alignment: filename=face_alignment-1.3.4-py2.py3-none-any.whl size=27844 sha256=1099ac2f57890d2e4d94b972703f5a6ccf487376bad7cd60ee7a00c6f84736e9
Stored in directory: /root/.cache/pip/wheels/da/f8/cf/6ba533b36b381bf8f2ed87d82b95e5097c4f2ca9aab1acb8cf
Building wheel for dlib (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [7 lines of output]
running bdist_wheel
running build
running build_py
running build_ext
ERROR: CMake must be installed to build dlib
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for dlib
Running setup.py clean for dlib
Building wheel for ffmpy (setup.py) ... done
Created wheel for ffmpy: filename=ffmpy-0.3.1-py3-none-any.whl size=5579 sha256=61354e3c970907807c38694ea3da2a6183ac05bf4497ed85eac27222e15cf2a9
Stored in directory: /root/.cache/pip/wheels/0f/7f/ad/15fba8ee0656ffade5c40beace0c545743e91060c8af30efc9
Building wheel for future (setup.py) ... done
Created wheel for future: filename=future-0.18.3-py3-none-any.whl size=492024 sha256=f2792f6ac146614217f9fd5808a2025c68f1fc8c4785c5486eec94e4404ba96e
Stored in directory: /root/.cache/pip/wheels/07/14/8c/1cb73be9422f7e071f24ed77cb8e51eb87ac17e6fc06640715
Successfully built face-alignment ffmpy future
Failed to build dlib
ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects
2 问题分析
从异常信息可以看出,安装dlib是需要cmake,使用命令安装cmake
yum install cmake
安装完成后,再次运行出现如下错误:
Building wheels for collected packages: dlib
Building wheel for dlib (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [68 lines of output]
running bdist_wheel
running build
running build_py
running build_ext
Building extension for Python 3.8.18 | packaged by conda-forge | (default, Oct 10 2023, 15:44:36)
Invoking CMake setup: 'cmake /tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/build/lib.linux-x86_64-cpython-38 -DPYTHON_EXECUTABLE=/root/anaconda3/envs/retalking/bin/python3.8 -DCMAKE_BUILD_TYPE=Release'
-- The C compiler identification is unknown
CMake Error at /usr/share/cmake/Modules/CMakeDetermineCXXCompiler.cmake:55 (message):
Could not find compiler set in environment variable CXX:
g++.
Call Stack (most recent call first):
CMakeLists.txt:14 (project)
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file: /tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/build/temp.linux-x86_64-cpython-38/CMakeFiles/2.8.12.2/CMakeCXXCompiler.cmake
CMake Error: your C compiler: "CMAKE_C_COMPILER-NOTFOUND" was not found. Please set CMAKE_C_COMPILER to a valid compiler path or name.
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "/tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/build/temp.linux-x86_64-cpython-38/CMakeFiles/CMakeOutput.log".
See also "/tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/build/temp.linux-x86_64-cpython-38/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/setup.py", line 222, in <module>
setup(
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/__init__.py", line 103, in setup
return distutils.core.setup(**attrs)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 185, in setup
return run_commands(dist)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
dist.run_commands()
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 969, in run_commands
self.run_command(cmd)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/dist.py", line 989, in run_command
super().run_command(command)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
cmd_obj.run()
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/wheel/bdist_wheel.py", line 368, in run
self.run_command("build")
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
self.distribution.run_command(command)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/dist.py", line 989, in run_command
super().run_command(command)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
cmd_obj.run()
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/command/build.py", line 131, in run
self.run_command(cmd_name)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/cmd.py", line 318, in run_command
self.distribution.run_command(command)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/dist.py", line 989, in run_command
super().run_command(command)
File "/root/anaconda3/envs/retalking/lib/python3.8/site-packages/setuptools/_distutils/dist.py", line 988, in run_command
cmd_obj.run()
File "/tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/setup.py", line 134, in run
self.build_extension(ext)
File "/tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/setup.py", line 171, in build_extension
subprocess.check_call(cmake_setup, cwd=build_folder)
File "/root/anaconda3/envs/retalking/lib/python3.8/subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/tools/python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/tmp/pip-install-92e1e42i/dlib_b04bbb8202ab4a81b4fd32bf1517ed88/build/lib.linux-x86_64-cpython-38', '-DPYTHON_EXECUTABLE=/root/anaconda3/envs/retalking/bin/python3.8', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for dlib
Running setup.py clean for dlib
Failed to build dlib
ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects
查看cmake版本
(retalking) [root@localhost video-retalking]# cmake -version
cmake version 2.8.12.2
3 问题解决
3.1 更新cmake版本
- 移除旧版本
yum remove -y cmake
yum remove -y make
yum remove -y gcc
yum remove -y gcc-c++
- 下载新版本
wget -c https://cmake.org/files/v3.26/cmake-3.26.0-linux-x86_64.tar.gz
tar xvf cmake-3.26.0-linux-x86_64.tar.gz
mv cmake-3.26.0-linux-x86_64 cmake-3.26.0
mv cmake-3.26.0 /usr/local/share/
- 配置环境变量
echo "export PATH=\$PATH:/usr/local/share/cmake-3.26.0/bin" >> /etc/profile
source /etc/profile
3.2 更新gcc版本
- 安装devtoolset-10
yum install centos-release-scl -y
yum install devtoolset-10-gcc* -y
scl enable devtoolset-10 bash
- 配置环境变量
echo "source /opt/rh/devtoolset-10/enable" >> ~/.bash_profile
source /opt/rh/devtoolset-10/enable
- 查看更新后的gcc版本
(retalking) [root@localhost video-retalking]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-10/root/usr --mandir=/opt/rh/devtoolset-10/root/usr/share/man --infodir=/opt/rh/devtoolset-10/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-10.2.1-20210130/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 10.2.1 20210130 (Red Hat 10.2.1-11) (GCC)
再次运行包含dlib的依赖安装
pip install -r requirements.txt
不再报错,问题解决。
4 conda环境介绍
Conda是一个开源的包管理器和环境管理系统,用于安装、运行和更新包和其依赖项。它是由Anaconda, Inc.(以前称为Continuum Analytics)创建,用于支持Python程序开发,但它也可以用来管理来自其他语言的包。Conda使得包管理和环境隔离变得简单,对于处理多个项目中的依赖关系和版本控制尤其有用。
Conda是一个强大的工具,对于管理复杂的Python项目和环境至关重要。它简化了包管理和环境设置,使得Python开发更加容易和高效。通过使用Conda,开发者可以确保他们的项目在不同机器和操作系统上都能以相同的方式运行,大大提高了项目的可移植性和可复现性。
4.1 Conda的核心功能
-
包管理:Conda作为包管理器,可以安装、更新和移除Python包。它通过Conda仓库,如Anaconda Cloud或Conda Forge,来获取包。
-
环境管理:Conda允许用户创建隔离的环境,以便于不同项目可以拥有不同的库和/或Python版本。这在处理不兼容的依赖项或不同项目的需求时非常有用。
-
跨平台:Conda支持Linux、OS X和Windows,并允许创建跨平台的Python环境。
-
开源:Conda是开源的,允许用户查看源代码并对其进行改进。
4.2 使用Conda的优势
-
解决依赖性问题:Conda可以自动解决包之间的依赖关系,简化了安装过程。
-
环境隔离:创建独立的环境可以避免包之间的版本冲突,使得项目更稳定。
-
易于使用:Conda的命令行界面简单直观,易于学习和使用。
-
广泛的包支持:Conda支持Python的许多流行库和应用程序。
-
社区支持:作为一个流行的工具,Conda拥有一个活跃的社区,用户可以从中找到支持和资源。
4.3 Conda环境的创建和管理
-
创建新环境:使用
conda create
命令创建一个新环境,可以指定Python版本和所需的包。 -
激活环境:使用
conda activate
命令来激活环境。 -
安装包:在激活的环境中使用
conda install
命令来安装新的包。 -
环境列表:使用
conda env list
来查看所有可用的Conda环境。 -
移除环境:使用
conda env remove
命令来移除不再需要的环境。
4.4 应用场景
-
数据科学和机器学习:Conda非常适合于数据科学和机器学习项目,这些项目通常需要多个库和框架。
-
软件开发:软件开发者使用Conda来管理项目依赖,确保一致的开发环境。
-
教学和学术研究:教师和研究人员使用Conda来创建具有特定库和工具的环境,用于教学和研究。
4.5 常用命令
Conda 是一个开源的包管理器和环境管理器,广泛用于管理Python环境和包。以下是一些常用的 Conda 命令:
-
安装 Conda 包:
conda install [package-name]
: 安装指定的包。
-
创建和管理环境:
conda create --name [env-name]
: 创建一个新的环境。conda activate [env-name]
: 激活指定环境。conda deactivate
: 退出当前环境。conda env list
: 列出所有可用的环境。
-
管理包:
conda list
: 在当前环境中列出所有已安装的包。conda update [package-name]
: 更新指定的包。conda remove [package-name]
: 移除指定的包。
-
搜索包:
conda search [package-name]
: 搜索可用的包版本。
-
环境导出和导入:
conda env export > environment.yml
: 导出当前环境的配置到一个YAML文件。conda env create -f environment.yml
: 使用YAML文件创建一个新环境。
-
更新 Conda:
conda update conda
: 更新 Conda 到最新版本。
-
查看 Conda 信息:
conda info
: 显示关于 Conda 的信息。