Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'DISTRO_NAME' referenced before assignment #11662

Closed
AnmolMajithia opened this issue Mar 13, 2020 · 40 comments
Closed

Comments

@AnmolMajithia
Copy link

AnmolMajithia commented Mar 13, 2020

Actual Behavior

Opening anaconda navigator gives error and the opening splash gets stucks and doesn't load any further.

Expected Behavior

Anaconda navigator should open

Steps to Reproduce

After freshly installing Anaconda 3.7 and running anaconda-navigator on Linux Mint 19.3 i was faced with the error (give in the title)

Anaconda or Miniconda version:

Anaconda3-2020.02-Linux-x86_x64.sh

Operating System:

Linux Mint 19.3

conda info
PASTE OUTPUT HERE:
     active environment : base
    active env location : /home/anmol/anaconda3
            shell level : 1
       user config file : /home/anmol/.condarc
 populated config files : /home/anmol/.condarc
          conda version : 4.8.2
    conda-build version : 3.18.11
         python version : 3.7.6.final.0
       virtual packages : __glibc=2.27
       base environment : /home/anmol/anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/linux-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/linux-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /home/anmol/anaconda3/pkgs
                          /home/anmol/.conda/pkgs
       envs directories : /home/anmol/anaconda3/envs
                          /home/anmol/.conda/envs
               platform : linux-64
             user-agent : conda/4.8.2 requests/2.22.0 CPython/3.7.6 Linux/5.3.0-40-generic linuxmint/19.3 glibc/2.27
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

