title: How to call a Rust function from a Python file using pyo3?
body: <p>I'm working on a videogame in which I'll need to set Rust objects (like, add a button with <code>texture:"", coords:"", text:"", action:""</code>) from Python files.</p>
  
  <p>I'm using the pyo3 crate to link Python and Rust. I succeed calling Python scripts from my Rust code, but I can't find how to call a Rust function from a Python file.</p>
  
  <p>Rust code that executes my Python script:</p>
  
  <pre class="lang-rust prettyprint-override"><code>fn main() -&gt; PyResult&lt;()&gt; {
      let gil = Python::acquire_gil();
      let py = gil.python();
      let script = fs::read_to_string("deep_hello.py")?;
  
      println!("RUNNING :\n[\n{}]", script);
      py.run(&amp;script, None, None)
  }
  </code></pre>
  
  <p>Rust function that I'd like to call from my Python script:</p>
  
  <pre class="lang-rust prettyprint-override"><code>/// hello_from_rust(/)
  /// --
  ///
  /// This function prints hello because she is very nice.
  #[pyfunction]
  fn hello_from_rust() {
      println!("Hello from rust from python !");
  }
  </code></pre>
  
  <p>My Python script:</p>
  
  <pre class="lang-py prettyprint-override"><code>hello_from_rust()
  </code></pre>
  
  <p>I'm getting this output:</p>
  
  <pre class="lang-none prettyprint-override"><code>RUNNING :
  [
  hello_from_rust()
  ]
  Error: PyErr { type: Py(0x7f9cdd1e9580, PhantomData) }
  </code></pre>