简体   繁体   中英

no module named error after pyinstaller python script

What I want: Turn a python file to executable file with all modules and start script.

Problem: Executable file gives no module named signalrcore when execute.

I already have module named 'signalrcore' but when I convert my python script to executable file with pyinstaller it wont work. The error is no module named signalrcore . It only appears with executable file. The python script is work fine. Script work with python2 python myscript.py -> work without any error. But python3 myscript.py -> have same error with executable file.

My python code:

from signalrcore.hub_connection_builder import HubConnectionBuilder

print('TEST')

My .spec file :

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None


a = Analysis(['service.py'],
             pathex=['/home/pi/Desktop/agent'],
             binaries=[],
             datas=[],
             hiddenimports=['signalrcore','signalrcore.hub_connection_builder'] ,

             hookspath=['/usr/lib/python2.7/dist-packages'],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)

pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='service',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False)

coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='service')

This errors pops while compile python code to executable ( sudo pyinstaller service.spec )

56429 INFO: Analyzing hidden import 'signalrcore'

56433 ERROR: Hidden import 'signalrcore' not found

56434 INFO: Analyzing hidden import 'signalrcore.hub_connection_builder'

56438 ERROR: Hidden import 'signalrcore.hub_connection_builder' not found

The problem seems to be, that you installed signalrcore only for the current user, but not for root.

Is there any reason, that you run pyinstaller as root?

This should not be necessary.

Call following command without sudo and look at the output.

python -c "import signalrcore ; print(signalrcore.__file__)"

It will show you where the signalrcore module is installed I assume, that this is a local path.

What is normally best is to use python virtualenv to have specific python setups for specific tasks. these virtualenvs can be shared amongst users as long as it is always one user (the one who created the virtualenv) who performs the pip installs and as long as the other is only using the virtualenv.

I suggest you try to read about virtualenvs. ( https://virtualenv.pypa.io/en/latest/ )

Very quick introduction

# install virtualenv
python -m pip install --user virtualenv  

# create a virtualenv
python -m virtualenv /path/to/virtualenv  # e.g /home/pi/virtualenv4service

# activate virtualenv
source /path/to/virtualenv/bin/activate

pip install signalrcore
pip install pyinstaller
pip install any_other_module_you_need

Then call pyinstaller with

pyinstaller service.spec

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM