Python 运行`pip install`的Ubuntu给出错误“无法构建以下必需的包:* freetype”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20533426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 20:41:05  来源:igfitidea点击:

Ubuntu running `pip install` gives error 'The following required packages can not be built: * freetype'

pythonubuntupython-2.7matplotlibpip

提问by Athena Wisdom

When performing pip install -r requirements.txt, I get the following error during the stage where it is installing matplotlib:

执行时pip install -r requirements.txt,我在安装阶段收到以下错误matplotlib

REQUIRED DEPENDENCIES AND EXTENSIONS
                 numpy: yes [not found. pip may install it below.]
              dateutil: yes [dateutil was not found. It is required for date
                        axis support. pip/easy_install may attempt to
                        install it after matplotlib.]
               tornado: yes [tornado was not found. It is required for the
                        WebAgg backend. pip/easy_install may attempt to
                        install it after matplotlib.]
             pyparsing: yes [pyparsing was not found. It is required for
                        mathtext support. pip/easy_install may attempt to
                        install it after matplotlib.]
                 pycxx: yes [Couldn't import.  Using local copy.]
                libagg: yes [pkg-config information for 'libagg' could not
                        be found. Using local copy.]
              freetype: no  [pkg-config information for 'freetype2' could
                        not be found.]

...

...

The following required packages can not be built:

                    * freetype

Shouldn't pip install -r requirements.txtalso install freetype? How should freetype be installed in Ubuntu 12.04 so it works with matplotlib?

不应该pip install -r requirements.txt也安装freetype吗?应该如何在 Ubuntu 12.04 中安装 freetype 才能使用它matplotlib

采纳答案by James Mills

No. pipwill not install system-level dependencies. This means pipwill not install RPM(s) (Redhat based systems) or DEB(s) (Debian based systems).

pip将不会安装系统级的依赖性。这意味着pip不会安装 RPM(s)(基于 Redhat 的系统)或 DEB(s)(基于 Debian 的系统)。

To install system dependencies you will need to use one of the following methods depending on your system.

要安装系统依赖项,您需要根据您的系统使用以下方法之一。

Ubuntu/Debian:

Ubuntu/Debian:

apt-get install libfreetype6-dev

To search for packages on Ubuntu/Debian based systems:

在基于 Ubuntu/Debian 的系统上搜索软件包:

apt-cache search <string>

e.g:

例如:

apt-cache search freetype | grep dev


Redhat/CentOS/Fedora:

红帽/CentOS/Fedora:

yum -y install freetype-devel

To search for packages on Redhat/CentOS/Fedora based systems:

在基于 Redhat/CentOS/Fedora 的系统上搜索软件包:

yum search <string>

e.g:

例如:

yum search freetype | grep devel


Mac OS X:(via Homebrew)

Mac OS X:(通过Homebrew)

brew install freetype

To search for packages on Mac OS X based systems:

在基于 Mac OS X 的系统上搜索软件包:

brew search <string>

e.g:

例如:

brew search freetype

回答by Sudipta Basak

I had to install libxft-dev in order to enable matplotlib on ubuntu server 14.04.

我必须安装 libxft-dev 才能在 ubuntu 服务器 14.04 上启用 matplotlib。

sudo apt-get install libfreetype6-dev libxft-dev

And then I could use

然后我可以使用

sudo easy_install matplotlib

回答by notconfusing

A workaround is to do sudo apt-get install pkg-configwhich I found in this github issue.

一种解决方法是sudo apt-get install pkg-config在这个 github 问题中找到的方法。

回答by PaulMest

None of the existing answers worked for me to upgrade matplotlib on Ubuntu. This is what ultimately work for me:

现有的答案都不适合我在 Ubuntu 上升级 matplotlib。这就是最终对我有用的东西:

$ sudo apt-get install build-dep python-matplotlib
$ pip install matplotlib --upgrade

回答by AndreL

I'm using Mint an none of this answers worked for me, I needed to:

我正在使用 Mint,但这些答案都不适合我,我需要:

sudo apt-get install build-essential g++

回答by MiaeKim

This command will download all dependencies.

此命令将下载所有依赖项。

For python 2.x

对于 python 2.x

sudo apt-get install python-matplotlib

For python 3.x

对于python 3.x

sudo apt-get install python3-matplotlib

After installing, you can try

安装后,您可以尝试

(sudo) pip install matplotlib

回答by Caleb Kiage

On Ubuntu, it worked after I installed blt-devpackage.

在 Ubuntu 上,它在我安装blt-dev软件包后工作。

$sudo apt-get install blt-dev
$pip install matplotlib

回答by klimenkov

I had the same issue with Python 3.6 on Windows, but then I switched to Python 3.5.2 and everything works fine.

我在 Windows 上使用 Python 3.6 时遇到了同样的问题,但后来我切换到了 Python 3.5.2,一切正常。

回答by StackEdd

This command sudo apt-get install libfreetype6-devfailed for me on ubuntu 16.04,
The following packages have unmet dependencies: libfreetype6-dev : Depends: libfreetype6 (= 2.6.1-0.1ubuntu2) but 2.6.1-0.1ubuntu2.3 is to be installed

这个命令sudo apt-get install libfreetype6-dev在 ubuntu 16.04 上对我来说失败了,
The following packages have unmet dependencies: libfreetype6-dev : Depends: libfreetype6 (= 2.6.1-0.1ubuntu2) but 2.6.1-0.1ubuntu2.3 is to be installed

So I downloaded installed freetype from the source, credit to this guide

所以我从源代码下载了安装的 freetype ,归功于本指南

$ tar -xvjf freetype-x.y.tar.bz2  # extract the downloaded version file
$ cd freetype-x.y/ 
$ ./configure
$ make
$ sudo make install 

switched to virtualenv and pip install matplotliband everything is working.

切换到 virtualenv 并且pip install matplotlib一切正常。