conda list --show-channel-urls
PASTE OUTPUT HERE:
# Name                    Version                   Build  Channel
_ipyw_jlab_nb_ext_conf    0.1.0                    py37_0    defaults
_libgcc_mutex             0.1                        main    defaults
alabaster                 0.7.12                   py37_0    defaults
anaconda                  2020.02                  py37_0    defaults
anaconda-client           1.7.2                    py37_0    defaults
anaconda-navigator        1.9.12                   py37_0    defaults
anaconda-project          0.8.4                      py_0    defaults
argh                      0.26.2                   py37_0    defaults
asn1crypto                1.3.0                    py37_0    defaults
astroid                   2.3.3                    py37_0    defaults
astropy                   4.0              py37h7b6447c_0    defaults
atomicwrites              1.3.0                    py37_1    defaults
attrs                     19.3.0                     py_0    defaults
autopep8                  1.4.4                      py_0    defaults
babel                     2.8.0                      py_0    defaults
backcall                  0.1.0                    py37_0    defaults
backports                 1.0                        py_2    defaults
backports.functools_lru_cache 1.6.1                      py_0    defaults
backports.shutil_get_terminal_size 1.0.0                    py37_2    defaults
backports.tempfile        1.0                        py_1    defaults
backports.weakref         1.0.post1                  py_1    defaults
beautifulsoup4            4.8.2                    py37_0    defaults
bitarray                  1.2.1            py37h7b6447c_0    defaults
bkcharts                  0.2                      py37_0    defaults
blas                      1.0                         mkl    defaults
bleach                    3.1.0                    py37_0    defaults
blosc                     1.16.3               hd408876_0    defaults
bokeh                     1.4.0                    py37_0    defaults
boto                      2.49.0                   py37_0    defaults
bottleneck                1.3.2            py37heb32a55_0    defaults
bzip2                     1.0.8                h7b6447c_0    defaults
ca-certificates           2020.1.1                      0    defaults
cairo                     1.14.12              h8948797_3    defaults
certifi                   2019.11.28               py37_0    defaults
cffi                      1.14.0           py37h2e261b9_0    defaults
chardet                   3.0.4                 py37_1003    defaults
click                     7.0                      py37_0    defaults
cloudpickle               1.3.0                      py_0    defaults
clyent                    1.2.2                    py37_1    defaults
colorama                  0.4.3                      py_0    defaults
conda                     4.8.2                    py37_0    defaults
conda-build               3.18.11                  py37_0    defaults
conda-env                 2.6.0                         1    defaults
conda-package-handling    1.6.0            py37h7b6447c_0    defaults
conda-verify              3.4.2                      py_1    defaults
contextlib2               0.6.0.post1                py_0    defaults
cryptography              2.8              py37h1ba5d50_0    defaults
curl                      7.68.0               hbc83047_0    defaults
cycler                    0.10.0                   py37_0    defaults
cython                    0.29.15          py37he6710b0_0    defaults
cytoolz                   0.10.1           py37h7b6447c_0    defaults
dask                      2.11.0                     py_0    defaults
dask-core                 2.11.0                     py_0    defaults
dbus                      1.13.12              h746ee38_0    defaults
decorator                 4.4.1                      py_0    defaults
defusedxml                0.6.0                      py_0    defaults
diff-match-patch          20181111                   py_0    defaults
distributed               2.11.0                   py37_0    defaults
docutils                  0.16                     py37_0    defaults
entrypoints               0.3                      py37_0    defaults
et_xmlfile                1.0.1                    py37_0    defaults
expat                     2.2.6                he6710b0_0    defaults
fastcache                 1.1.0            py37h7b6447c_0    defaults
filelock                  3.0.12                     py_0    defaults
flake8                    3.7.9                    py37_0    defaults
flask                     1.1.1                      py_0    defaults
fontconfig                2.13.0               h9420a91_0    defaults
freetype                  2.9.1                h8a8886c_1    defaults
fribidi                   1.0.5                h7b6447c_0    defaults
fsspec                    0.6.2                      py_0    defaults
future                    0.18.2                   py37_0    defaults
get_terminal_size         1.0.0                haa9412d_0    defaults
gevent                    1.4.0            py37h7b6447c_0    defaults
glib                      2.63.1               h5a9c865_0    defaults
glob2                     0.7                        py_0    defaults
gmp                       6.1.2                h6c8ec71_1    defaults
gmpy2                     2.0.8            py37h10f8cd9_2    defaults
graphite2                 1.3.13               h23475e2_0    defaults
greenlet                  0.4.15           py37h7b6447c_0    defaults
gst-plugins-base          1.14.0               hbbd80ab_1    defaults
gstreamer                 1.14.0               hb453b48_1    defaults
h5py                      2.10.0           py37h7918eee_0    defaults
harfbuzz                  1.8.8                hffaf4a1_0    defaults
hdf5                      1.10.4               hb1b8bf9_0    defaults
heapdict                  1.0.1                      py_0    defaults
html5lib                  1.0.1                    py37_0    defaults
hypothesis                5.5.4                      py_0    defaults
icu                       58.2                 h9c2bf20_1    defaults
idna                      2.8                      py37_0    defaults
imageio                   2.6.1                    py37_0    defaults
imagesize                 1.2.0                      py_0    defaults
importlib_metadata        1.5.0                    py37_0    defaults
intel-openmp              2020.0                      166    defaults
intervaltree              3.0.2                      py_0    defaults
ipykernel                 5.1.4            py37h39e3cac_0    defaults
ipython                   7.12.0           py37h5ca1d4c_0    defaults
ipython_genutils          0.2.0                    py37_0    defaults
ipywidgets                7.5.1                      py_0    defaults
isort                     4.3.21                   py37_0    defaults
itsdangerous              1.1.0                    py37_0    defaults
jbig                      2.1                  hdba287a_0    defaults
jdcal                     1.4.1                      py_0    defaults
jedi                      0.14.1                   py37_0    defaults
jeepney                   0.4.2                      py_0    defaults
jinja2                    2.11.1                     py_0    defaults
joblib                    0.14.1                     py_0    defaults
jpeg                      9b                   h024ee3a_2    defaults
json5                     0.9.1                      py_0    defaults
jsonschema                3.2.0                    py37_0    defaults
jupyter                   1.0.0                    py37_7    defaults
jupyter_client            5.3.4                    py37_0    defaults
jupyter_console           6.1.0                      py_0    defaults
jupyter_core              4.6.1                    py37_0    defaults
jupyterlab                1.2.6              pyhf63ae98_0    defaults
jupyterlab_server         1.0.6                      py_0    defaults
keyring                   21.1.0                   py37_0    defaults
kiwisolver                1.1.0            py37he6710b0_0    defaults
krb5                      1.17.1               h173b8e3_0    defaults
lazy-object-proxy         1.4.3            py37h7b6447c_0    defaults
ld_impl_linux-64          2.33.1               h53a641e_7    defaults
libarchive                3.3.3                h5d8350f_5    defaults
libcurl                   7.68.0               h20c2e04_0    defaults
libedit                   3.1.20181209         hc058e9b_0    defaults
libffi                    3.2.1                hd88cf55_4    defaults
libgcc-ng                 9.1.0                hdf63c60_0    defaults
libgfortran-ng            7.3.0                hdf63c60_0    defaults
liblief                   0.9.0                h7725739_2    defaults
libpng                    1.6.37               hbc83047_0    defaults
libsodium                 1.0.16               h1bed415_0    defaults
libspatialindex           1.9.3                he6710b0_0    defaults
libssh2                   1.8.2                h1ba5d50_0    defaults
libstdcxx-ng              9.1.0                hdf63c60_0    defaults
libtiff                   4.1.0                h2733197_0    defaults
libtool                   2.4.6                h7b6447c_5    defaults
libuuid                   1.0.3                h1bed415_2    defaults
libxcb                    1.13                 h1bed415_1    defaults
libxml2                   2.9.9                hea5a465_1    defaults
libxslt                   1.1.33               h7d1a2b0_0    defaults
llvmlite                  0.31.0           py37hd408876_0    defaults
locket                    0.2.0                    py37_1    defaults
lxml                      4.5.0            py37hefd8a0e_0    defaults
lz4-c                     1.8.1.2              h14c3975_0    defaults
lzo                       2.10                 h49e0be7_2    defaults
markupsafe                1.1.1            py37h7b6447c_0    defaults
matplotlib                3.1.3                    py37_0    defaults
matplotlib-base           3.1.3            py37hef1b27d_0    defaults
mccabe                    0.6.1                    py37_1    defaults
mistune                   0.8.4            py37h7b6447c_0    defaults
mkl                       2020.0                      166    defaults
mkl-service               2.3.0            py37he904b0f_0    defaults
mkl_fft                   1.0.15           py37ha843d7b_0    defaults
mkl_random                1.1.0            py37hd6b4f25_0    defaults
mock                      4.0.1                      py_0    defaults
more-itertools            8.2.0                      py_0    defaults
mpc                       1.1.0                h10f8cd9_1    defaults
mpfr                      4.0.1                hdf1c602_3    defaults
mpmath                    1.1.0                    py37_0    defaults
msgpack-python            0.6.1            py37hfd86e86_1    defaults
multipledispatch          0.6.0                    py37_0    defaults
navigator-updater         0.2.1                    py37_0    defaults
nbconvert                 5.6.1                    py37_0    defaults
nbformat                  5.0.4                      py_0    defaults
ncurses                   6.2                  he6710b0_0    defaults
networkx                  2.4                        py_0    defaults
nltk                      3.4.5                    py37_0    defaults
nose                      1.3.7                    py37_2    defaults
notebook                  6.0.3                    py37_0    defaults
numba                     0.48.0           py37h0573a6f_0    defaults
numexpr                   2.7.1            py37h423224d_0    defaults
numpy                     1.18.1           py37h4f9e942_0    defaults
numpy-base                1.18.1           py37hde5b4d6_1    defaults
numpydoc                  0.9.2                      py_0    defaults
olefile                   0.46                     py37_0    defaults
openpyxl                  3.0.3                      py_0    defaults
openssl                   1.1.1d               h7b6447c_4    defaults
packaging                 20.1                       py_0    defaults
pandas                    1.0.1            py37h0573a6f_0    defaults
pandoc                    2.2.3.2                       0    defaults
pandocfilters             1.4.2                    py37_1    defaults
pango                     1.42.4               h049681c_0    defaults
parso                     0.5.2                      py_0    defaults
partd                     1.1.0                      py_0    defaults
patchelf                  0.10                 he6710b0_0    defaults
path                      13.1.0                   py37_0    defaults
path.py                   12.4.0                        0    defaults
pathlib2                  2.3.5                    py37_0    defaults
pathtools                 0.1.2                      py_1    defaults
patsy                     0.5.1                    py37_0    defaults
pcre                      8.43                 he6710b0_0    defaults
pep8                      1.7.1                    py37_0    defaults
pexpect                   4.8.0                    py37_0    defaults
pickleshare               0.7.5                    py37_0    defaults
pillow                    7.0.0            py37hb39fc2d_0    defaults
pip                       20.0.2                   py37_1    defaults
pixman                    0.38.0               h7b6447c_0    defaults
pkginfo                   1.5.0.1                  py37_0    defaults
pluggy                    0.13.1                   py37_0    defaults
ply                       3.11                     py37_0    defaults
prometheus_client         0.7.1                      py_0    defaults
prompt_toolkit            3.0.3                      py_0    defaults
psutil                    5.6.7            py37h7b6447c_0    defaults
ptyprocess                0.6.0                    py37_0    defaults
py                        1.8.1                      py_0    defaults
py-lief                   0.9.0            py37h7725739_2    defaults
pycodestyle               2.5.0                    py37_0    defaults
pycosat                   0.6.3            py37h7b6447c_0    defaults
pycparser                 2.19                     py37_0    defaults
pycrypto                  2.6.1            py37h14c3975_9    defaults
pycurl                    7.43.0.5         py37h1ba5d50_0    defaults
pydocstyle                4.0.1                      py_0    defaults
pyflakes                  2.1.1                    py37_0    defaults
pygments                  2.5.2                      py_0    defaults
pylint                    2.4.4                    py37_0    defaults
pyodbc                    4.0.30           py37he6710b0_0    defaults
pyopenssl                 19.1.0                   py37_0    defaults
pyparsing                 2.4.6                      py_0    defaults
pyqt                      5.9.2            py37h05f1152_2    defaults
pyrsistent                0.15.7           py37h7b6447c_0    defaults
pysocks                   1.7.1                    py37_0    defaults
pytables                  3.6.1            py37h71ec239_0    defaults
pytest                    5.3.5                    py37_0    defaults
pytest-arraydiff          0.3              py37h39e3cac_0    defaults
pytest-astropy            0.8.0                      py_0    defaults
pytest-astropy-header     0.1.2                      py_0    defaults
pytest-doctestplus        0.5.0                      py_0    defaults
pytest-openfiles          0.4.0                      py_0    defaults
pytest-remotedata         0.3.2                    py37_0    defaults
python                    3.7.6                h0371630_2    defaults
python-dateutil           2.8.1                      py_0    defaults
python-jsonrpc-server     0.3.4                      py_0    defaults
python-language-server    0.31.7                   py37_0    defaults
python-libarchive-c       2.8                     py37_13    defaults
pytz                      2019.3                     py_0    defaults
pywavelets                1.1.1            py37h7b6447c_0    defaults
pyxdg                     0.26                       py_0    defaults
pyyaml                    5.3              py37h7b6447c_0    defaults
pyzmq                     18.1.1           py37he6710b0_0    defaults
qdarkstyle                2.8                        py_0    defaults
qt                        5.9.7                h5867ecd_1    defaults
qtawesome                 0.6.1                      py_0    defaults
qtconsole                 4.6.0                      py_1    defaults
qtpy                      1.9.0                      py_0    defaults
readline                  7.0                  h7b6447c_5    defaults
requests                  2.22.0                   py37_1    defaults
ripgrep                   11.0.2               he32d670_0    defaults
rope                      0.16.0                     py_0    defaults
rtree                     0.9.3                    py37_0    defaults
ruamel_yaml               0.15.87          py37h7b6447c_0    defaults
scikit-image              0.16.2           py37h0573a6f_0    defaults
scikit-learn              0.22.1           py37hd81dba3_0    defaults
scipy                     1.4.1            py37h0b6359f_0    defaults
seaborn                   0.10.0                     py_0    defaults
secretstorage             3.1.2                    py37_0    defaults
send2trash                1.5.0                    py37_0    defaults
setuptools                45.2.0                   py37_0    defaults
simplegeneric             0.8.1                    py37_2    defaults
singledispatch            3.4.0.3                  py37_0    defaults
sip                       4.19.8           py37hf484d3e_0    defaults
six                       1.14.0                   py37_0    defaults
snappy                    1.1.7                hbae5bb6_3    defaults
snowballstemmer           2.0.0                      py_0    defaults
sortedcollections         1.1.2                    py37_0    defaults
sortedcontainers          2.1.0                    py37_0    defaults
soupsieve                 1.9.5                    py37_0    defaults
sphinx                    2.4.0                      py_0    defaults
sphinxcontrib             1.0                      py37_1    defaults
sphinxcontrib-applehelp   1.0.1                      py_0    defaults
sphinxcontrib-devhelp     1.0.1                      py_0    defaults
sphinxcontrib-htmlhelp    1.0.2                      py_0    defaults
sphinxcontrib-jsmath      1.0.1                      py_0    defaults
sphinxcontrib-qthelp      1.0.2                      py_0    defaults
sphinxcontrib-serializinghtml 1.1.3                      py_0    defaults
sphinxcontrib-websupport  1.2.0                      py_0    defaults
spyder                    4.0.1                    py37_0    defaults
spyder-kernels            1.8.1                    py37_0    defaults
sqlalchemy                1.3.13           py37h7b6447c_0    defaults
sqlite                    3.31.1               h7b6447c_0    defaults
statsmodels               0.11.0           py37h7b6447c_0    defaults
sympy                     1.5.1                    py37_0    defaults
tbb                       2020.0               hfd86e86_0    defaults
tblib                     1.6.0                      py_0    defaults
terminado                 0.8.3                    py37_0    defaults
testpath                  0.4.4                      py_0    defaults
tk                        8.6.8                hbc83047_0    defaults
toolz                     0.10.0                     py_0    defaults
tornado                   6.0.3            py37h7b6447c_3    defaults
tqdm                      4.42.1                     py_0    defaults
traitlets                 4.3.3                    py37_0    defaults
ujson                     1.35             py37h14c3975_0    defaults
unicodecsv                0.14.1                   py37_0    defaults
unixodbc                  2.3.7                h14c3975_0    defaults
urllib3                   1.25.8                   py37_0    defaults
watchdog                  0.10.2                   py37_0    defaults
wcwidth                   0.1.8                      py_0    defaults
webencodings              0.5.1                    py37_1    defaults
werkzeug                  1.0.0                      py_0    defaults
wheel                     0.34.2                   py37_0    defaults
widgetsnbextension        3.5.1                    py37_0    defaults
wrapt                     1.11.2           py37h7b6447c_0    defaults
wurlitzer                 2.0.0                    py37_0    defaults
xlrd                      1.2.0                    py37_0    defaults
xlsxwriter                1.2.7                      py_0    defaults
xlwt                      1.3.0                    py37_0    defaults
xmltodict                 0.12.0                     py_0    defaults
xz                        5.2.4                h14c3975_4    defaults
yaml                      0.1.7                had09818_2    defaults
yapf                      0.28.0                     py_0    defaults
zeromq                    4.3.1                he6710b0_3    defaults
zict                      1.0.0                      py_0    defaults
zipp                      2.2.0                      py_0    defaults
zlib                      1.2.11               h7b6447c_3    defaults
zstd                      1.3.7                h0b5b093_0    defaults

