Why can't the packaged program run?

A few simple lines of code all have problems, so there must be many problems with the big project :face_exhaling:

I didn’t even import the numpy module before, and there was a problem. I imported it but it still had problems

import pyautogui,numpy

box = pyautogui.locateOnScreen('q.png')
p = pyautogui.center(box)
pyautogui.click(p.x,p.y+8)

pyinstaller -F nocv.py

PS D:\TOOLS\temp77\dist> D:\TOOLS\temp77\dist\nocv.exe
OpenCV bindings requires "numpy" package.
Install it via command:
    pip install numpy
Traceback (most recent call last):
  File "numpy\core\__init__.py", line 24, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "numpy\core\multiarray.py", line 10, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "numpy\core\overrides.py", line 8, in <module>
ImportError: DLL load failed while importing _multiarray_umath: The specified module could not be found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "numpy\__init__.py", line 144, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "numpy\__config__.py", line 4, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "numpy\core\__init__.py", line 50, in <module>
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.

We have compiled some common reasons and troubleshooting tips at:

    https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  * The Python version is: Python3.10 from "D:\TOOLS\temp77\dist\nocv.exe"
  * The NumPy version is: "1.26.4"

and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "nocv.py", line 1, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 495, in exec_module
  File "numpy\__init__.py", line 149, in <module>
ImportError: Error importing numpy: you should not try to import numpy from
        its source directory; please exit the numpy source tree, and relaunch
        your python interpreter from there.
[22244] Failed to execute script 'nocv' due to unhandled exception!

Have you installed numpy?
To install, enter:

pip install numpy

Undoubtedly, it was installed, and the previous code can be run

Seems that pyinstaller failed to detect you need numpy.
What I do when a .exe tool fails to find dependencies is add
an explicit import into my script.

If you add import numpy in nocv.py it may fix it.

I wrote the import section at the beginning as:

import pyautogui
import numpy

But it still doesn’t work, it still keeps reporting errors

Did you check that when you run

that it actually creates the executable that you expect and puts it in the place you expect, with the name you expect?

There is no problem with the code. I have checked that it can run, and as for the location and name, they are default and have not been changed.

Upgrading numpy and pyinstaller will be fine.