title: Cannot generate a pyinstaller binary from python files or from cython generated library files
body: <p>I wish to make a standalone executable binary from a small python (2.7) project on linux.</p>
  
  <p><strong>My project is structured this way:</strong></p>
  
  <pre><code>- proto/
      - main.py
      - file1.py
      - file2.py
      - gui/
          - __init__.py
          - file3.py
          - file4.py
          - qt/
              - __init__.py
              - file5.py
              - file6.py
      - external/
          - __init__.py
          - ext1/
              - __init__.py
              - file7.py
              - file8.py
  </code></pre>
  
  <p><strong>1- I converted all .py files to .so files</strong> (except <code>main.py</code> and all <code>__init__.py</code>) in a separate folder, using cython/distutil :</p>
  
  <pre><code>-proto_cython/
      - main.py
      - file1.so
      - file2.so
      - gui/
          - __init__.py
          - file3.so
          - file4.so
          - qt/
              - __init__.py
              - file5.so
              - file6.so
      - external/
          - __init__.py
          - ext1/
              - __init__.py
              - file7.so
              - file8.so
  </code></pre>
  
  <p>And it works fine when I run <code>python main.py</code></p>
  
  <p><strong>2 - Now I want to get rid of .py files completely</strong>, so I try to do it using pyinstaller. It may not be the right tool by the way.</p>
  
  <p><code>pyinstaller --onefile --clean --name=gui main.py</code></p>
  
  <p><strong>2.a - pyinstaller from folder proto_cython</strong></p>
  
  <p>I get this error when I run dist/gui:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;string&gt;", line 6, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 416, in load_module
      module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
    File "mainwindow.py", line 9, in init gui.mainwindow (/home/cyrille/proto/gui/mainwindow.c:2312)
  ImportError: No module named qt.ui_mainwindow
  </code></pre>
  
  <p>(There is a <code>ui_mainwindow.so</code> file in <code>gui/qt</code>)</p>
  
  <p>Well, before trying to correct it, let's try without cython/distutil generated .so files (only original .py files)</p>
  
  <p><strong>2.b - pyinstaller from folder proto</strong></p>
  
  <p>I get this error when I run dist/gui:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;string&gt;", line 6, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
      exec(bytecode, module.__dict__)
    File "/home/cyrille/proto/build/gui/out00-PYZ.pyz/gui.mainwindow", line 16, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
      exec(bytecode, module.__dict__)
    File "/home/cyrille/proto/build/gui/out00-PYZ.pyz/gui.viewerconfigwidget", line 6, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
      exec(bytecode, module.__dict__)
    File "/home/cyrille/proto/build/gui/out00-PYZ.pyz/viewer", line 15, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
      exec(bytecode, module.__dict__)
    File "/home/cyrille/proto/build/gui/out00-PYZ.pyz/sklearn.decomposition", line 7, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
      exec(bytecode, module.__dict__)
    File "/home/cyrille/proto/build/gui/out00-PYZ.pyz/sklearn.decomposition.nmf", line 22, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
      exec(bytecode, module.__dict__)
    File "/home/cyrille/proto/build/gui/out00-PYZ.pyz/sklearn.utils", line 17, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
      exec(bytecode, module.__dict__)
    File "/home/cyrille/proto/build/gui/out00-PYZ.pyz/sklearn.utils.sparsetools", line 3, in &lt;module&gt;
    File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 416, in load_module
      module = imp.load_module(fullname, fp, filename, self._c_ext_tuple)
    File "_min_spanning_tree.pyx", line 8, in init sklearn.utils.mst._min_spanning_tree (sklearn/utils/sparsetools/_min_spanning_tree.c:4754)
  ImportError: No module named _graph_validation
  </code></pre>
  
  <p><strong>3 - So, it looks I have more than one problem here</strong>:</p>
  
  <ul>
  <li><p>pyinstaller doesn't seem to like <a href="http://scikit-learn.org/" rel="nofollow" title="scikit-learn website">scikit-learn</a> module </p></li>
  <li><p>pyinstaller can't find imports from cython generated files</p></li>
  </ul>
  
  <p>Any idea to go further ?</p>
  
  <p><strong>EDIT</strong>
  In both cases (pure python and .so files), the generated gui.spec looks like:</p>
  
  <pre><code># -*- mode: python -*-
  
  block_cipher = None
  
  
  a = Analysis(['proto.py'],
               pathex=['/home/cyrille/proto'],
               hiddenimports=[],
               hookspath=None,
               runtime_hooks=None,
               excludes=None,
               cipher=block_cipher)
  pyz = PYZ(a.pure,
               cipher=block_cipher)
  exe = EXE(pyz,
            a.scripts,
            a.binaries,
            a.zipfiles,
            a.datas,
            name='proto_gui',
            debug=False,
            strip=None,
            upx=True,
            console=True
  </code></pre>