Linux Mint 19安装Anaconda 3后启动报错求助
Looks like you're hitting a bug in Anaconda Navigator's VS Code integration script—it doesn't properly recognize Linux Mint, leading to an uninitialized variable error. Here's how to fix it:
Option 1: Update Anaconda Navigator (Recommended)
First, try updating Navigator to the latest version, since this issue might have been patched already:
conda update anaconda-navigator
After the update completes, restart Anaconda Navigator. If the error goes away, you're done!
Option 2: Manually Fix the VS Code Detection Script
If updating doesn't resolve the issue, you can edit the problematic script directly:
- Open the
vscode.pyfile in a text editor (I'll usenanofor simplicity):
nano /home/partha/anaconda3/lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py
- Locate the
_find_linux_install_dirfunction. You'll see code that parses the distro name but doesn't account for Linux Mint. Modify it to:- Initialize
DISTRO_NAMEat the start of the function - Add a check for Linux Mint and map it to Ubuntu (since Mint is Ubuntu-based)
- Add a fallback for unrecognized distros
- Initialize
Here's the updated code snippet for the function:
def _find_linux_install_dir(self): INST_DIR = None SUBDIR = None INST_EXT = None DISTRO_NAME = None # Initialize the variable to avoid UnboundLocalError try: with open('/etc/os-release') as f: distro_info = f.read() # Parse distro name if 'ID=ubuntu' in distro_info: DISTRO_NAME = 'ubuntu' elif 'ID=debian' in distro_info: DISTRO_NAME = 'debian' elif 'ID=fedora' in distro_info: DISTRO_NAME = 'fedora' elif 'ID=rhel' in distro_info or 'ID=centos' in distro_info: DISTRO_NAME = 'rhel' elif 'ID=linuxmint' in distro_info: DISTRO_NAME = 'ubuntu' # Mint is based on Ubuntu, use Ubuntu's paths except Exception as e: pass # Handle distro-specific paths if DISTRO_NAME in ['ubuntu', 'debian']: SUBDIR = 'bin' INST_EXT = '.deb' INST_DIR = '/usr/share/code' if not os.path.exists(INST_DIR): INST_DIR = '/opt/code' elif DISTRO_NAME == 'fedora': SUBDIR = 'bin' INST_EXT = '.rpm' INST_DIR = '/usr/share/code' elif DISTRO_NAME == 'rhel': SUBDIR = 'bin' INST_EXT = '.rpm' INST_DIR = '/usr/share/code' else: # Fallback: check common VS Code installation locations common_dirs = ['/usr/share/code', '/opt/code', '/usr/local/bin/code'] for dir_path in common_dirs: if os.path.exists(dir_path): INST_DIR = dir_path SUBDIR = 'bin' break return SUBDIR, INST_EXT, INST_DIR
Save the file (in
nano, pressCtrl+O, hit Enter, thenCtrl+Xto exit).Restart Anaconda Navigator—this should resolve the
UnboundLocalErrorsinceDISTRO_NAMEis now properly initialized and mapped for Linux Mint.
Why This Happens
The error occurs because the script tries to check DISTRO_NAME before it's assigned a value. Linux Mint isn't in the original list of detected distros, so the variable stays uninitialized until the conditional check, triggering the error. By adding Mint support and initializing the variable, we fix this gap.
内容的提问来源于stack exchange,提问作者Partha D.

