在 PyCharm (macOS) 中安装 dlib 时出现问题
Posted
技术标签:
【中文标题】在 PyCharm (macOS) 中安装 dlib 时出现问题【英文标题】:Problem in installing dlib in PyCharm (macOS) 【发布时间】:2019-12-20 21:00:27 【问题描述】:我是 Python 编程语言的初学者。我正在研究一个用 Python 进行面部地标检测的项目。为此,我正在尝试使用 dlib。
我正在使用 Python 编程语言的 PyCharm IDE,但是当我尝试在我的 PyCharm 包上安装 dlib 库时,我收到以下错误。
谁能帮我解决这个问题。
编辑: 这是我得到的完整错误。
**收集 dlib 使用缓存的https://files.pythonhosted.org/packages/05/57/e8a8caa3c89a27f80bc78da39c423e2553f482a3705adc619176a3a24b36/dlib-19.17.0.tar.gz 安装收集的包:dlib 为 dlib 运行 setup.py install:已启动 为 dlib 运行 setup.py install:完成状态为“错误” 命令 /Users/mayanktiwari/human_detect/untitled/bin/python -u -c "import setuptools, tokenize;file='/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm 的完整输出-packaging/dlib/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, file, 'exec'))" install --record /private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/ pip-record-hq673j64/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mayanktiwari/human_detect/untitled/include/site/python3.7/dlib: 运行安装 运行构建 运行 build_py 未找到包初始化文件“dlib/init.py”(或不是常规文件) 警告:build_py:字节编译已禁用,正在跳过。
running build_ext
Building extension for Python 3.7.2 (default, Dec 27 2018, 07:35:52)
Invoking CMake setup: 'cmake /private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/tools/python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/build/lib.macosx-10.13-x86_64-3.7 -DPYTHON_EXECUTABLE=/Users/mayanktiwari/human_detect/untitled/bin/python -DCMAKE_BUILD_TYPE=Release'
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- broken
CMake Error at /usr/local/Cellar/cmake/3.13.2/share/cmake/Modules/CMakeTestCCompiler.cmake:52 (message):
The C compiler
"/usr/bin/cc"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/build/temp.macosx-10.13-x86_64-3.7/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_dc7d9/fast"
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
CMake will not be able to correctly generate this project.
-- Configuring incomplete, errors occurred!
See also "/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/build/temp.macosx-10.13-x86_64-3.7/CMakeFiles/CMakeOutput.log".
See also "/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/build/temp.macosx-10.13-x86_64-3.7/CMakeFiles/CMakeError.log".
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/setup.py", line 261, in <module>
'Topic :: Software Development',
File "/Users/mayanktiwari/human_detect/untitled/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg/setuptools/__init__.py", line 145, in setup
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 966, in run_commands
self.run_command(cmd)
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/Users/mayanktiwari/human_detect/untitled/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg/setuptools/command/install.py", line 61, in run
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/install.py", line 545, in run
self.run_command('build')
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/command/build.py", line 135, in run
self.run_command(cmd_name)
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py", line 985, in run_command
cmd_obj.run()
File "/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/setup.py", line 135, in run
self.build_extension(ext)
File "/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/setup.py", line 172, in build_extension
subprocess.check_call(cmake_setup, cwd=build_folder)
File "/usr/local/Cellar/python/3.7.2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 347, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/tools/python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/build/lib.macosx-10.13-x86_64-3.7', '-DPYTHON_EXECUTABLE=/Users/mayanktiwari/human_detect/untitled/bin/python', '-DCMAKE_BUILD_TYPE=Release']' returned non-zero exit status 1.
----------------------------------------
命令 "/Users/mayanktiwari/human_detect/untitled/bin/python -u -c "import setuptools, tokenize;file='/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/ pycharm-packaging/dlib/setup.py';f=getattr(tokenize, 'open', open)(file);code=f.read().replace('\r\n' , '\n');f.close();exec(compile(code, file, 'exec'))" install --record /private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T /pip-record-hq673j64/install-record.txt --single-version-externally-managed --compile --install-headers /Users/mayanktiwari/human_detect/untitled/include/site/python3.7/dlib" 失败/private/var/folders/ww/21lp_4013plfs5g1ym7wh39h0000gn/T/pycharm-packaging/dlib/**中的错误代码1
【问题讨论】:
你使用的是虚拟环境还是默认的python解释器? 无法打开“错误”,请粘贴到这里。 您是否按照错误消息中的建议进行操作?如果有,结果如何?另外,请复制完整的错误消息并将其包含在您的帖子中。 @GamingWithAltitude,我正在使用默认的 python 解释器。 @Aaron_ab,我已经发布了完整的错误信息。 【参考方案1】:conda install cmake
然后
pip install dlib
它对我有用。
【讨论】:
【参考方案2】:我已经找到了这个问题的答案。我们只需要按照简单的步骤在 Python 中安装 dlib。
-
安装 Python
安装 Pycharm
安装 Anaconda
打开anaconda,新建一个环境,然后依次执行以下命令。
conda 更新 conda
conda 更新 anaconda
conda 安装 cmake
conda install -c conda-forge dlib
现在您可以通过这种方式在 anaconda 的虚拟环境中安装 dlib。接下来,您可以在 Pycharm 编辑器中访问这个虚拟环境。
【讨论】:
以上是关于在 PyCharm (macOS) 中安装 dlib 时出现问题的主要内容,如果未能解决你的问题,请参考以下文章