@AnmolMajithia
Copy link
Author

AnmolMajithia commented Mar 13, 2020

Edit:
Another much simpler solution is just entering the command in the terminal:

conda update anaconda-navigator

Solved It By:
Editing the file : ".../anaconda3//lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py"

By declaring the variable outside the loop.

Just add the line :

DISTRO_NAME = None

on Line 159 and indent it in line with the if above it (Outside it)

devs can close this issue if the solution seems right

@RicFraga
Copy link

RicFraga commented Mar 18, 2020

I had exactly the same issue with exactly the same os, great to find a working solution!
The only problem is that now you can't install VS Code

@banstala
Copy link

banstala commented Mar 19, 2020

I too had the same error:
UnboundLocalError: local variable 'DISTRO_NAME' referenced before assignment
from a new Anaconda3-2020.02-Linux-x86_64 installation on Linux Mint 19 which got solved with the tips from @AnmolMajithia

Thanks a lot !
Here's the new line I added (with comments ## ... on the right)--

        ...

    def _find_linux_install_dir(self):
        INST_DIR = None
        exe = os.path.join('/snap', 'bin', 'code')
        if os.path.lexists(exe):
            INST_DIR = '/snap'

        DISTRO_NAME = None     ##  Adding this line... takes care of the bug in my case
        for distro in self.distro_map.keys():
            _distro_regex = ".*{}/([^ ]*)".format(distro)
            m = re.match(_distro_regex, self._conda_api.user_agent)
            if m:
                DISTRO_NAME = distro
                DISTRO_VER = m.group(1)
                break

        if DISTRO_NAME in ['ubuntu', 'debian']:
            _pkg_type = 'deb'
        else:
            _pkg_type = 'rpm'

        ...

