<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code-It &#187; weasyprint</title>
	<atom:link href="http://lois.di-qual.net/blog/tag/weasyprint/feed/" rel="self" type="application/rss+xml" />
	<link>http://lois.di-qual.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 30 Oct 2012 19:19:29 +0000</lastBuildDate>
	<language>fr-FR</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Python &#8211; Install WeasyPrint on a linux (Webfaction) server</title>
		<link>http://lois.di-qual.net/blog/python-install-weasyprint-on-a-dedicated-webfaction-server/</link>
		<comments>http://lois.di-qual.net/blog/python-install-weasyprint-on-a-dedicated-webfaction-server/#comments</comments>
		<pubDate>Thu, 23 Aug 2012 16:28:39 +0000</pubDate>
		<dc:creator>Loïs Di Qual</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[weasyprint]]></category>
		<category><![CDATA[webfaction]]></category>

		<guid isPermaLink="false">http://lois.di-qual.net/blog/?p=95</guid>
		<description><![CDATA[WeasyPrint is a great python library to generate PDFs from HTML. It beats hands down xhtml2pdf, by interpreting CSS and HTML the right way. However, it has a lot of dependencies and it just can&#8217;t fit in a simple python virtual environment. It took me a whole day to install on Webfaction, so I think [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://weasyprint.org/">WeasyPrint</a> is a great python library to generate PDFs from HTML. It beats hands down <a href="http://www.xhtml2pdf.com/">xhtml2pdf</a>, by interpreting CSS and HTML the right way.</p>
<p>However, it has a lot of dependencies and it just can&#8217;t fit in a simple python virtual environment. It took me a whole day to install on Webfaction, so I think it would be helpful to show how to do it properly.</p>
<p>These steps has been tested on a Webfaction CentOS 6 server (python2.7), and they should be the same for others Linux systems. If your system is not exactly the same, you might have to install other dependencies manually. <a href="http://www.linuxfromscratch.org/">Linux From Scratch</a> is your helpful friend in this kind of situation.</p>
<p><span id="more-95"></span></p>
<p>Log to ssh, and let the magic begin.</p>
<h2>Dependencies</h2>
<p>WeasyPrint relies on the following dependencies:</p>
<ul>
<li>Pango >= 1.29.3 (with introspection)</li>
<li>pycairo</li>
<li>GdkPixbuf >= 2.25 (with introspection, required for images other than PNG)</li>
<li>PyGObject 3.x</li>
</ul>
<p>Of course, these dependencies have their own dependencies. It becomes really hard to install all of them by hand, so I made a small <a href="https://raw.github.com/gist/3438324/weasyprint_webfaction.sh">shell script</a> to do it automatically. It will install all of them in your home directory (with <code class="codecolorer text default"><span class="text">--prefix=$HOME</span></code>).</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ curl -fsSkL https://raw.github.com/gist/3438324/weasyprint_webfaction.sh | sh</div></td></tr></tbody></table></div>
<p>Then, add the following lines to your <code class="codecolorer text default"><span class="text">~/.bashrc</span></code>:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">export LD_LIBRARY_PATH=$HOME/lib<br />
export PYTHONPATH=&quot;$HOME/lib/python2.7/site-packages/:$PYTHONPATH&quot;</div></td></tr></tbody></table></div>
<p>And source it:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ source ~/.bashrc</div></td></tr></tbody></table></div>
<h2>Virtual environment</h2>
<p>As we will install global python libraries, we need a virtual environment that is aware of system packages. If you didn&#8217;t create one yet:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ cd /path/to/project<br />
$ virtualenv --system-site-packages ./venv</div></td></tr></tbody></table></div>
<p>If your virtual env is already created:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ cd /path/to/project<br />
$ mv ./venv/lib/python2.7/no-global-site-packages.txt ./venv/lib/python2.7/_no-global-site-packages.txt</div></td></tr></tbody></table></div>
<h2>WeasyPrint</h2>
<p>Here we are. Install WeasyPrint using the following lines:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ source ./venv/bin/activate<br />
$ pip install weasyprint</div></td></tr></tbody></table></div>
<p>Finally, test it:</p>
<div class="codecolorer-container text twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ weasyprint http://weasyprint.org ./weasyprint-website.pdf</div></td></tr></tbody></table></div>
<p>If there is an import error, please check that you correctly sourced your <code class="codecolorer text default"><span class="text">~/.bashrc</span></code>.</p>
<p>Thanks to <a href="http://community.webfaction.com/users/1146/iliasr/">Ilias Romanos</a> from the Webfaction Q/A forum for the pyCairo part ! Don&#8217;t hesitate to improve the install script on <a href="https://gist.github.com/3438324">github:gist</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lois.di-qual.net/blog/python-install-weasyprint-on-a-dedicated-webfaction-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
