0

I have this Python 3 code that uses Tkinter, numpy, pylab, os ast, and matplotlib, along with CPLEX and some files (txt and png) to solve a type of Vehicle Routing Problem and I would like to turn into an executable (never done it before). I tried with pyinstaller but I keep getting this error Modulenotfound, while searching for a solution i found suggestions all over the place and none of them worked (or maybe i just did them wrong) to the point where i was wondering if i can even make this executable since my code implements from CPLEX (from docplex.mp.model import Model).

Thanks in advance for all your help.

Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22
Samji
  • 1
  • 1
  • If you cannot resolve your issues with one of the answers then maybe extend your question with the actual error message, backtrace etc. And also show *exactly* what you are doing, how you are invoking the tool etc. – Daniel Junglas Jul 06 '20 at 17:19

1 Answers1

0

auto-py-to-exe seems to be a really simple converter that's worked for me everytime.

A note, if you have any paths in your script (leading to textures, sounds, etc.), you will need to get their absolute path to work with the package by doing this:

def resource_path(relative_path):
    # Get absolute path to resource, works for dev and for PyInstaller
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except AttributeError:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

Specific to the modulenotfound error, check if this helps: https://nitratine.net/blog/post/issues-when-using-auto-py-to-exe/#how-to-fix-specific-issues

"This means a particular module ('x' in this case) was not added to the package. I have seen this occur with packages in the pandas library and win32api; as long as you can identify the package (e.g. 'x'), then it is very easy to fix. To fix this in the UI, open the advanced tab and find the --hidden-import input. Simply paste the module name into this input and then repackage. If the original error is still appearing, you have done this incorrectly. For example, if you are missing pandas._libs.tslib, add 'pandas._libs.tslib' into the input by --hidden-import. Additionally, you can add more than one module, for example, pandas._libs.tslib, win32api"

So in your case, I am assuming you would place the CPLEX library into the hidden imports.

Bhavye Mathur
  • 1,024
  • 1
  • 7
  • 25