@forrestwaters
Copy link

forrestwaters commented Mar 19, 2020

Please see #11635 (comment)

@MohamedAbdelrahim
Copy link

MohamedAbdelrahim commented Mar 23, 2020

Actual Behavior

Opening anaconda navigator gives error and the opening splash gets stucks and doesn't load any further.

Expected Behavior

Anaconda navigator should open

Steps to Reproduce

After freshly installing Anaconda 3.7 and running anaconda-navigator on Linux Mint 19.3 i was faced with the error (give in the title)

Anaconda or Miniconda version:

Anaconda3-2020.02-Linux-x86_x64.sh

Operating System:

Linux Mint 19.3

conda info
conda list --show-channel-urls

tnx i't work with me by elementary os too

@maharishi-coder
Copy link

maharishi-coder commented Mar 24, 2020

Thank you very much @AnmolMajithia

@ghost
Copy link

ghost commented Mar 25, 2020

I had exactly the same issue with exactly the same os, great to find a working solution!
The only problem is that now you can't install VS Code

That is not the case, I am using VS Code just fine. @RicFraga

@ghost
Copy link

ghost commented Mar 25, 2020

I wrote a beginner friendly guide here.

@olividir
Copy link

olividir commented Mar 25, 2020

This fix does not work on Manjaro 19.0.2 GNOME edition. Adding DISTRO_NAME = None to line 159 gives the error: api/external_apps/vscode.py", line 159 DISTRO_NAME = None ^ TabError: inconsistent use of tabs and spaces in indentation
I did watch out for indentation.

