Skip to content
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

Import error after pyinstaller #133

Closed
Anniywell opened this issue Mar 2, 2018 · 6 comments
Closed

Import error after pyinstaller #133

Anniywell opened this issue Mar 2, 2018 · 6 comments

Comments

@Anniywell
Copy link

Anniywell commented Mar 2, 2018

I install keyboard from master code.

  File "my_code.py", line 4, in <module>
    import keyboard
  File "c:\miniconda3\envs\x86\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 631, in exec_module

    exec(bytecode, module.__dict__)
  File "site-packages\keyboard\__init__.py", line 126, in <module>
  File "importlib\__init__.py", line 109, in import_module
ImportError: No module named 'keyboard._winkeyboard'
@2press
Copy link

2press commented Mar 15, 2018

You have to add an hidden import for PyInstaller when you use the current master code:

hiddenimports=['keyboard._winkeyboard']

@boppreh
Copy link
Owner

boppreh commented Mar 25, 2018

What's the best practices around pyinstaller? Should _winkeyboard be named something else to be included automatically?

@2press
Copy link

2press commented Mar 26, 2018

I don't know what is the best practice with pyinstaller. The problem is the use of importlib and the fact that it effectively hides the import from pyinstaller:

_os_keyboard = _importlib.import_module(
{
'Windows': '._winkeyboard',
'Linux': '._nixkeyboard',
'Darwin': '._darwinkeyboard',
}[_platform.system()],
__package__
) # 100% coverage or bust.

The previous if-else-import chain was fully compatible with pyinstaller:
574f259#diff-78144a085fc983d74768166c57ad6c89

Is there any reason why we can't go back to this?

@boppreh
Copy link
Owner

boppreh commented Mar 26, 2018

Ah, so PyInstaller is probably parsing the source code to find imports. No, there's no reason why we cannot go back. I'll revert the change as soon as I get home.

Now I feel kinda stupid for doing that just to get 100% coverage. Oh well, living is learning.

@ivanhercaz
Copy link

ivanhercaz commented May 16, 2018

Hi,
I tried to use this module but I get this error too, ImportError after install with pip install keyboard. The traceback:

ImportError                               Traceback (most recent call last)
<ipython-input-1-f0d8a51b726e> in <module>()
----> 1 import keyboard

ImportError: No module named 'keyboard'

The same without IPython.

Regards,
Iván

@CrafterFlanceBOOM
Copy link

Hello,
I got an error yesterday. I tried deleting the keyboard folder and then install it again with pip,
but it does not even work still. I also got Visual Studio 2017 and I think that's problem.
Traceback:

C:\Users\brand\Desktop\VirusShooter>"Virus Shooter.py"
Traceback (most recent call last):
File "C:\Users\brand\Desktop\VirusShooter\Virus Shooter.py", line 1, in
import keyboard
ImportError: No module named keyboard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants