How to fix error with freetype while installing all packages from a requirements.txt file?
Asked Answered
C

6

131

I ran the following command to install dependencies for a Python project?

# pip install requirements.txt 
Collecting requirements.txt
  Could not find a version that satisfies the requirement requirements.txt (from versions: )
No matching distribution found for requirements.txt

I searched on Google and found this post: python pip trouble installing from requirements.txt but I don't quite understand what the solution was in that post.

Here is my requirements.txt file:

# cat requirements.txt 
ordereddict==1.1
argparse==1.2.1
python-dateutil==2.2
matplotlib==1.3.1
nose==1.3.0
numpy==1.8.0
pymongo==3.3.0
psutil>=2.0

I then tried to do pip3 install -r requirements.txt and here is the output:

# pip3 install -r requirements.txt 
Requirement already satisfied: ordereddict==1.1 in /usr/local/lib/python3.5/dist-packages (from -r requirements.txt (line 1))
Collecting argparse==1.2.1 (from -r requirements.txt (line 2))
  Using cached argparse-1.2.1.tar.gz
Collecting python-dateutil==2.2 (from -r requirements.txt (line 3))
  Using cached python-dateutil-2.2.tar.gz
Collecting matplotlib==1.3.1 (from -r requirements.txt (line 4))
  Using cached matplotlib-1.3.1.tar.gz
    Complete output from command python setup.py egg_info:
    ============================================================================
    Edit setup.cfg to change the build options
    
    BUILDING MATPLOTLIB
                matplotlib: yes [1.3.1]
                    python: yes [3.5.2 (default, Nov 17 2016, 17:05:23)  [GCC
                            5.4.0 20160609]]
                  platform: yes [linux]
    
    REQUIRED DEPENDENCIES AND EXTENSIONS
                     numpy: yes [version 1.11.3]
                  dateutil: yes [using dateutil version 2.6.0]
                   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 [using pyparsing version 2.1.10]
                     pycxx: yes [Official versions of PyCXX are not compatible
                            with Python 3.x.  Using local copy]
                    libagg: yes [pkg-config information for 'libagg' could not
                            be found. Using local copy.]
                  freetype: no  [The C/C++ header for freetype2 (ft2build.h)
                            could not be found.  You may need to install the
                            development package.]
                       png: yes [pkg-config information for 'libpng' could not
                            be found. Using unknown version.]
    
    OPTIONAL SUBPACKAGES
               sample_data: yes [installing]
                  toolkits: yes [installing]
                     tests: yes [using nose version 1.3.7]
    
    OPTIONAL BACKEND EXTENSIONS
                    macosx: no  [Mac OS-X only]
                    qt4agg: no  [PyQt4 not found]
                   gtk3agg: no  [gtk3agg backend does not work on Python 3]
                 gtk3cairo: no  [Requires cairo to be installed.]
                    gtkagg: no  [Requires pygtk]
                     tkagg: no  [TKAgg requires Tkinter.]
                     wxagg: no  [requires wxPython]
                       gtk: no  [Requires pygtk]
                       agg: yes [installing]
                     cairo: no  [cairo not found]
                 windowing: no  [Microsoft Windows only]
    
    OPTIONAL LATEX DEPENDENCIES
                    dvipng: no
               ghostscript: no
                     latex: no
                   pdftops: no
    
    ============================================================================
                            * The following required packages can not be built:
                            * freetype
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-don4ne_2/matplotlib/

I have already installed libfreetype6-dev but the pip command still reports missing this dependency.

# apt-get install libfreetype6-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libfreetype6-dev is already the newest version (2.6.1-0.1ubuntu2).
0 upgraded, 0 newly installed, 0 to remove and 4 not upgraded.

Is there an easy way to install all required dependencies for this python project?

Carma answered 4/1, 2017 at 6:33 Comment(5)
pip install -r requirements.txtArista
I have updated the output to include the output with -r flag but still not able to install.Carma
in output you see that it needs freetype. It is not python module but system package. You have to install it using ie. apt-get on Ubuntu/MintIncumbency
Why -r because it has nothing to do with file ??Bifrost
Does this answer your question? How can I install packages using pip according to the requirements.txt file from a local directory?Polled
F
106

If you are using Linux OS:

  1. Remove matplotlib==1.3.1 from requirements.txt
  2. Try to install matplotlib with sudo apt-get install python-matplotlib
  3. Install all packages again from requirements.txt
    • For Python 2: run pip install -r requirements.txt
    • For Python 3: run pip3 install -r requirements.txt
  4. pip freeze > requirements.txt

If you are using Windows OS:

  1. python -m pip install -U pip setuptools
  2. python -m pip install matplotlib
Forme answered 4/1, 2017 at 7:25 Comment(3)
Hi Nilesh, welcome to Stack Overflow. In the future, please include explanation of what the commands you give in your answer do, don't just tell people to run commands.Lifeline
Thanks @Nilesh. Did you mean putting 4. before 3.?Agnomen
No @Anupam, As in step1, we removed "matplotlib" from requirements.txt, in step4 we are updating requirements.txt with a newly installed package for future use. step3 is for installing other requirements from the file.Forme
T
57

pip install -r requirements.txt for python 2.x

pip3 install -r requirements.txt for python 3.x (in case multiple versions are installed)

Toole answered 4/1, 2017 at 6:38 Comment(3)
I tried both but still failed. I have posted the output from this command.Carma
I think there is a required dependency 'freetype' missing for installing MATPLOTLIB. Try installing the dependency and running pip install -r requirements.txt again.Asafoetida
pip won't handle system level dependencies. You'll have to apt-get install libfreetype6-dev before continuing. (It even says so right in your output. Try skimming over it for such errors next time, usually build outputs are very detailed)Teerell
J
9
python -m pip install -r requirements.txt

Referece: How to install packages using pip according to the requirements.txt file from a local directory?

Jerol answered 28/1, 2019 at 15:45 Comment(0)
G
5

Python 3:

pip3 install -r requirements.txt

Python 2:

pip install -r requirements.txt

To get all the dependencies for the virtual environment or for the whole system:

pip freeze

To push all the dependencies to the requirements.txt (Linux):

pip freeze > requirements.txt
Gotcher answered 3/2, 2020 at 12:38 Comment(0)
T
4

(Taken from my comment on another answer)

pip won't handle system-level dependencies. You'll have to apt-get install libfreetype6-dev before continuing. (It even says so right in your output. Try skimming over it for such errors next time, usually build outputs are very detailed.)

Teerell answered 4/1, 2017 at 7:0 Comment(2)
I have already installed libfreetype6-dev. But pip still reports this error.Carma
Did you see this bug? github.com/matplotlib/matplotlib/issues/3029Teerell
C
0

If you want to install all the dependencies inside the requirements file, like npm install on a Node.js project

in python you run the following command:

pip3 install -r  ./requirements.txt

you can use pip or pip3 both work

Coze answered 13/6, 2021 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.