@olividir
Copy link

olividir commented Mar 25, 2020

I fixed my problem by putting this command into terminal: conda update anaconda-navigator

@hariszulfiqar054
Copy link

hariszulfiqar054 commented Mar 30, 2020

Solved It By:
Editing the file : ".../anaconda3//lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py"

By declaring the variable outside the loop.

Just add the line :

DISTRO_NAME = None

on Line 159 and indent it in line with the if above it (Outside it)

devs can close this issue if the solution seems right

Fixed my problem on zorin os Thanks mate.

@oluwaseun-Adesina
Copy link

oluwaseun-Adesina commented Apr 2, 2020

I too had the same error:
UnboundLocalError: local variable 'DISTRO_NAME' referenced before assignment
from a new Anaconda3-2020.02-Linux-x86_64 installation on Linux Mint 19 which got solved with the tips from @AnmolMajithia

Thanks a lot !
Here's the new line I added (with comments ## ... on the right)--

        ...

    def _find_linux_install_dir(self):
        INST_DIR = None
        exe = os.path.join('/snap', 'bin', 'code')
        if os.path.lexists(exe):
            INST_DIR = '/snap'

        DISTRO_NAME = None     ##  Adding this line... takes care of the bug in my case
        for distro in self.distro_map.keys():
            _distro_regex = ".*{}/([^ ]*)".format(distro)
            m = re.match(_distro_regex, self._conda_api.user_agent)
            if m:
                DISTRO_NAME = distro
                DISTRO_VER = m.group(1)
                break

        if DISTRO_NAME in ['ubuntu', 'debian']:
            _pkg_type = 'deb'
        else:
            _pkg_type = 'rpm'

        ...

