# Python API

**URL:** https://discourse.kitware.com/t/python-api/684
**Category:** Pulse Physiology Engine
**Created:** [July 25, 2021, 6:20pm UTC](https://discourse.kitware.com/t/python-api/684 "2021-07-25T18:20:43Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![epitomeri](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/e/9fc348/32.png) [@epitomeri](https://discourse.kitware.com/u/epitomeri)
#### Post date: [July 25, 2021, 6:20pm UTC](https://discourse.kitware.com/t/python-api/684/1 "2021-07-25T18:20:44Z")

</div>

Hi all,

Following the instructions in the wiki, I was able to build Pulse with Python API support. I have my PYTHONPATH also updated appropriately. Looks like the pulse.cdm.bind module is missing? See below for the output from running a howto script. What have I misunderstood here? Any ideas.

TIA,  
Satish

**schimaku@eri:~/Development/Pulse/engine/src/python/pulse/howto$ python3 HowTo\_AcuteStress.py**  
Traceback (most recent call last):  
File “HowTo\_AcuteStress.py”, line 7, in   
from pulse.cpm.PulsePhysiologyEngine import PulsePhysiologyEngine  
File “/home/schimaku/Development/Pulse/engine/src/python/pulse/cpm/PulsePhysiologyEngine.py”, line 9, in   
from pulse.cdm.io.engine import serialize\_actions\_to\_string,   
File “/home/schimaku/Development/Pulse/engine/src/python/pulse/cdm/io/engine.py”, line 6, in   
from pulse.cdm.bind.Engine\_pb2 import AnyActionData,   
ModuleNotFoundError: No module named ‘pulse.cdm.bind’

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 26, 2021, 12:56pm UTC](https://discourse.kitware.com/t/python-api/684/2 "2021-07-26T12:56:58Z")

</div>

Hi epitomeri

You should have added 2 paths to your PYTHONPATH, the location of the python shared object, as well as the python folder as part of the pulse source code

Your path should look something like:

`ENV PYTHONPATH /source/src/python:/pulse/bin`

The error looks like you did not add the folder from the source code…

What is your python path?

---

<div class="post-metadata">

### Author: ![epitomeri](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/e/9fc348/32.png) [@epitomeri](https://discourse.kitware.com/u/epitomeri)
#### Post date: [July 26, 2021, 1:27pm UTC](https://discourse.kitware.com/t/python-api/684/3 "2021-07-26T13:27:28Z")

</div>

Hi Aaron,

I believe that my PYTHONPATH is as expected. Please see below.

**schimaku@eri:** ~$ echo $PYTHONPATH  
/home/schimaku/Development/Pulse/engine/src/python:/home/schimaku/Development/Pulse/builds/install/bin

The /src/python folder contains the following:  
CMakeLists.txt **init**.py pulse pybind setup.py venv

The ‘bin’ folder is the one that contains ‘PyPulse.cpython-38-x86\_64-linux-gnu.so’.

What else could I be missing?

Thanks in advance,  
Satish

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 26, 2021, 2:44pm UTC](https://discourse.kitware.com/t/python-api/684/4 "2021-07-26T14:44:40Z")

</div>

Do you have any files in your

/home/schimaku/Development/Pulse/engine/src/python/pulse/cdm/bind/

`aaron.bray@krs-812:~/Programming/pulse/engine/src/python/pulse/howto$ ls ~/Programming/pulse/engine/src/python/pulse/cdm/bind/ Actions_pb2.py Engine_pb2.py Inhaler_pb2.py Patient_pb2.py AnesthesiaMachineActions_pb2.py Enums_pb2.py __init__.py Physiology_pb2.py AnesthesiaMachine_pb2.py EnvironmentActions_pb2.py MechanicalVentilatorActions_pb2.py Properties_pb2.py BlackBox_pb2.py EnvironmentConditions_pb2.py MechanicalVentilator_pb2.py __pycache__ Circuit_pb2.py Environment_pb2.py PatientActions_pb2.py Scenario_pb2.py Compartment_pb2.py EquipmentActions_pb2.py PatientAssessments_pb2.py Substance_pb2.py Conditions_pb2.py Events_pb2.py PatientConditions_pb2.py SubstanceQuantity_pb2.py ElectroCardioGram_pb2.py InhalerActions_pb2.py PatientNutrition_pb2.py TestReport_pb2.py`

---

<div class="post-metadata">

### Author: ![epitomeri](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/e/9fc348/32.png) [@epitomeri](https://discourse.kitware.com/u/epitomeri)
#### Post date: [July 26, 2021, 2:50pm UTC](https://discourse.kitware.com/t/python-api/684/5 "2021-07-26T14:50:41Z")

</div>

No, as I mentioned in my original email, that module is missing somehow. There is no folder by name ‘bind’ under ‘cdm’. Have I not installed Pulse correctly? I did use the flag ‘-DPulse\_PYTHON\_API:BOOL=ON’ in my cmake command.

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 26, 2021, 2:53pm UTC](https://discourse.kitware.com/t/python-api/684/6 "2021-07-26T14:53:04Z")

</div>

Hmm  
Those should have been generated during the build  
I am currently generating these files in the source directory, which is not great…

You can regenerate those missing files by running this script from your install/bin

`aaron.bray@krs-812:~/Programming/builds/manual/pulse-engine/install/bin$ ./run.sh protoc`

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [July 27, 2021, 1:01pm UTC](https://discourse.kitware.com/t/python-api/684/7 "2021-07-27T13:01:35Z")

</div>

Hi epitomeri

I found a few issues I needed to correct to get python running.  
I pushed them to the head of 3.x, should be a quick rebuild if you `make install` from the Innerbuild

You should be good to go!

Let me know if you are still having issues!

---

<div class="post-metadata">

### Author: ![epitomeri](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/e/9fc348/32.png) [@epitomeri](https://discourse.kitware.com/u/epitomeri)
#### Post date: [July 27, 2021, 2:19pm UTC](https://discourse.kitware.com/t/python-api/684/8 "2021-07-27T14:19:37Z")

</div>

Thanks. In general, my Python build issues got resolved after I switched to 3.x branch from Master! The build is successful and the ‘bind’ folder is in place.

schimaku@eri:~/Development/Pulse-3.0/engine/src/python/pulse/howto$ python3 HowTo\_AcuteStress.py  
**Unable to load initial state file**

Could you tell me where to find the inputs necessary to run the scripts in the ‘howto’ folder? Running one of them threw an error as you can see above. Since I am a first time user, my goal is to go through some examples to understand what it is that Pulse can/cannot do. I figured that the scripts in the ‘howto’ folder are a good starting point unless you recommend otherwise.

Thanks in advance,  
Satish

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [August 4, 2021, 12:14pm UTC](https://discourse.kitware.com/t/python-api/684/9 "2021-08-04T12:14:21Z")

</div>

Hi Satish,

I accidentially responded to your question on the wrong forum thread

Moving the answer to this thread now

---

<div class="post-metadata">

### Author: ![abray](https://discourse.kitware.com/user_avatar/discourse.kitware.com/abray/32/12_2.png) [@abray](https://discourse.kitware.com/u/abray)
#### Post date: [August 4, 2021, 12:15pm UTC](https://discourse.kitware.com/t/python-api/684/10 "2021-08-04T12:15:19Z")

</div>

The HowTo files all load up a saved state that is found in your install/bin/states folder.  
In the code, they are specified via a relative directory, so these how to files are expected to be run in the install/bin folder, like this:

`aaron.bray@krs-812:~/Programming/builds/manual/pulse-engine/install/bin$ python3 ~/Programming/pulse/engine/src/python/pulse/howto/HowTo_AcuteStress.py`

I also run via PyCharm and just change the working directory  
Note, There is a pycharm project in the source/src/python folder you can point pycharm to

 ![image](https://discourse.kitware.com/uploads/default/original/1X/1d2932163fce0d297e1ef177da08cc8753aa4252.png)

I will add this to the python wiki page

---

<div class="post-metadata">

### Author: ![epitomeri](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/e/9fc348/32.png) [@epitomeri](https://discourse.kitware.com/u/epitomeri)
#### Post date: [August 7, 2021, 2:22am UTC](https://discourse.kitware.com/t/python-api/684/11 "2021-08-07T02:22:04Z")

</div>

Thanks Aaron. It worked now!
