auto-py-to-exe icon indicating copy to clipboard operation
auto-py-to-exe copied to clipboard

Unique case of 'can't find module' error

Open 0xJonasDev opened this issue 3 years ago • 5 comments
trafficstars

First, I have to commend you on your hard work in putting this together. I just came across auto-py-to-exe via a youtube video and it is tremendously more convenient than using command-line pyInstaller.

So, I've read your help documentation (which is well done as well) and I've followed every necessary step to my knowledge but I'm still running into 'can't find module' errors. I'll go step by step to be as clear as possible:

  1. I have a precompiled program (using different software) that is in a similar file structure as what you would get in a One Directory output except that the program initiator is a batch file instead of an .exe. My goal is to bundle all of the files into One File and it hasn't been a cakewalk in the park -- putting it lightly.

  2. I used Auto-Py-to-Exe with the following config pyinstaller --noconfirm --onedir --console --icon "path_to_icon" --name "MyProgram" --debug "all" --add-data "path_to_files".

  3. Here's the file structure before using Auto-Py-to-Exe. Files added to Auto-Py-to-Exe include (All files/folder except Anon.session, MyProgram.bat , MyProgram-lnk.bat and __pycache__ : image

  4. Here's the entry file run.py:

import os, sys

def resource_path(relative):
    return os.path.join(os.environ.get("_MEIPASS2", os.path.abspath(".")), relative)
    
wt_dir = resource_path("Third-party\wt_1.12.10732.0_x64__8wekyb3d8bbwe\wt.exe") 

py_dir = resource_path("python.exe")

app_dir = resource_path("app.zip")

os.system(f"start {wt_dir} -w -1 nt -p MyProgram {py_dir} {app_dir} %*")  # Opens app.zipp in Windows terminal shell using the default profile.
  1. It seems like it's not finding the encoding folder which is located inside the python39.zip. The files inside the encoding folder are pre-compiled by the other software so that may be suspect. I've tried adding encodings as a --hidden-import but it still failed with the same error. Here's the error message:
Python path configuration:
  PYTHONHOME = (not set)
  PYTHONPATH = (not set)
  program name = 'C:\Users\Owner\Desktop\M-95\M-95\python.exe'
  isolated = 0
  environment = 1
  user site = 1
  import site = 1
  sys._base_executable = 'C:\\Users\\Owner\\Desktop\\M-95\\M-95\\python.exe'
  sys.base_prefix = 'C:\\Users\\Owner\\Desktop\\M-95\\M-95'
  sys.base_exec_prefix = 'C:\\Users\\Owner\\Desktop\\M-95\\M-95'
  sys.platlibdir = 'lib'
  sys.executable = 'C:\\Users\\Owner\\Desktop\\M-95\\M-95\\python.exe'
  sys.prefix = 'C:\\Users\\Owner\\Desktop\\M-95\\M-95'
  sys.exec_prefix = 'C:\\Users\\Owner\\Desktop\\M-95\\M-95'
  sys.path = [
    'C:\\Users\\Owner\\Desktop\\M-95\\M-95\\python39.zip',
    'C:\\Users\\Owner\\Desktop\\M-95\\M-95\\DLLs',
    'C:\\Users\\Owner\\Desktop\\M-95\\M-95\\lib',
    'C:\\Users\\Owner\\Desktop\\M-95\\M-95',
  ]
Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
Traceback (most recent call last):
  File "<frozen zipimport>", line 241, in load_module
  File "<frozen zipimport>", line 721, in _get_module_code
zipimport.ZipImportError: can't find module 'encodings'
  1. What do I need to do to get over this hurdle, please? Any advise would help, thanks

0xJonasDev avatar Apr 19 '22 00:04 0xJonasDev

I see under 5, it's expecting the Python lib folder (that holds the standard library modules) to be at C:\\Users\\Owner\\Desktop\\M-95\\M-95\\lib, however in your screenshot (assuming that this was another run and the directory "App" is actually "M-95"), that folder does not exist.

I imagine Python will be looking for the encodings module typically found in lib. Unfortunately I am not aware of why this folder is not being added.

brentvollebregt avatar Apr 20 '22 03:04 brentvollebregt

@brentvollebregt Thanks for your response. Yes, you're right, the "App" directory was later changed to "M-95" after the screenshot was taken (Sorry for the confusion).

That makes a lot of sense. How would you advise adding the lib folder to see if that'll work? Manually as an additional folder or as a hidden package?

0xJonasDev avatar Apr 20 '22 05:04 0xJonasDev

You could try copying in your existing lib folder from your Python 3.9.x installation (is by the Scripts folder in the installation root) into the generated executable. This may solve the issue but doesn't really provide a solution for later generations.

This does look like a PyInstaller issue as auto-py-to-exe seems to be doing what it should. What version of PyInstaller are you using?

brentvollebregt avatar Apr 21 '22 03:04 brentvollebregt

This issue is stale because it has been open for 60 days with no activity. Remove stale label or comment on this issue or it will be closed in 5 days.

github-actions[bot] avatar Jun 19 '22 01:06 github-actions[bot]

This issue is stale because it has been open for 60 days with no activity. Remove stale label or comment on this issue or it will be closed in 5 days.

github-actions[bot] avatar Jul 21 '22 01:07 github-actions[bot]

This issue is stale because it has been open for 60 days with no activity. Remove stale label or comment on this issue or it will be closed in 5 days.

github-actions[bot] avatar Aug 22 '22 01:08 github-actions[bot]

Closing issue due to no activity in more than 60 days.

github-actions[bot] avatar Aug 27 '22 01:08 github-actions[bot]