Thanks I fixed the issue by add the line

@modicin
Copy link

modicin commented Apr 4, 2020

Hey guys, had a similar issue,

(base) modicin@modicin:~$ anaconda-navigator
Traceback (most recent call last):
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/widgets/main_window.py", line 541, in setup
    self.post_setup(conda_data=conda_data)
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/widgets/main_window.py", line 578, in post_setup
    self.tab_home.setup(conda_data)
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/widgets/tabs/home.py", line 169, in setup
    self.set_applications(applications, packages)
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/widgets/tabs/home.py", line 204, in set_applications
    apps = self.api.process_apps(applications, prefix=self.current_prefix)
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/api/anaconda_api.py", line 848, in process_apps
    app = app(config=self.config, process_api=self._process_api, conda_api=self._conda_api)
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py", line 48, in __init__
    **kwargs
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/api/external_apps/base.py", line 43, in __init__
    self.init()
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/api/external_apps/base.py", line 60, in init
    SUBDIR, INST_EXT, INST_DIR = self._find_linux_install_dir()
  File "/home/modicin/anaconda3/lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py", line 168, in _find_linux_install_dir
    if DISTRO_NAME in ['ubuntu', 'debian']:
UnboundLocalError: local variable 'DISTRO_NAME' referenced before assignment

simply fixed my issue by adding

DISTRO_NAME = 'ubuntu' 

to line 167 in column 9

works fine now, I assume if you are on a debian based distribution it will work by putting in 'debian' instead but can't guarantee.

@csoja
Copy link
Contributor

csoja commented Apr 6, 2020

Which build and version of Anaconda Navigator do you have?

@Nprash
Copy link

Nprash commented Apr 10, 2020

I fixed my problem by putting this command into terminal: conda update anaconda-navigator

in my case its working, i have also sucked with same error in kali linux but after updating anaconda-navigator, its working,thank you.

@csoja
Copy link
Contributor

csoja commented Apr 10, 2020

I'm going to close this as I believe it is fixed in the latest version of Anaconda-Navigator.

@csoja csoja closed this as completed Apr 10, 2020
@ivishalsinghhh
Copy link

ivishalsinghhh commented Apr 24, 2020

I too had the same error:

UnboundLocalError: local variable 'DISTRO_NAME' referenced before assignment

from a new Anaconda3-2020.02-Linux-x86_64 installation on Linux Mint 19.02 which got solved with the tips from @AnmolMajithia

Thanks a lot !
Here's the new line I added (with comments ## ... on the right)--

def _application_data(self):
"""Get app data from microsoft rest api."""
data = {}
url = (
'https://update.code.visualstudio.com/api/update'
'/{}/stable/version'.format(self._SUBDIR)
)
if url:
data = self._download_api.get_url(
url=url,
as_json=True,
non_blocking=False,
)
return data

def _find_linux_install_dir(self):
    INST_DIR = None
    exe = os.path.join('/snap', 'bin', 'code')
    if os.path.lexists(exe):
        INST_DIR = '/snap'
    DISTRO_NAME = None                               **##add this module in the script**
    for distro in self.distro_map.keys():
        _distro_regex = ".*{}/([^ ]*)".format(distro)
        m = re.match(_distro_regex, self._conda_api.user_agent)
        if m:
            DISTRO_NAME = distro
            DISTRO_VER = m.group(1)
            break

    if DISTRO_NAME in ['ubuntu', 'debian']:
        _pkg_type = 'deb'
    else:
        _pkg_type = 'rpm'

    _os_arch = 'x64' if OS_64_BIT else 'ia32'
    SUBDIR = 'linux-{}-{}'.format(_pkg_type, _os_arch)
    INST_EXT = _pkg_type
    if not INST_DIR:
        INST_DIR = '/usr/share/{}'.format(self.filename)

    return SUBDIR, INST_EXT, INST_DIR

@MMarcelo85
Copy link

MMarcelo85 commented May 9, 2020

Solved It By:
Editing the file : ".../anaconda3//lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py"

By declaring the variable outside the loop.

Just add the line :

DISTRO_NAME = None

on Line 159 and indent it in line with the if above it (Outside it)

devs can close this issue if the solution seems right

