# Issue compiling Python Plugin, importing PIP modules, UBUNTU 20.04

**URL:** https://discourse.orthanc-server.org/t/issue-compiling-python-plugin-importing-pip-modules-ubuntu-20-04/2082
**Category:** Google Groups archive
**Created:** [August 30, 2020, 7:08pm UTC](https://discourse.orthanc-server.org/t/issue-compiling-python-plugin-importing-pip-modules-ubuntu-20-04/2082 "2020-08-30T19:08:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Stephen\_Douglas\_Scot](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@Stephen\_Douglas\_Scot](https://discourse.orthanc-server.org/u/Stephen_Douglas_Scot)
#### Post date: [August 30, 2020, 7:08pm UTC](https://discourse.orthanc-server.org/t/issue-compiling-python-plugin-importing-pip-modules-ubuntu-20-04/2082/1 "2020-08-30T19:08:56Z")

</div>

I’m moving Orthanc to another system. UBUNTU 20.04. Compiled orthanc and the orthanc-python (mainline) from source. When I start up Orthanc I get the following errors. My plugin, combined.py, imports both pydicom and pdfkit. When I comment those out and restart Orthanc it starts up without error.

`  
Orthanc version: mainline (20200830T165517)

W0830 13:32:50.306206 main.cpp:802] Loading plugin(s) from: /home/sscotti/Desktop/OrthancConfig/plugins/libOrthancPython.so.mainline  
W0830 13:32:50.309307 PluginsManager.cpp:269] Registering plugin ‘python’ (version mainline)  
W0830 13:32:50.309342 PluginsManager.cpp:168] Python plugin is initializing  
W0830 13:32:50.309691 PluginsManager.cpp:168] Using Python script “combined.py” from directory: /home/sscotti/Desktop/OrthancConfig/plugins  
W0830 13:32:50.309733 PluginsManager.cpp:168] Force global loading of Python shared library: /lib/x86\_64-linux-gnu/libpython3.8.so.1.0  
W0830 13:32:50.309843 PluginsManager.cpp:168] Program name: /home/sscotti/Desktop/orthanc/Build/Orthanc  
E0830 13:32:50.369613 PluginsManager.cpp:164] Error during the installation of the Python script, traceback:  
\<class ‘ModuleNotFoundError’\>  
No module named ‘pydicom’  
File “”, line 991, in \_find\_and\_load  
File “”, line 975, in \_find\_and\_load\_unlocked  
File “”, line 671, in \_load\_unlocked  
File “”, line 783, in exec\_module  
File “”, line 219, in \_call\_with\_frames\_removed  
File “/home/sscotti/Desktop/OrthancConfig/plugins/combined.py”, line 4, in   
import pydicom  
File “”, line 991, in \_find\_and\_load  
File “”, line 973, in \_find\_and\_load\_unlocked  
E0830 13:32:50.369701 PluginsManager.cpp:102] Error while initializing plugin

`

My system has Python 3.8.2, which I think is installed by default on 20.04. When I built the plugin from source the compilation appeared to go OK.

`-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") -- Checking for module 'python-3.8-embed' -- Found python-3.8-embed, version 3.8 -- Configuring done -- Generating done`

pip3 list includes the two modules that I want enabled with the plugin (pdfkit and pydicom), and those were installed before building the plug-in:

`pdfkit 0.6.1 pexpect 4.6.0 Pillow 7.0.0 pip 20.0.2 protobuf 3.6.1 pycairo 1.16.2 pycups 1.9.73 pydicom 2.0.0`

The cmake was:cmake … -DPYTHON\_VERSION=3.8 -DSTATIC\_BUILD=ON -DCMAKE\_BUILD\_TYPE=Release

After commenting out import pydicom an import pdfkit:

`  
W0830 13:53:58.178403 main.cpp:802] Loading plugin(s) from: /home/sscotti/Desktop/OrthancConfig/plugins/libOrthancPython.so.mainline  
W0830 13:53:58.181938 PluginsManager.cpp:269] Registering plugin ‘python’ (version mainline)  
W0830 13:53:58.181983 PluginsManager.cpp:168] Python plugin is initializing  
W0830 13:53:58.182487 PluginsManager.cpp:168] Using Python script “combined.py” from directory: /home/sscotti/Desktop/OrthancConfig/plugins  
W0830 13:53:58.182542 PluginsManager.cpp:168] Force global loading of Python shared library: /lib/x86\_64-linux-gnu/libpython3.8.so.1.0  
W0830 13:53:58.182781 PluginsManager.cpp:168] Program name: /home/sscotti/Desktop/orthanc/Build/Orthanc  
. . . orthanc starts up

`

Just leaving out for now, but would like to compile with those modules enabled. Any suggestions appreciated.

Thanks.

---

<div class="post-metadata">

### Author: ![jodogne](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/jodogne/32/1511_2.png) [@jodogne](https://discourse.orthanc-server.org/u/jodogne)
#### Post date: [September 2, 2020, 1:00pm UTC](https://discourse.orthanc-server.org/t/issue-compiling-python-plugin-importing-pip-modules-ubuntu-20-04/2082/2 "2020-09-02T13:00:42Z")

</div>

Check out the attached Dockerfile and sample script.

As can be seen from this configuration, both pydicom and pdfkit work fine with Orthanc on Ubuntu 20.04.

By the way, answering your question took 1h30 of my time, just to conclude that there was no problem with Orthanc, but that it was an issue with your personal setup. You are endangering the development of Orthanc by claiming so many issues without providing minimal working examples:  
[https://book.orthanc-server.com/users/support.html#discussing-a-minimal-working-example](https://book.orthanc-server.com/users/support.html#discussing-a-minimal-working-example)

[Dockerfile](https://discourse.orthanc-server.org/uploads/short-url/40tN1QyZcXJT45uqi0KRO4yC3kc) (1.71 KB)

[sample.py](https://discourse.orthanc-server.org/uploads/short-url/2B9SUpvNGboHqIU5k4EbDjkooLW.py) (261 Bytes)

[configuration.json](https://discourse.orthanc-server.org/uploads/short-url/vTIkmEM2VOHPpGcUrMU8HvER7xO.json) (83 Bytes)

---

<div class="post-metadata">

### Author: ![Stephen\_Douglas\_Scot](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@Stephen\_Douglas\_Scot](https://discourse.orthanc-server.org/u/Stephen_Douglas_Scot)
#### Post date: [September 2, 2020, 4:44pm UTC](https://discourse.orthanc-server.org/t/issue-compiling-python-plugin-importing-pip-modules-ubuntu-20-04/2082/3 "2020-09-02T16:44:20Z")

</div>

Sorry about that. It took me about that long to write the e-mail, and much longer trying various things to compile. Must be something with my UBUNTU setup, although got OS X to work finally. I’ll follow up with the fix on my UBUNTU install if I can figure that out.

I am attaching a python script file containing a number of scripts that I’ve developed, including the one using pdfkit. You have to use PIP to install the pdfkit module, and then also compile the Python Plug-in again to use that, but it does work now. Same applies for pydicom Here is a description of the scripts, the source is attached.

# 1. curl [http://localhost:8042/pydicom/af1c0b10-c44ac936-74aa66e8-0c4463e0-2e98c65e](http://localhost:8042/pydicom/af1c0b10-c44ac936-74aa66e8-0c4463e0-2e98c65e) (uuid for instance)

# Demo for using Pydicom, can be extended. Bascially returns a dump2dcm.

# 2. curl [http://localhost:8042/get-configs/ALL](http://localhost:8042/get-configs/ALL)

# Gets Orthanc config file params, all or by a particular group;

# 3. curl [http://localhost:8042/sendemail](http://localhost:8042/sendemail) -d ‘{“subject”:“This is a test”,“body”:“string”}’

# Sends an email. Could be extended for HTML mails and other features, also callable from with the script.

# 4. curl [http://localhost:8042/studies/page](http://localhost:8042/studies/page) -d ‘{“Query”:{“PatientName”:“ **“,“PatientBirthDate”:”“,“PatientSex”:”“,“PatientID”:”“,“AccessionNumber”:”“,“StudyDescription”:”** ”,“ReferringPhysicianName”:“\*\*”,“StudyDate”:“”},“Level”:“Study”,“Expand”:true,“MetaData”:{},“pagenumber”:1,“itemsperpage”:5,“sortparam”:“StudyDate”,“reverse”:1,“widget”:1}’

# PAGINATION SCRIPT, SEE BELOW FOR DETAILS

# 5. curl -k -X POST -d ‘[“AccessionNumber”]’ [http://localhost:8042/mwl/file/delete](http://localhost:8042/mwl/file/delete)

# Deletes .wl file in the Worklists Folder, could be extended to delete multiple from array of values, the passed in param is the filename prefix

# 6. curl --request POST --url [http://localhost:8042/mwl/file/make](http://localhost:8042/mwl/file/make) --data ‘{“MediaStorageSOPClassUID”:“MediaStorageSOPClassUID”,“CharSet”:“CharSet”,“AccessionNumber”:“AccessionNumber”,“Modality”:“Modality”,“RequestingPhysician”:“RequestingPhysician”,“PatientName”:“PatientName”,“PatientID”:“PatientID”,“PatientBirthDate”:“PatientBirthDate”,“PatientSex”:“PatientSex”,“MedicalAlerts”:“MedicalAlerts”,“Allergies”:“Allergies”,“AdditionalPatientHistory”:“AdditionalPatientHistory”,“StudyInstanceUID”:“StudyInstanceUID”,“RequestingPhysician”:“RequestingPhysician”,“RequestedProcedureDescription”:“RequestedProcedureDescription”,“ScheduleStationAETitle”:“ScheduleStationAETitle”,“ScheduledProcedureStepStartDate”:“ScheduledProcedureStepStartDate”,“ScheduledProcedureStepStartTime”:“ScheduledProcedureStepStartTime”,“RequestedProcedureID”:“RequestedProcedureID”,“RequestedProcedurePriority”:“RequestedProcedurePriority”}’

# Creates a MWL .wl files and a .txt file in the Worlists Folder with a name equal to the Accession Number. Can be

# customized to meet needs

# 7. curl -k [http://localhost:8042/pdfkit/htmltopdf](http://localhost:8042/pdfkit/htmltopdf) -d ‘{“html”:“This is a test”,“method”:“string”}’

# Creates a PDF file from raw HTML string using wkhtmltopdf pdfkit wrapper. Requires the pip module and wkhtmltopdf installed on the system. The Python Plugin has to be compiled with that PIP module also.

# 8. curl -k [http://localhost:8042/studies/arrayIDs](http://localhost:8042/studies/arrayIDs) -d ‘[“6efb3ff2-4cd16ca1-35cdb247-2d1c5f78-d6ba584e”,“79de0218-30258875-1adaa569-f71944db-a88eef7c”]’

# Gets Array of Expanded study data for an array of uuid’s, including the instance count and modalities

# 9. curl -k [http://localhost:8042/patient/studycounts](http://localhost:8042/patient/studycounts) -d ‘[“DEV0000001”,“DEV0000002”]’

# Gets study counts for a patient ID, or array of ID’s

[combined.py](https://discourse.orthanc-server.org/uploads/short-url/37nQ601WQ0aXuOnGuajLk8kxBAi.py) (24.8 KB)

---

<div class="post-metadata">

### Author: ![Stephen\_Douglas\_Scot](https://discourse.orthanc-server.org/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@Stephen\_Douglas\_Scot](https://discourse.orthanc-server.org/u/Stephen_Douglas_Scot)
#### Post date: [September 4, 2020, 9:35pm UTC](https://discourse.orthanc-server.org/t/issue-compiling-python-plugin-importing-pip-modules-ubuntu-20-04/2082/4 "2020-09-04T21:35:42Z")

</div>

Just a comment.

I tried to add some Python scripts to: [OrthancContributed - GitHub](https://github.com/jodogne/OrthancContributed)  
and it looks like you have to have write privileges to add any files ?

I did separate out the one for using wkhtmltopdf into a separate file and did some testing. I’ve attached that. It is pretty well documented and has some sample HTML (escaped and including a style sheet), as well as a Base64encoded sample because it’ll also attach the generated PDF or the passed in Base64 as a series to a study if that is specified by the study uuid. It does require the wkhtmltopdf executable and dcmtk and the pdfkit Python PIP module, so there is a bit of a setup.

I found a somewhat more explicit way to compile the Python Plug-in on OS X, which works if you have several versions of Python:

cmake - **DPYTHON\_LIBRARY** =/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/lib/libpython3.8.dylib - **DPYTHON\_INCLUDE\_DIR** =/usr/local/Cellar/python@3.8/3.8.5/Frameworks/Python.framework/Versions/3.8/include/python3.8/ -DPYTHON\_VERSION=3.8 -DSTATIC\_BUILD=ON -DCMAKE\_BUILD\_TYPE=Release …/

Thanks for your help.

[pdfhtmlpython.py](https://discourse.orthanc-server.org/uploads/short-url/ilfXP509tXWu7zec7ObX5AFikwy.py) (20.7 KB)

---

<div class="post-metadata">

### Author: ![jodogne](https://discourse.orthanc-server.org/user_avatar/discourse.orthanc-server.org/jodogne/32/1511_2.png) [@jodogne](https://discourse.orthanc-server.org/u/jodogne)
#### Post date: [September 5, 2020, 9:22am UTC](https://discourse.orthanc-server.org/t/issue-compiling-python-plugin-importing-pip-modules-ubuntu-20-04/2082/5 "2020-09-05T09:22:28Z")

</div>

Hello,

In order to interact with the “OrthancContributed” repository, you’ll have to learn about GitHub pull requests. Many tutorials are available on the Web:  
[https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request)

[https://guides.github.com/activities/hello-world/](https://guides.github.com/activities/hello-world/)

I have added your instructions about Python and OS X in the Orthanc Book:  
[https://book.orthanc-server.com/plugins/python.html#compiling-from-source](https://book.orthanc-server.com/plugins/python.html#compiling-from-source)

Thanks for your contributions,  
Sébastien-
