Skip to content

Commit 90e2fbb

Browse files
authored
docs: add troubleshooting guide for packaging tm_devices with PyInstaller (#473)
1 parent 73aea27 commit 90e2fbb

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

docs/known_words.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ hostnames
4848
html
4949
http
5050
https
51+
hukkin
5152
io
5253
js
5354
keithley
@@ -103,6 +104,8 @@ tm
103104
tm_devices
104105
tmdevicessupport
105106
toml
107+
tomli
108+
traceback
106109
usb
107110
venv
108111
walkthrough

docs/troubleshooting/usage.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,80 @@ The `DeviceManager` will not be able to connect to a device defined as
3737
`TCPIP::device-hostname::INSTR` in the `yaml` file. Changing the resource
3838
definition to `TCPIP::DEVICE-HOSTNAME::INSTR` will allow the `DeviceManager` to
3939
connect to the device.
40+
41+
---
42+
43+
## Packaging `tm_devices` with PyInstaller
44+
45+
### Problem:
46+
47+
When using [PyInstaller](https://pyinstaller.org/en/stable/) to create an executable that includes `tm_devices`, you may encounter errors such as:
48+
49+
- `tm_devices library not installed` (even though it is installed)
50+
- `ModuleNotFoundError: No module named '3c22db458360489351e4._mypyc'`
51+
- Functionality dependent on `tm_devices` fails in the packaged app, but works in native Python.
52+
53+
This is often due to PyInstaller not correctly packaging compiled dependencies (like `tomli`) or missing package metadata required by `tm_devices`.
54+
55+
### Solution:
56+
57+
1. **Use a Virtual Environment:**
58+
59+
- Always create and activate a virtual environment before installing dependencies and running PyInstaller. This ensures all required packages are present and isolated.
60+
- Example:
61+
```bash
62+
python -m venv .venv
63+
64+
.venv\Scripts\activate # Windows
65+
# or
66+
source .venv/bin/activate # Linux/Mac
67+
68+
pip install tm_devices pyinstaller tomli==2.0.1
69+
```
70+
71+
2. **Install `tomli==2.0.1`:**
72+
73+
- The error caused by the missing `*_mypyc` files is due to PyInstaller not detecting compiled `tomli` files. Use `tomli` version 2.0.1 as a workaround.
74+
- Check your version:
75+
```bash
76+
pip show tomli
77+
```
78+
- If needed, install the correct version:
79+
```bash
80+
pip install tomli==2.0.1
81+
```
82+
83+
3. **Include `tm_devices` Metadata:**
84+
85+
- Use the `--copy-metadata=tm_devices` flag when running PyInstaller to ensure package metadata is included.
86+
- Example:
87+
```bash
88+
pyinstaller --onefile main.py --copy-metadata=tm_devices
89+
```
90+
91+
4. **If you see import errors for `DeviceManager` or `tm_devices`:**
92+
93+
- Make sure tm_devices is installed in the same environment as PyInstaller.
94+
- You can check with:
95+
```bash
96+
pip show tm_devices
97+
```
98+
99+
5. **Remove `ImportError` Catching for Debugging:**
100+
101+
- Temporarily remove any try/except blocks around `tm_devices` imports to see the full traceback and diagnose missing modules.
102+
103+
6. **Example Working `main.py`:**
104+
105+
```python
106+
from tm_devices import DeviceManager
107+
108+
with DeviceManager() as device_manager:
109+
scope = device_manager.add_scope("192.168.0.1")
110+
print(scope)
111+
```
112+
113+
### References:
114+
115+
- [hukkin/tomli#255](https://github.com/hukkin/tomli/issues/255)
116+
- [tektronix/tm_devices#470](https://github.com/tektronix/tm_devices/issues/470)

0 commit comments

Comments
 (0)