Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ModuleNotFoundError: No module named 'imagehash'? #7088

Closed
Rapid1898-code opened this issue Sep 16, 2022 · 5 comments
Closed

ModuleNotFoundError: No module named 'imagehash'? #7088

Rapid1898-code opened this issue Sep 16, 2022 · 5 comments
Labels
triage Please triage and relabel this issue

Comments

@Rapid1898-code
Copy link

Hello - i have written a python-code which is using the imagehash module

from PIL import Image
import imagehash
import requests
img = "https://i.imgur.com/5bGzZi7.jpg"
resp = requests.get(img, stream=True)
ihashImg = imagehash.average_hash(Image.open(resp.raw)) 
print(ihashImg)

This works fine when i run the python-code in vscode.
But when i compile with pyinstaller (version 5.4.1) and try to create the windiows-exe with eg.

pyinstaller --onefile --hidden-import=imagehash test1.py
pyinstaller --onefile test1.py

With both variants i get this error when running the executeable:

Traceback (most recent call last):
  File "test1.py", line 2, in <module>
    import imagehash
ModuleNotFoundError: No module named 'imagehash'
[24964] Failed to execute script test1

Any ideas why this is not working?
Is it necessary to use some other parameters?

@Rapid1898-code Rapid1898-code added the triage Please triage and relabel this issue label Sep 16, 2022
@rokm
Copy link
Member

rokm commented Sep 16, 2022

Any ideas why this is not working?
Is it necessary to use some other parameters?

If a direct import from your entry-point script is not found at runtime, chances are very high that it cannot be found during the freezing process, typically because you have PyInstaller installed in a different python environment (virtual or base) than you usually use to run your code.

@Rapid1898-code
Copy link
Author

Hello - pyinstaller is also installed in the venv which i am using for program start.

@rokm
Copy link
Member

rokm commented Sep 16, 2022

What if you run pyinstaller via python -m PyInstaller instead of using the pyinstaller shim? The latter might (also) be installed in some other environment (which you can check with where pyinstaller)...

@Rapid1898-code
Copy link
Author

When i write this
python -m pyinstaller --onefile test2.py
he tells me for whatever reason
C:\Users\Polzi\Documents\DEV\.venv\test\Scripts\python.exe: No module named pyinstaller

But when i do pip list (within the activated venv) i get this:

pyinstaller               5.4.1
pyinstaller-hooks-contrib 2022.10

How is this possible?

When i do where pyinstaller i get:

C:\Users\Polzi\Documents\DEV\.venv\test\Scripts\pyinstaller.exe
C:\Users\Polzi\AppData\Local\Programs\Python\Python39\Scripts\pyinstaller.exe

@bwoodsend
Copy link
Member

PyInstaller the module name is case sensitive. You need to use python -m PyInstaller.

@pyinstaller pyinstaller locked and limited conversation to collaborators Sep 16, 2022
@bwoodsend bwoodsend converted this issue into discussion #7090 Sep 16, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
triage Please triage and relabel this issue
Projects
None yet
Development

No branches or pull requests

3 participants