Ancient
Ancient

Reputation: 3057

ImportError: No module named pdfkit

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.

Upvotes: 2

Views: 18778

Answers (2)

Manuel Chang
Manuel Chang

Reputation: 11

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

Upvotes: 1

Yuvraj Takey
Yuvraj Takey

Reputation: 87

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

Upvotes: 1

Related Questions