Tuesday, June 19, 2018

Python - PDF reports module - weasyprint - install

Follow the below steps to install weasyprint module for python on Ubuntu 18.04:

Step 1: Install the dependencies for weasyprint:

Install dependencies using the command:
sudo apt-get install build-essential python3-dev python3-pip python3-setuptools python3-wheel python3-cffi libcairo2 libpango-1.0-0 libpangocairo-1.0-0 libgdk-pixbuf2.0-0 libffi-dev shared-mime-info



Step 2: Install using pip :

$ sudo pip install weasyprint
[sudo] password for ubuntu: 
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting weasyprint
  Downloading https://files.pythonhosted.org/packages/7e/4c/cf2ec7abf7f84a2d1325d01dcac1d4bcb77f41117101fe564eb76952c65f/WeasyPrint-0.42.3.tar.gz (399kB)
    100% |████████████████████████████████| 409kB 1.4MB/s 
Collecting Pyphen>=0.8 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/dd/c4/74859f895e2361d92cfbb6208ea7afd06c2f1f05c491da71cbd7ce3887be/Pyphen-0.9.4-py2.py3-none-any.whl (1.9MB)
    100% |████████████████████████████████| 2.0MB 516kB/s 
Collecting cairocffi>=0.5 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/7a/2f/78179fea3413322fd20be407897738e5569e876e7cb6e4647a79b1ffd8dd/cairocffi-0.8.1.tar.gz (79kB)
    100% |████████████████████████████████| 81kB 2.9MB/s 
Collecting cffi>=0.6 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/14/dd/3e7a1e1280e7d767bd3fa15791759c91ec19058ebe31217fe66f3e9a8c49/cffi-1.11.5-cp27-cp27mu-manylinux1_x86_64.whl (407kB)
    100% |████████████████████████████████| 409kB 1.5MB/s 
Collecting cssselect2>=0.1 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/12/e2/91fcd4cd32545beec6e11628d64d3e20f11b5a95dd1ccf3216fd69f176b7/cssselect2-0.2.1-py2.py3-none-any.whl
Collecting html5lib>=0.999999999 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/a5/62/bbd2be0e7943ec8504b517e62bab011b4946e1258842bc159e5dfde15b96/html5lib-1.0.1-py2.py3-none-any.whl (117kB)
    100% |████████████████████████████████| 122kB 2.5MB/s 
Collecting pdfrw>=0.4 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/c0/84/af442c4458756bb0c0d2424102d1200616f3ff9b82c48aaa130e08549bf6/pdfrw-0.4-py2.py3-none-any.whl (69kB)
    100% |████████████████████████████████| 71kB 2.9MB/s 
Collecting tinycss2>=0.5 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/88/95/0ec73db7fc638ec000e662936ffe1a4e1eaa22f2861c8de18b1597c42584/tinycss2-0.6.1-py2.py3-none-any.whl (61kB)
    100% |████████████████████████████████| 71kB 3.6MB/s 
Collecting CairoSVG<2.0.0,>=1.0.20 (from weasyprint)
  Downloading https://files.pythonhosted.org/packages/d9/9b/c241990c86faa9e52a01f0570bba4247ba0f3d66eae2607e179cb9ae773a/CairoSVG-1.0.22.tar.gz
Collecting pycparser (from cffi>=0.6->weasyprint)
  Downloading https://files.pythonhosted.org/packages/8c/2d/aad7f16146f4197a11f8e91fb81df177adcc2073d36a17b1491fd09df6ed/pycparser-2.18.tar.gz (245kB)
    100% |████████████████████████████████| 256kB 2.1MB/s 
Requirement already satisfied: six>=1.9 in ./.local/lib/python2.7/site-packages (from html5lib>=0.999999999->weasyprint)
Collecting webencodings (from html5lib>=0.999999999->weasyprint)
  Downloading https://files.pythonhosted.org/packages/f4/24/2a3e3df732393fed8b3ebf2ec078f05546de641fe1b667ee316ec1dcf3b7/webencodings-0.5.1-py2.py3-none-any.whl
Installing collected packages: Pyphen, pycparser, cffi, cairocffi, webencodings, tinycss2, cssselect2, html5lib, pdfrw, CairoSVG, weasyprint
  Running setup.py install for pycparser ... done
  Running setup.py install for cairocffi ... done
  Running setup.py install for CairoSVG ... done
  Running setup.py install for weasyprint ... done
Successfully installed CairoSVG-1.0.22 Pyphen-0.9.4 cairocffi-0.8.1 cffi-1.11.5 cssselect2-0.2.1 html5lib-1.0.1 pdfrw-0.4 pycparser-2.18 tinycss2-0.6.1 weasyprint-0.42.3 webencodings-0.5.1
$

Check the installation:

$ python
Python 2.7.15rc1 (default, Apr 15 2018, 21:51:34) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import weasyprint
>>> exit()

Installation is successful.

No comments:

Post a Comment