title: Something wrong with how I'm bundling rasterio into an executable
body: <h2>Expected behavior and actual behavior.</h2>
  
  <p>I expected to compile a script using <code>rasterio</code> into an executable using <code>pyinstaller</code>.  The script runs fine from within my python environment. However I am not able to freeze it into an executable using <code>PyInstaller</code>.</p>
  
  <h2>Steps to reproduce the problem.</h2>
  
  <p>I have a script called <code>workflow_3.py</code> which contains the following:</p>
  
  <p><code>import rasterio</code></p>
  
  <p>That's it. I tried to compile then run this using  pyinstaller as follows:</p>
  
  <p><code>
  (wps_env36) D:\11202750-002_RA2CE\Basis&gt;pyinstaller workflow_3.py
  (wps_env36) D:\11202750-002_RA2CE\Basis&gt;dist\workflow_3\workflow_3.exe
  </code></p>
  
  <p>The compilation seems to run to completion, however when I run the executable I get the following error:</p>
  
  <pre><code>(wps_env36) D:\11202750-002_RA2CE\Basis&gt;dist\workflow_3\workflow_3.exe
  Traceback (most recent call last):
    File "workflow_3.py", line 1, in &lt;module&gt;
      import rasterio
    File "c:\programdata\anaconda2\envs\wps_env36\lib\site-packages\PyInstaller\loader\pyimod03_i
  mporters.py", line 627, in exec_module
      exec(bytecode, module.__dict__)
    File "site-packages\rasterio\__init__.py", line 23, in &lt;module&gt;
    File "rasterio\_base.pyx", line 1, in init rasterio._base
  ModuleNotFoundError: No module named 'rasterio._shim'
  [17536] Failed to execute script workflow_3
  </code></pre>
  
  <h2>Attempt to fix the problem</h2>
  
  <p>I modified the spec file  by explicitly adding <code>'rasterio._shim'</code> to the list contained by the <code>hidden-imports</code> variable.  Then I ran <code>pyinstaller workflow_3.spec</code> . This caused other <code>ModuleNotFoundError</code> for modules such as <code>control</code>.py, <code>crs.py</code> and <code>vrt.py</code>. </p>
  
  <p>Adding these to <code>hidden-imports</code> successfully eliminates the <code>ModuleNotFoundError</code> 
   for that particular package but it still looks for other packages, all of which are contained in <code>C:\ProgramData\Anaconda2\envs\wps_env36\Lib\site-packages\rasterio</code>. There are about 40 modules in this directory. It seems excessive to add every single filename in this directory to the <code>hidden-imports</code> variable. In fact I don't even know if it would work.</p>
  
  <p>Therefore, I also tried adding that whole directory into my <code>pathex</code> variable so that it can extend the <code>PYTHONPATH</code> with it. However this causes another problem:</p>
  
  <p><code>
    File "c:\programdata\anaconda2\envs\wps_env36\lib\traceback.py", line 5, in &lt;module&gt;
    File "c:\programdata\anaconda2\envs\wps_env36\lib\linecache.py", line 11, in &lt;module&gt;
    File "c:\programdata\anaconda2\envs\wps_env36\lib\tokenize.py", line 27, in &lt;module&gt;
  ImportError: cannot import name 'open'
  pre-safe-import-module hook failed, needs fixing.
  </code></p>
  
  <h2>Operating system</h2>
  
  <p>Windows 7</p>
  
  <h2>Rasterio version and provenance</h2>
  
  <p>The rasterio version is 1.0.8, from conda-forge
  The python version is 3.6.6</p>
  
  <p>I have two versions of pyinstaller</p>
  
  <pre><code>pyinstaller               3.4              py36h7602738_0    conda-forge
  PyInstaller               3.5.dev0+b13e6b30b           &lt;pip&gt;
  </code></pre>
  
  <p>The second one is the development version, which I had to get because of <a href="https://github.com/pyinstaller/pyinstaller/issues/3750" rel="noreferrer">this problem</a> </p>
  
  <h2>Question</h2>
  
  <p>How do I use <code>PyInstaller</code> to freeze an application which uses <code>rasterio</code>?</p>