2

I am working on pdfkit library in python in order to create pdf file from html string. It works fine on my linux system but when i try to run it on windows server then it gives me error

pdfkit.from_string(html_string, output_dir)

and i get following error

import pdfkit
ImportError: No module named pdfkit

I installed wkhtmltopdf using .exe and pdfkit on windows using pip.

I also set path for wkhtmltopdf in environment variables.

Ancient
  • 3,007
  • 14
  • 55
  • 104

2 Answers2

1

Yaa, the main issue is, it may unable to find out the absolute path because of permission in windows, just try with administrator privileges as well give permission to directories to traversal.

for simple, you can do, copy the executable into your current directory :) :-)

or use the below lines in your code

path_wkthmltopdf = 'C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe'
config = pdfkit.configuration(wkhtmltopdf=path_wkthmltopdf)

pdfkit.from_string(html_string, output_file, configuration=config)

If you are using Anaconda cloud, you can install pdfkit using conda install -c conda-forge python-pdfkit

or conda install -c bioconda wkhtmltopdf

for more details you can go through below links

Docs

1: wkhtmltopdf

2: pdfkit

Yuvraj Takey
  • 87
  • 1
  • 11
1

Besides the previous answer, I had the same problem. I was using a Virtual Environment and I was installing Pdfkit to the Global Python config, but I had to install it inside the Virtual Environment.

(myvenv) C:\Users\user1\Documents\python-project> pip install pdfkit

or

(myvenv) C:\Users\user1\Documents\python-project> C:\Users\user1\Documents\python-project/myvenv/Scripts/python.exe -m pip install pdfkit
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77