The solution posted by @AnmolMajithia Worked for me on Linux Mint 19.3!!
Thanks !

@nbelloy
Copy link

nbelloy commented May 11, 2020

Solved It By:
Editing the file : ".../anaconda3//lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py"

By declaring the variable outside the loop.

Just add the line :

DISTRO_NAME = None

on Line 159 and indent it in line with the if above it (Outside it)

devs can close this issue if the solution seems right

Thanks... it worked for me!

@rvmaurelli
Copy link

rvmaurelli commented May 14, 2020

Solved It By:
Editing the file : ".../anaconda3//lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py"

By declaring the variable outside the loop.

Just add the line :

DISTRO_NAME = None

on Line 159 and indent it in line with the if above it (Outside it)

devs can close this issue if the solution seems right

Hello!!
It worked for me on POP_OS 20.04
Thank you, mate. 👍

@leoc8697
Copy link

leoc8697 commented May 25, 2020

If you add the line "DISTRO_NAME = None" and it gives you an indentation error, you should just sort that line with spaces. Do not use the TAB key. And ready! The problem is solved. You can also try the command "conda update anaconda-navigator". These two things solved the problem for me on Arch Linux.

@Shrishml
Copy link

Shrishml commented May 25, 2020

Thanks a lot.

@RiseT
Copy link

RiseT commented May 28, 2020

The currently downloadable full installer (Anaconda3-2020.02) still doesn't contain a fix. But I've noticed that it'll get fixed if you update anaconda with conda update --all after the initial install.

After updating, the file mentioned by OP will contain the following added lines at the position suggested by the OP:

DISTRO_NAME = ''
DISTRO_VER = ''

@sar0868
Copy link

sar0868 commented Jun 5, 2020

Thanks !

@suvaanshkumar
Copy link

suvaanshkumar commented Jun 8, 2020

awesome buddy !!!!!!

@cprabhanjan
Copy link

cprabhanjan commented Jun 22, 2020

Updating the anaconda navigator will resolve the issue. You can use the following command..

sudo env "PATH=$PATH" conda update anaconda-navigator

Hope this helps.

@katirinenrikes
Copy link

katirinenrikes commented Jul 2, 2020

Thank you very much! Trying to install Anaconda in Kali Linux. This fixed the issue.

@jajapremier
Copy link

jajapremier commented Jul 6, 2020

Thank you ! now it's working fine.

@saimoncse19
Copy link

saimoncse19 commented Jul 11, 2020

I fixed my problem by putting this command into terminal: conda update anaconda-navigator

Thanks. It worked for me too.

@jafortti
Copy link

jafortti commented Jul 15, 2020

Thanks man, I apply it and after that all is ok.

@stevenossa21
Copy link

stevenossa21 commented Jul 20, 2020

I fixed my problem by putting this command into terminal: conda update anaconda-navigator

It works, thanks a lot.

@happybirddayspape
Copy link

happybirddayspape commented Jul 20, 2020

Solved It By:
Editing the file : ".../anaconda3//lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py"

By declaring the variable outside the loop.

Just add the line :

DISTRO_NAME = None

on Line 159 and indent it in line with the if above it (Outside it)

devs can close this issue if the solution seems right

IT works fine.....Thanks a LOT

@buddhaspake
Copy link

buddhaspake commented Jul 27, 2020

I fixed my problem by putting this command into terminal: conda update anaconda-navigator

This seems to be the better solution, since the error is clearly a bug. In the updated version, the devs have fixed it (and maybe other things which we did not encounter at first run). 'conda update' worked seamlessly for me too. I am sceptical about editing code without understanding the final consequences. the DISTRO_NAME var might also be a global which was not populated due to factors other than the missing declaration.

@HananeMeftahi0
Copy link

HananeMeftahi0 commented Aug 4, 2020

Thanks a lot @AnmolMajithia

@diegomc365
Copy link

diegomc365 commented Aug 10, 2020

I had to add "DISTRO_NAME = None" in line 159 of the vscode.py file:

Editing the file: .../anaconda3/lib/python3.8/site-packages/anaconda_navigator/api/external_apps/vscode.py"

154|    def _find_linux_install_dir(self):
155|        INST_DIR = None
156|        exe = os.path.join('/snap', 'bin', 'code')
157|        if os.path.lexists(exe):
158|            INST_DIR = '/snap'
159|        DISTRO_NAME = None
160|        for distro in self.distro_map.keys():
161|            _distro_regex = ".*{}/([^ ]*)".format(distro)
162|            m = re.match(_distro_regex, self._conda_api.user_agent)
163|            if m:
164|                DISTRO_NAME = distro
165|                DISTRO_VER = m.group(1)
166|                break

Good luck to you all!

@HITlittlefox
Copy link

HITlittlefox commented Sep 2, 2020

I too had the same error:

UnboundLocalError: local variable 'DISTRO_NAME' referenced before assignment

