IanHarvey / bluepy

Python interface to Bluetooth LE on Linux
Other
1.59k stars 491 forks source link

Can not make executable #367

Closed Machoney closed 5 years ago

Machoney commented 5 years ago

Hi. This is my first project on Linux. I do not exactly know how "executables" works here and quick research showed to use PyInstaller like on Windows.

I'm using:

The installation went with some warnings, but no one of them concern Bluetooth or bluepy. When I run my program, have error like his:

Traceback (most recent call last):
  File "app/Main.py", line 5, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/home/kacper/PycharmProjects/app/venv/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "app/Sensor.py", line 4, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/home/kacper/PycharmProjects/app/venv/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "scripts/BLE/SensorBLEController.py", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/home/kacper/PycharmProjects/app/venv/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "bluepy/__init__.py", line 2, in <module>
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "/home/kacper/PycharmProjects/app/venv/lib/python3.7/site-packages/PyInstaller/loader/pyimod03_importers.py", line 627, in exec_module
    exec(bytecode, module.__dict__)
  File "bluepy/btle.py", line 889, in <module>
  File "bluepy/btle.py", line 870, in __init__
  File "bluepy/btle.py", line 882, in get_json_uuid
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEI6WEUtd/bluepy/uuids.json'
[32758] Failed to execute script GatewayApp

I went deep into the code, and it looks like the path to the bluepy-helper is incorrect.

helperExe = os.path.join(script_path, "bluepy-helper") used in:

def get_json_uuid():
    import json
    with open(os.path.join(script_path, 'uuids.json'),"rb") as fp:
...

I don't understand why he's referring to the /tmp/ folder, if it's generated from venv.

Did anyone have such a problem?

Machoney commented 5 years ago

Okey, I have figure it out.

I have build bluepy from source in my venv. Then I set to run bluepy-helper as a normal user. sudo setcap 'cap_net_raw,cap_net_admin+eip' bluepy-helper

After that, I have run pyinstaller one more time and it works.

bambachas commented 3 years ago

@Machoney can you describe with details what you done to make it works i have the same problem

JimmyWang1989 commented 2 years ago

@bambachas this issue is caused by the required data file from bluepy is missed when PyInstaller trying collect the dependency. Put the attached hook-bluepy.py(change from .txt to .py) under /site-packages/PyInstaller/hooks and re-run the PyInstaller generation process can fix the problem hook-bluepy.txt

amartineze2i commented 1 year ago

@bambachas this issue is caused by the required data file from bluepy is missed when PyInstaller trying collect the dependency. Put the attached hook-bluepy.py(change from .txt to .py) under /site-packages/PyInstaller/hooks and re-run the PyInstaller generation process can fix the problem hook-bluepy.txt

It works for me.