12

I'm attempting to install PyQuery via pip but I'm getting an error I do not understand. The command I used was:

sudo pip install pyquery

I get the output below:

Requirement already satisfied (use --upgrade to upgrade): pyquery in /usr/local/lib/python2.7/dist-packages
Downloading/unpacking lxml>=2.1 (from pyquery)
Running setup.py egg_info for package lxml
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
  warnings.warn(msg)
Building lxml version 3.3.0.
Building without Cython.
ERROR: /bin/sh: 1: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt

Downloading/unpacking cssselect (from pyquery)
Running setup.py egg_info for package cssselect

no previously-included directories found matching 'docs/_build'
Installing collected packages: lxml, cssselect
Running setup.py install for lxml
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
  warnings.warn(msg)
Building lxml version 3.3.0.
Building without Cython.
ERROR: /bin/sh: 1: xslt-config: not found

** make sure the development packages of libxml2 and libxslt are installed **

Using build configuration of libxslt
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/home/imageek/scripts/facebook/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w
src/lxml/lxml.etree.c:16:20: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
Complete output from command /usr/bin/python -c "import setuptools;__file__='/home/imageek/scripts/facebook/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-dyUZWZ-record/install-record.txt:
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'

warnings.warn(msg)

Building lxml version 3.3.0.

Building without Cython.

ERROR: /bin/sh: 1: xslt-config: not found



** make sure the development packages of libxml2 and libxslt are installed **



Using build configuration of libxslt

running install

running build

running build_py

copying src/lxml/includes/lxml-version.h -> build/lib.linux-i686-2.7/lxml/includes

running build_ext

building 'lxml.etree' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/home/imageek/scripts/facebook/build/lxml/src/lxml/includes -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.7/src/lxml/lxml.etree.o -w

src/lxml/lxml.etree.c:16:20: fatal error: Python.h: No such file or directory

compilation terminated.

error: command 'gcc' failed with exit status 1

----------------------------------------
Command /usr/bin/python -c "import setuptools;__file__='/home/imageek/scripts/facebook/build/lxml/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --single-version-externally-managed --record /tmp/pip-dyUZWZ-record/install-record.txt failed with error code 1
Storing complete log in /home/imageek/.pip/pip.log

I have a feeling it's something to do with dependencies, but should 'pip' not automatically install dependencies?

Torra
  • 1,022
  • 3
  • 12
  • 23

2 Answers2

21

You have missing dependencies. Try running:

sudo apt-get install libxml2-dev libxslt1-dev python-dev

Pancho Jay
  • 480
  • 6
  • 10
0

Put following lines in a file called pyquery.sh

#ADD SWAP FOR lxml COMPILATION
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

#ACTIVATE ENV
#Comment following line if you don't use virtualenv
#source /home/py3/bin/activate

#INSTALL ALL DEP
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt-get -y update
apt-get -y install gcc
apt-get -y install g++
apt-get -y install build-essential
apt-get -y install python-dev
apt-get -y install libxml2-dev
apt-get -y install libxslt-dev
apt-get -y install libxslt1-dev
apt-get -y install zlib1g-dev
apt-get -y install python3-setuptools
apt-get -y install python3-lxml
apt-get -y install python3-lxml-dbg
apt-get -y install python3-dev

pip install lxml
pip install pyquery

#REMOVE SWAP
swapoff /swapfile
rm -rf /swapfile

After this run this file by:

source pyquery.sh
Adrian B
  • 1,059
  • 1
  • 13
  • 25
  • In my case, I was only trying to install `lxml` and ran into the same error. I removed the repository's version of `python-lxml`, `2.3.2-1ubuntu0.2`, and tried again. It doesn't make a difference, the `gcc` problem remains. (I suspected it would, I just had to confirm.) – icedwater Sep 03 '14 at 15:09
  • Now I have added the complete script – Adrian B Apr 12 '17 at 12:47