Install third party python libraries (e.g. PDFMiner)

I would like to use third party python libraries in a server whitelist script.
The thing is: by running pip pip install pdfminer I am unable to use this library in a py file:

Failed to get method for command with No module named 'pdfminer'

Is it even possible to import third party libraries using installation manager that fixes all prerequisites?

You’ll have to activate the virtual environment first:

# change to bench directory
cd /home/frappe/frappe-bench
# activate virtual environment
source env/bin/activate
# install python package in virtual environment
pip install pdfminer

Haven’t had a chance to handle virtual environments “hands on” by myself by now.

And after the installation we don’t need to activate environment again?
How about in production?

  • Frappe/ERPNext automatically activates the 'env' virtual environment on startup. You don’t need to activate manually yourself.

  • It works the same in production.

  • If you don’t want to manually 'pip install ...' in every environment? Then you would add your Python package requirements to your App’s “requirements.txt” file. (packages named in “requirements.txt” are automatically installed when you install the App)

As an example, here’s a link to the ERPNext App’s 'requirements.txt'.

thank you @brian_pond

If you’re using a relatively recent version of bench you can also do bench pip install PDFMiner