from a new Anaconda3-2020.02-Linux-x86_64 installation on Linux Mint 19.02 which got solved with the tips from @AnmolMajithia

Thanks a lot !
Here's the new line I added (with comments ## ... on the right)--

def _application_data(self):
"""Get app data from microsoft rest api."""
data = {}
url = (
'https://update.code.visualstudio.com/api/update'
'/{}/stable/version'.format(self._SUBDIR)
)
if url:
data = self._download_api.get_url(
url=url,
as_json=True,
non_blocking=False,
)
return data

def _find_linux_install_dir(self):
    INST_DIR = None
    exe = os.path.join('/snap', 'bin', 'code')
    if os.path.lexists(exe):
        INST_DIR = '/snap'
    DISTRO_NAME = None                               **##add this module in the script**
    for distro in self.distro_map.keys():
        _distro_regex = ".*{}/([^ ]*)".format(distro)
        m = re.match(_distro_regex, self._conda_api.user_agent)
        if m:
            DISTRO_NAME = distro
            DISTRO_VER = m.group(1)
            break

    if DISTRO_NAME in ['ubuntu', 'debian']:
        _pkg_type = 'deb'
    else:
        _pkg_type = 'rpm'

    _os_arch = 'x64' if OS_64_BIT else 'ia32'
    SUBDIR = 'linux-{}-{}'.format(_pkg_type, _os_arch)
    INST_EXT = _pkg_type
    if not INST_DIR:
        INST_DIR = '/usr/share/{}'.format(self.filename)

    return SUBDIR, INST_EXT, INST_DIR

I try it in Manjaro of linux which tell me the same problem. It works very well. Thank you very much!

@Agab22
Copy link

Agab22 commented Oct 8, 2020

I changed DISTRO_NAME = None or ubuntu
and also changed it to DISTRO_NAME = ' '
but still got the same error

@marfotony
Copy link

marfotony commented Oct 10, 2020

Edit:
Another much simpler solution is just entering the command in the terminal:

conda update anaconda-navigator

Solved It By:
Editing the file : ".../anaconda3//lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py"

By declaring the variable outside the loop.

Just add the line :

DISTRO_NAME = None

on Line 159 and indent it in line with the if above it (Outside it)

devs can close this issue if the solution seems right

This worked perfectly for me. Thanks a mill

@AnwarKamel
Copy link

AnwarKamel commented Apr 28, 2021

go to path /anaconda3//lib/python3.7/site-packages/anaconda_navigator/api/external_apps/vscode.py
and edit file vscode.py
add this line
DISTRO_NAME = None
in the function named : def _find_linux_install_dir
like this:

def _find_linux_install_dir(self):
        INST_DIR = None
        exe = os.path.join('/snap', 'bin', 'code')
        if os.path.lexists(exe):
            INST_DIR = '/snap'
        DISTRO_NAME = None

        for distro in self.distro_map.keys():
            _distro_regex = ".*{}/([^ ]*)".format(distro)
            m = re.match(_distro_regex, self._conda_api.user_agent)
            if m:
                DISTRO_NAME = distro
                DISTRO_VER = m.group(1)
                break

        if DISTRO_NAME in ['ubuntu', 'debian']:
            _pkg_type = 'deb'
        else:
            _pkg_type = 'rpm'

        _os_arch = 'x64' if OS_64_BIT else 'ia32'
        SUBDIR = 'linux-{}-{}'.format(_pkg_type, _os_arch)
        INST_EXT = _pkg_type
        if not INST_DIR:
            INST_DIR = '/usr/share/{}'.format(self.filename)

        return SUBDIR, INST_EXT, INST_DIR

@gabrieltovarj
Copy link

gabrieltovarj commented Jun 18, 2021

I too had the same error:
UnboundLocalError: local variable 'DISTRO_NAME' referenced before assignment
from a new Anaconda3-2020.02-Linux-x86_64 installation on Linux Mint 19 which got solved with the tips from @AnmolMajithia

Thanks a lot !
Here's the new line I added (with comments ## ... on the right)--

        ...

    def _find_linux_install_dir(self):
        INST_DIR = None
        exe = os.path.join('/snap', 'bin', 'code')
        if os.path.lexists(exe):
            INST_DIR = '/snap'

        DISTRO_NAME = None     ##  Adding this line... takes care of the bug in my case
        for distro in self.distro_map.keys():
            _distro_regex = ".*{}/([^ ]*)".format(distro)
            m = re.match(_distro_regex, self._conda_api.user_agent)
            if m:
                DISTRO_NAME = distro
                DISTRO_VER = m.group(1)
                break

        if DISTRO_NAME in ['ubuntu', 'debian']:
            _pkg_type = 'deb'
        else:
            _pkg_type = 'rpm'

        ...

This work for me!! Thanks!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests