troubleshooting - itzmetanjim/py-positron GitHub Wiki
This guide helps you solve common issues when working with PyPositron.
Problem: ModuleNotFoundError: No module named 'py_positron'
Solutions:
-
Check installation:
pip show py-positron
-
Reinstall the package:
pip uninstall py-positron pip install py-positron
-
Check Python environment:
which python which pip
-
Install with --user flag:
pip install --user py-positron
Problem: Permission denied during installation
Solutions:
-
Use --user flag:
pip install --user py-positron
-
Use virtual environment:
python -m venv myenv # Windows: myenv\Scripts\activate # Linux/macOS: source myenv/bin/activate pip install py-positron
Problem: Conflicting package versions
Solutions:
-
Create fresh virtual environment:
python -m venv fresh_env source fresh_env/bin/activate # or fresh_env\Scripts\activate on Windows pip install py-positron
-
Update pip:
pip install --upgrade pip
Problem: 'positron' is not recognized as an internal or external command
Solutions:
-
Check if Python Scripts directory is in PATH:
# Windows echo $env:PATH # Linux/macOS echo $PATH
-
Use python -m instead:
python -m py_positron.cli create
-
Reinstall package:
pip uninstall py-positron pip install py-positron
Problem: Error during positron create
Solutions:
-
Check directory permissions:
- Ensure you have write access to the target directory
- Try creating in a different location
-
Check disk space:
- Ensure sufficient disk space
-
Run with elevated privileges (if necessary):
# Windows (run as Administrator) # Linux/macOS sudo positron create
Problem: Virtual environment creation fails
Solutions:
-
Manual venv creation:
cd your_project python -m venv venv # Windows: venv\Scripts\activate # Linux/macOS: source venv/bin/activate
-
For macOS users:
-
Check Python version:
python --version # Should be 3.9+
Problem: FileNotFoundError: HTML file not found
Solutions:
-
Check file path:
import os print(os.path.abspath("views/index.html")) print(os.path.exists("views/index.html"))
-
Verify working directory:
import os print(os.getcwd())
-
Use absolute paths:
import os html_path = os.path.join(os.path.dirname(__file__), "views", "index.html") main.openUI(html_path) # App starts automatically
Problem: Application starts but no window appears
Solutions:
-
Check for errors in console:
- Look for Python error messages
-
Verify HTML content:
- Ensure HTML file is valid
- Check for syntax errors
-
Test with minimal HTML:
<!DOCTYPE html> <html> <head><title>Test</title></head> <body><h1>Test</h1></body> </html>
-
Check PyWebView dependencies:
pip install --upgrade pywebview
Problem: Code in <py>
tags doesn't execute
Solutions:
-
Check for Python syntax errors:
- Ensure proper indentation
- Check for missing imports
-
Verify py tag styling:
py { display: none; }
-
Check browser console for errors:
- Right-click → Inspect → Console
-
Test with simple code:
<py> print("This should appear in console") document.alert("Hello from Python!") </py>
Problem: document.getElementById
returns None
Solutions:
-
Check element ID:
<button id="my-button">Click me</button> <py> button = document.getElementById('my-button') if button: print("Button found!") else: print("Button not found!") </py>
-
Ensure DOM is loaded:
<py> # Code runs after DOM is loaded button = document.getElementById('my-button') </py>
-
Use setTimeout for delayed execution:
<py> import time def delayed_setup(): button = document.getElementById('my-button') if button: button.addEventListener('click', handle_click) # Run after a small delay window.setTimeout(delayed_setup, 100) </py>
Problem: App takes long time to load
Solutions:
-
Optimize imports:
# Import only what you need from py_positron import openUI # Note: start() is called automatically by openUI()
-
Move heavy operations to background:
import threading def heavy_task(): # Long-running operation pass # Run in background thread = threading.Thread(target=heavy_task) thread.daemon = True thread.start()
-
Minimize HTML file size:
- Remove unnecessary CSS/JS
- Optimize images
Problem: High memory consumption
Solutions:
-
Clear unused variables:
del large_data_structure import gc gc.collect()
-
Avoid circular references:
# Use weak references when needed import weakref
-
Monitor memory usage:
import psutil import os process = psutil.Process(os.getpid()) print(f"Memory usage: {process.memory_info().rss / 1024 / 1024:.2f} MB")
Problem: PowerShell execution policy errors
Solution:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Problem: Antivirus blocking application
Solution:
- Add PyPositron installation directory to antivirus exclusions
- Add your project directory to exclusions
Problem: "App can't be opened" security warning
Solutions:
-
Allow in Security & Privacy:
- System Preferences → Security & Privacy → General
- Click "Allow anyway"
-
Run from Terminal first:
cd your_project positron start
Problem: Missing GUI libraries
Solution:
# Ubuntu/Debian
sudo apt-get install python3-tk python3-dev
# Red Hat/Fedora
sudo dnf install python3-tkinter python3-devel
# Arch Linux
sudo pacman -S tk python-pip
Add debug information to your application:
import logging
logging.basicConfig(level=logging.DEBUG)
import py_positron as main
main.openUI("views/index.html")
# App starts automatically
Add console output to track execution:
<py>
print("Python code executing...")
def debug_function():
print("Function called!")
return "Success"
# Test function
result = debug_function()
print(f"Result: {result}")
</py>
Wrap risky code in try-catch blocks:
<py>
try:
risky_operation()
except Exception as e:
print(f"Error occurred: {e}")
import traceback
traceback.print_exc()
</py>
Debug event handler registration:
<py>
def check_handlers():
if hasattr(window, '_py_context'):
handlers = list(window._py_context.event_handlers.keys())
print(f"Registered handlers: {handlers}")
else:
print("No context found")
check_handlers()
</py>
- Official Documentation: GitHub Wiki
- API Reference: API Documentation
- Examples: Examples Guide
- GitHub Issues: Report bugs or ask questions
- Discussions: Community discussions
Include the following information:
-
Environment details:
- Operating system and version
- Python version
- PyPositron version
-
Error details:
- Complete error message
- Stack trace
- Steps to reproduce
-
Code samples:
- Minimal reproducible example
- Relevant configuration files
Example issue template:
**Environment:**
- OS: Windows 11
- Python: 3.13.0
- PyPositron: 0.0.1.6
**Problem:**
Description of the issue...
**Steps to reproduce:**
1. Run `positron create`
2. Add this code...
3. Error occurs...
**Error message:**
Paste complete error message here
**Code:**
```python
# Minimal example that reproduces the issue
This should help you resolve most common issues with PyPositron. If you encounter a problem not covered here, please check the GitHub issues or create a new one.