From 42fb2b782d536b034428e1af754a6de22d8fc1c9 Mon Sep 17 00:00:00 2001 From: Martin Laasmaa Date: Fri, 5 Dec 2025 16:18:37 +0200 Subject: [PATCH] Bug fix in installing and lauching the program --- INSTALL_TEST.md | 236 ++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 9 +- setup.py | 2 +- src/cli.py | 2 +- src/gui_launcher.py | 49 +++++++++ 5 files changed, 291 insertions(+), 7 deletions(-) create mode 100644 INSTALL_TEST.md create mode 100644 src/gui_launcher.py diff --git a/INSTALL_TEST.md b/INSTALL_TEST.md new file mode 100644 index 0000000..8740da4 --- /dev/null +++ b/INSTALL_TEST.md @@ -0,0 +1,236 @@ +# Installation Testing Guide + +This guide helps you verify that the package installation works correctly. + +## Clean Installation Test + +### 1. Remove Any Previous Installations + +```bash +# Deactivate any active virtual environment +deactivate + +# Remove old virtual environment (if exists) +rm -rf venv + +# Create fresh virtual environment +python3 -m venv venv +source venv/bin/activate # On Linux/Mac +# or +venv\Scripts\activate # On Windows +``` + +### 2. Install the Package + +#### Option A: Editable/Development Install + +```bash +pip install -e . +``` + +This allows you to modify source code and see changes immediately. + +#### Option B: Regular Install + +```bash +pip install . +``` + +This installs the package as if it were from PyPI. + +### 3. Verify Installation + +```bash +# Check package is installed +pip list | grep microscopy + +# Check version +microscopy-detect --version +# Expected output: microscopy-object-detection 1.0.0 + +# Test Python import +python -c "import src; print(src.__version__)" +# Expected output: 1.0.0 +``` + +### 4. Test Entry Points + +```bash +# Test CLI +microscopy-detect --help + +# Test GUI launcher (will open window) +microscopy-detect-gui +``` + +### 5. Verify Package Contents + +```python +# Run this in Python shell +import src +import src.database +import src.model +import src.gui + +# Check schema file is included +from pathlib import Path +import src.database +db_path = Path(src.database.__file__).parent +schema_file = db_path / 'schema.sql' +print(f"Schema file exists: {schema_file.exists()}") +# Expected: Schema file exists: True +``` + +## Troubleshooting + +### Issue: ModuleNotFoundError + +**Error:** +``` +ModuleNotFoundError: No module named 'src' +``` + +**Solution:** +```bash +# Reinstall with verbose output +pip install -e . -v + +# Or try regular install +pip install . --force-reinstall +``` + +### Issue: Entry Points Not Working + +**Error:** +``` +microscopy-detect: command not found +``` + +**Solution:** +```bash +# Check if scripts are in PATH +which microscopy-detect + +# If not found, check pip install location +pip show microscopy-object-detection + +# You might need to add to PATH or use full path +~/.local/bin/microscopy-detect # Linux +``` + +### Issue: Import Errors for PySide6 + +**Error:** +``` +ImportError: cannot import name 'QApplication' from 'PySide6.QtWidgets' +``` + +**Solution:** +```bash +# Install Qt dependencies (Linux only) +sudo apt-get install libxcb-xinerama0 + +# Reinstall PySide6 +pip uninstall PySide6 +pip install PySide6 +``` + +### Issue: Config Files Not Found + +**Error:** +``` +FileNotFoundError: config/app_config.yaml +``` + +**Solution:** +The config file should be created automatically. If not: +```bash +# Create config directory in your home +mkdir -p ~/.microscopy-detect +cp config/app_config.yaml ~/.microscopy-detect/ + +# Or run from source directory first time +cd /home/martin/code/object_detection +python main.py +``` + +## Manual Testing Checklist + +- [ ] Package installs without errors +- [ ] Version command works (`microscopy-detect --version`) +- [ ] Help command works (`microscopy-detect --help`) +- [ ] GUI launches (`microscopy-detect-gui`) +- [ ] Can import all modules in Python +- [ ] Database schema file is accessible +- [ ] Configuration loads correctly + +## Build and Install from Wheel + +```bash +# Build the package +python -m build + +# Install from wheel +pip install dist/microscopy_object_detection-1.0.0-py3-none-any.whl + +# Test +microscopy-detect --version +``` + +## Uninstall + +```bash +pip uninstall microscopy-object-detection +``` + +## Development Workflow + +### After Code Changes + +If installed with `-e` (editable mode): +- Python code changes are immediately available +- No need to reinstall + +If installed with regular `pip install .`: +- Reinstall after changes: `pip install . --force-reinstall` + +### After Adding New Files + +```bash +# Reinstall to include new files +pip install -e . --force-reinstall +``` + +## Expected Installation Output + +``` +Processing /home/martin/code/object_detection + Installing build dependencies ... done + Getting requirements to build wheel ... done + Preparing metadata (pyproject.toml) ... done +Building wheels for collected packages: microscopy-object-detection + Building wheel for microscopy-object-detection (pyproject.toml) ... done +Successfully built microscopy-object-detection +Installing collected packages: microscopy-object-detection +Successfully installed microscopy-object-detection-1.0.0 +``` + +## Success Criteria + +Installation is successful when: +1. ✅ No error messages during installation +2. ✅ `pip list` shows the package +3. ✅ `microscopy-detect --version` returns correct version +4. ✅ GUI launches without errors +5. ✅ All Python modules can be imported +6. ✅ Database operations work +7. ✅ Detection functionality works + +## Next Steps After Successful Install + +1. Configure image repository path +2. Run first detection +3. Train a custom model +4. Export results + +For usage instructions, see [QUICKSTART.md](QUICKSTART.md) \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index d5993d6..7737939 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"] +requires = ["setuptools>=45", "wheel"] build-backend = "setuptools.build_meta" [project] @@ -63,10 +63,9 @@ Repository = "https://github.com/yourusername/object_detection" microscopy-detect = "src.cli:main" [project.gui-scripts] -microscopy-detect-gui = "main:main" +microscopy-detect-gui = "src.gui_launcher:main" [tool.setuptools] -package-dir = { "" = "." } packages = [ "src", "src.database", @@ -77,10 +76,10 @@ packages = [ "src.gui.widgets", "src.utils", ] +include-package-data = true [tool.setuptools.package-data] -src = ["database/*.sql"] -"" = ["config/*.yaml"] +"src.database" = ["*.sql"] [tool.black] line-length = 88 diff --git a/setup.py b/setup.py index 59a43a1..0366ec6 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ setup( "microscopy-detect=src.cli:main", ], "gui_scripts": [ - "microscopy-detect-gui=main:main", + "microscopy-detect-gui=src.gui_launcher:main", ], }, keywords="microscopy yolov8 object-detection segmentation computer-vision deep-learning", diff --git a/src/cli.py b/src/cli.py index 482ee52..5c02da4 100644 --- a/src/cli.py +++ b/src/cli.py @@ -44,7 +44,7 @@ Examples: if args.gui: # Launch GUI try: - from main import main as gui_main + from src.gui_launcher import main as gui_main gui_main() except Exception as e: diff --git a/src/gui_launcher.py b/src/gui_launcher.py new file mode 100644 index 0000000..1b921b0 --- /dev/null +++ b/src/gui_launcher.py @@ -0,0 +1,49 @@ +"""GUI launcher module for microscopy object detection application.""" + +import sys +from pathlib import Path + +from PySide6.QtWidgets import QApplication +from PySide6.QtCore import Qt + +from src import __version__ +from src.gui.main_window import MainWindow +from src.utils.logger import setup_logging +from src.utils.config_manager import ConfigManager + + +def main(): + """Launch the GUI application.""" + # Setup logging + config_manager = ConfigManager() + log_config = config_manager.get_section("logging") + setup_logging( + log_file=log_config.get("file", "logs/app.log"), + level=log_config.get("level", "INFO"), + log_format=log_config.get("format"), + ) + + # Enable High DPI scaling + QApplication.setHighDpiScaleFactorRoundingPolicy( + Qt.HighDpiScaleFactorRoundingPolicy.PassThrough + ) + + # Create Qt application + app = QApplication(sys.argv) + app.setApplicationName("Microscopy Object Detection") + app.setOrganizationName("MicroscopyLab") + app.setApplicationVersion(__version__) + + # Set application style + app.setStyle("Fusion") + + # Create and show main window + window = MainWindow() + window.show() + + # Run application + sys.exit(app.exec()) + + +if __name__ == "__main__": + main()