anaconda / anaconda-project

Tool for encapsulating, running, and reproducing data science projects
https://anaconda-project.readthedocs.io/en/latest/
Other
217 stars 88 forks source link

[BUG] wsl2 environment variables not showing up after setting #318

Open saguerraty opened 3 years ago

saguerraty commented 3 years ago

Not 100% sure if this is a bug or a feature request :)

I'm having an issue with setting and using environment variables within a wsl2 Ubuntu 20.0 distro using jupyter and VS code

I have tried:

But none of these solutions have solved the issue

ALL software version info

(anaconda-project version, conda version, etc.)

 active environment : OR_local
    active env location : /home/saguerraty/.conda/envs/OR_local
            shell level : 2
       user config file : /home/saguerraty/.condarc
 populated config files : /home/saguerraty/.condarc
          conda version : 4.9.2
    conda-build version : not installed
         python version : 3.8.5.final.0
       virtual packages : __glibc=2.31=0
                          __unix=0=0
                          __archspec=1=x86_64
       base environment : /opt/conda  (read only)
           channel URLs : http://conda.anaconda.org/gurobi/linux-64
                          http://conda.anaconda.org/gurobi/noarch
                          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 : /opt/conda/pkgs
                          /home/saguerraty/.conda/pkgs
       envs directories : /home/saguerraty/.conda/envs
                          /opt/conda/envs
               platform : linux-64
             user-agent : conda/4.9.2 requests/2.25.1 CPython/3.8.5 Linux/5.4.72-microsoft-standard-WSL2 ubuntu/20.04.2 glibc/2.31
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False

Description of expected behavior and the observed behavior

I added an environment variable using the following method (assuming a Linux OS) within the wsl2 ubuntu 20.0 terminal. The variable saves the path for my data location as a string for later use in python, I use the exact same method on a mac and works perfectly. When trying to access the variable it is not shown within a jupyter notebook

Relevant configuration files

-> activate.d/env_vars.sh file:

#!/bin/sh

#env variables 
export VAR_NAME='/mnt/c/Users/user_name/folder 1/folder 2'

-> deactivate.d/env_vars.sh file:

#!/bin/sh

#drive local location
unset VAR_NAME

Complete, minimal, self-contained example code that reproduces the issue

# list of commands you executed
import os

os.environ['VAR_NAME']

Expected output: '/mnt/c/Users/user_name/folder 1/folder 2' Obtained output: getting the variable raises a KeyError

Command output and/or screenshots of the bug in action

KeyError                                  Traceback (most recent call last)
<ipython-input-15-c94ae94a62ef> in <module>
----> 1 os.environ['VAR_NAME']

~/.conda/envs/OR_local/lib/python3.8/os.py in __getitem__(self, key)
    673         except KeyError:
    674             # raise KeyError with the original key value
--> 675             raise KeyError(key) from None
    676         return self.decodevalue(value)
    677 

KeyError: 'VAR_NAME'
AlbertDeFusco commented 3 years ago

It looks like you are not using anaconda-project, but this looks like an issue with Conda. Have you filed an issue there?

https://github.com/conda/conda

saguerraty commented 3 years ago

My bad, I'll open this issue there :) Thanks for the reply! :D