如何为私有仓库集成PyInstaller与PyUpdater更新功能?
Can PyUpdater Integrate with Private BitBucket Repositories?
Absolutely! PyUpdater does support private BitBucket repositories—you just need to fix a few configuration and code issues. Let’s walk through the solutions step by step, starting with the problems in your current setup, then the correct implementation.
First, Let’s Fix Your Existing Issues
Looking at your config and code, here are the key blockers:
- Your
PUBLIC_KEYis set to'None'—PyUpdater requires a valid public key (generated during your PyUpdater packaging workflow) to verify update signatures. - You’re re-initializing the
Clientmultiple times, overwriting your SSH config each time. - Your SSH key handling is broken (you pasted raw key content incorrectly instead of loading it properly).
ASSET_NAMEandASSET_VERSIONare undefined, which will throw errors when checking for updates.- Your
UPDATE_URLSpath is invalid—BitBucket private repos use standard Git URLs, not a custom/downloadpath.
Solution 1: SSH Key Authentication (Recommended for Security)
Step 1: Set Up BitBucket SSH Key
You already generated an SSH key with ssh-keygen -t rsa -C "youremail@example.com"—now:
- Copy your public key (
~/.ssh/id_rsa.pubcontent) - Add it to your BitBucket account: Go to BitBucket Settings → SSH keys → Add key
- Ensure your private key (
id_rsa) is unencrypted, or set upssh-agentto auto-unlock it if it has a passphrase.
Step 2: Update Your Client Config
Modify client_config.py to specify Git as the provider and your BitBucket repo SSH URL:
class ClientConfig(object): # Replace with your actual PyUpdater public key (not 'None') PUBLIC_KEY = 'your-generated-pyupdater-public-key' APP_NAME = 'dad123' COMPANY_NAME = 'dad123' # Tell PyUpdater to use Git as the update source PROVIDER = 'git' # Your BitBucket repo SSH URL (replace with your actual repo path) UPDATE_URLS = ['git@bitbucket.org:Tysondogerz/your-repo-name.git'] MAX_DOWNLOAD_RETRIES = 3
Step 3: Fix Your Main Script
Clean up the redundant Client initializations and properly load your SSH key:
#!/usr/bin/env python3 from __future__ import print_function import os import sys import logging from selenium import webdriver from client_config import ClientConfig from pyupdater.client import Client # Configure logging logging.basicConfig(level=logging.DEBUG) def load_ssh_key(key_path): """Load SSH private key from file""" with open(key_path, 'r') as f: return f.read() def print_status_info(info): """Show download progress""" total = info.get('total') downloaded = info.get('downloaded') status = info.get('status') print(f"{downloaded}/{total} - {status}") def main(): # Load your SSH private key (adjust path if needed) ssh_key_path = os.path.expanduser('~/.ssh/id_rsa') ssh_config = { 'ssh_key': load_ssh_key(ssh_key_path), # Uncomment below if your key has a passphrase # 'passphrase': 'your-key-passphrase' } # Initialize Client ONCE with SSH config client = Client( ClientConfig(), ssh=ssh_config, refresh=True, progress_hooks=[print_status_info] ) # Check for updates (replace with your app name and current version) ASSET_NAME = 'dad123' ASSET_VERSION = '1.0.0' app_update = client.update_check(ASSET_NAME, ASSET_VERSION) # Use this line instead to check beta channel updates: # app_update = client.update_check(ASSET_NAME, ASSET_VERSION, channel='beta') if app_update is not None: print("Update found! Starting download...") app_update.download() print("Download complete. Installing update...") app_update.install() print("Update installed. Restarting app...") sys.exit(0) else: print("You're already on the latest version.") # Your existing app logic driver = webdriver.Firefox() driver.get('http://stackoverflow.com') if __name__ == "__main__": main()
Solution 2: HTTPS with BitBucket App Password (Simpler)
If SSH feels too complex, use a BitBucket App Password:
- Go to BitBucket Settings → App passwords → Create app password
- Grant the
Repository readpermission, then save the generated password. - Update your
ClientConfigwith the HTTPS URL containing your credentials:class ClientConfig(object): PUBLIC_KEY = 'your-generated-pyupdater-public-key' APP_NAME = 'dad123' COMPANY_NAME = 'dad123' PROVIDER = 'git' # Format: https://{username}:{app-password}@bitbucket.org/{username}/{repo-name}.git UPDATE_URLS = ['https://your-bitbucket-username:your-app-password@bitbucket.org/Tysondogerz/your-repo-name.git'] MAX_DOWNLOAD_RETRIES = 3 - In your main script, you don’t need SSH config—just initialize the Client normally:
client = Client(ClientConfig(), refresh=True, progress_hooks=[print_status_info])
Final Testing Steps
- Make sure your BitBucket repo contains the PyUpdater-generated update files (like
updates.json,dad123-1.0.1.tar.gz, etc.). - Repackage your app with the fixed config and code.
- Run the packaged app—you should see it successfully check for and download updates from your private BitBucket repo.
内容的提问来源于stack exchange,提问作者user9155788
相关产品推荐
相关产品推荐

