title: How to list all python packages used by a script in python3
body: <p>There's a few of these question I've read through, but they all seem to link to methods exclusively for python 2.x and I'm working in python 3.x.</p>
  
  <p>I have a python file, call it test.py, it has a number of package imports (eg. import numpy as np) but it also imports some other files, lets call them subTest1.py and subTest2.py. Each of the subTest files have their own imports (possibly both other files and packages). Is there an automated way to get a list of all packages required to run the route script (test.py)?</p>
  
  <p>I'm aware that pip freeze shows me every packages installed, but that's not what I'm looking for - there could be a package installed that isn't required to run the test.py script.</p>
  
  <p><strong>Questions that are similar but python 2.x:</strong></p>
  
  <p><a href="https://stackoverflow.com/questions/2572582/return-a-list-of-imported-python-modules-used-in-a-script">Return a list of imported Python modules used in a script?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/35796968/get-all-modules-packages-used-by-a-python-project">Get all modules/packages used by a python project</a></p>
  
  <p><strong>Packages that seem to be specific to python 2.x:</strong></p>
  
  <p>snakefood</p>
  
  <p>pipreqs</p>
  
  <p>Where pipreqs fails:</p>
  
  <pre><code>Traceback (most recent call last):
    File "c:\anaconda36\envs\tensorflow\lib\runpy.py", line 193, in _run_module_as_main
      "__main__", mod_spec)
    File "c:\anaconda36\envs\tensorflow\lib\runpy.py", line 85, in _run_code
      exec(code, run_globals)
    File "C:\Anaconda36\envs\tensorflow\Scripts\pipreqs.exe\__main__.py", line 9, in &lt;module&gt;
    File "c:\anaconda36\envs\tensorflow\lib\site-packages\pipreqs\pipreqs.py", line 396, in main
      init(args)
    File "c:\anaconda36\envs\tensorflow\lib\site-packages\pipreqs\pipreqs.py", line 341, in init
      extra_ignore_dirs=extra_ignore_dirs)
    File "c:\anaconda36\envs\tensorflow\lib\site-packages\pipreqs\pipreqs.py", line 91, in get_all_imports
      raise exc
    File "c:\anaconda36\envs\tensorflow\lib\site-packages\pipreqs\pipreqs.py", line 77, in get_all_imports
      tree = ast.parse(contents)
    File "c:\anaconda36\envs\tensorflow\lib\ast.py", line 35, in parse
      return compile(source, filename, mode, PyCF_ONLY_AST)
    File "&lt;unknown&gt;", line 49
      print vsize
                ^
  SyntaxError: Missing parentheses in call to 'print'
  </code></pre>