title: Build Cython-compiled modules and python code into executable binary using PyInstaller
body: <p>I am trying to package my project code into a an executable binary using <code>Cython</code> and <code>PyInstaller</code> libraries.
  My code directory looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/o5J6L.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o5J6L.png" alt="Code Directory"></a>
  The <code>main.py</code> is the main code which imports the logic from <code>program_a.py</code> and <code>program_b.py</code>.</p>
  
  <p>I am successfully able to convert my <code>program_a</code> and <code>program_b</code> files into .so files which can be imported by any python code. I did this by executing the following script.</p>
  
  <pre><code>from distutils.core import setup
  from Cython.Build import cythonize
  
  sourcefiles = ['program_a.py', 'program_b.py']
  
  setup(
      name = "Hello World",
      ext_modules = cythonize(sourcefiles), 
  )
  </code></pre>
  
  <p>By executing ><code>python setup.py build_ext --inplace</code> I get <code>.so</code> files as shown below</p>
  
  <p><a href="https://i.stack.imgur.com/6CIgu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6CIgu.png" alt="binaries with libraries"></a>
  When I run <code>python main.py</code> it runs perfectly with <code>.so</code> files. Which shows that I can import them as a module.</p>
  
  <p>Now, I want to package binaries (.so) files and <code>main.py</code> into single binary file. For that I used the following command provided by <code>pyInstaller</code></p>
  
  <blockquote>
    <p><code>pyinstaller "main.py" --onefile</code></p>
  </blockquote>
  
  <p>It actually gives a binary in <code>dist/</code> folder but I cannot able to import some modules and getting the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "main.py", line 1, in &lt;module&gt;
      import program_a as lisence_checker
    File "program_a.py", line 1, in init program_a
  ModuleNotFoundError: No module named 'licensing'
  [18032] Failed to execute script main
  </code></pre>
  
  <p>How can I link libraries with the pyinstaller or embed library information into my binaries?</p>
  
  <p>What I found yet:</p>
  
  <ol>
  <li><p><a href="https://stackoverflow.com/questions/24525861/building-cython-compiled-python-code-with-pyinstaller">Building Cython-compiled python code with PyInstaller</a></p></li>
  <li><p><a href="https://riptutorial.com/cython/example/21982/bundling-a-cython-program-using-pyinstaller" rel="nofollow noreferrer">https://riptutorial.com/cython/example/21982/bundling-a-cython-program-using-pyinstaller</a></p></li>
  </ol>
  
  <p>But all of these above links are not using any external package inside there python code examples. I am able to compile the code without external modules</p>