Setting environment variables in Google Colab










2















I'm trying to use the Kaggle CLI API, and in order to do that, instead of using kaggle.json for authentication, I'm using environment variables to set the credentials.



!pip install --upgrade kaggle

!export KAGGLE_USERNAME=abcdefgh
!export KAGGLE_KEY=abcdefgh

!export -p


However, the printed list of env. variables doesn't contain the ones I set above.



declare -x CLICOLOR="1"
declare -x CLOUDSDK_CONFIG="/content/.config"
declare -x COLAB_GPU="1"
declare -x CUDA_PKG_VERSION="9-2=9.2.148-1"
declare -x CUDA_VERSION="9.2.148"
declare -x CUDNN_VERSION="7.4.1.5"
declare -x DATALAB_SETTINGS_OVERRIDES=""kernelManagerProxyPort":6000,"kernelManagerProxyHost":"172.28.0.3","jupyterArgs":["notebook","-y","--no-browser","--log-level=DEBUG","--debug","--NotebookApp.allow_origin=\"*\"","--NotebookApp.log_format=\"%(message)s\"","--NotebookApp.disable_check_xsrf=True","--NotebookApp.token=","--Session.key=\"\"","--Session.keyfile=\"\"","--ContentsManager.untitled_directory=\"Untitled Folder\"","--ContentsManager.untitled_file=\"Untitled File\"","--ContentsManager.untitled_notebook=\"Untitled Notebook\"","--KernelManager.autorestart=True","--ip=\"172.28.0.2\""]"
declare -x DEBIAN_FRONTEND="noninteractive"
declare -x ENV="/root/.bashrc"
declare -x GIT_PAGER="cat"
declare -x GLIBCPP_FORCE_NEW="1"
declare -x GLIBCXX_FORCE_NEW="1"
declare -x HOME="/root"
declare -x HOSTNAME="2ced809e9844"
declare -x JPY_PARENT_PID="57"
declare -x LANG="en_US.UTF-8"
declare -x LD_LIBRARY_PATH="/usr/lib64-nvidia"
declare -x LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4"
declare -x MPLBACKEND="module://ipykernel.pylab.backend_inline"
declare -x NCCL_VERSION="2.3.7"
declare -x NVIDIA_DRIVER_CAPABILITIES="compute,utility"
declare -x NVIDIA_REQUIRE_CUDA="cuda>=9.2"
declare -x NVIDIA_VISIBLE_DEVICES="all"
declare -x OLDPWD="/"
declare -x PAGER="cat"
declare -x PATH="/usr/local/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/opt/bin"
declare -x PWD="/content"
declare -x PYTHONPATH="/env/python"
declare -x SHELL="/bin/bash"
declare -x SHLVL="2"
declare -x TERM="xterm-color"
declare -x TF_FORCE_GPU_ALLOW_GROWTH="true"
declare -x _="/tools/node/bin/forever"
declare -x __EGL_VENDOR_LIBRARY_DIRS="/usr/lib64-nvidia:/usr/share/glvnd/egl_vendor.d/"









share|improve this question
























  • Possible duplicate of Is it possible to set environment variables in Google Colaboratory?

    – yellow01
    Nov 16 '18 at 19:03















2















I'm trying to use the Kaggle CLI API, and in order to do that, instead of using kaggle.json for authentication, I'm using environment variables to set the credentials.



!pip install --upgrade kaggle

!export KAGGLE_USERNAME=abcdefgh
!export KAGGLE_KEY=abcdefgh

!export -p


However, the printed list of env. variables doesn't contain the ones I set above.



declare -x CLICOLOR="1"
declare -x CLOUDSDK_CONFIG="/content/.config"
declare -x COLAB_GPU="1"
declare -x CUDA_PKG_VERSION="9-2=9.2.148-1"
declare -x CUDA_VERSION="9.2.148"
declare -x CUDNN_VERSION="7.4.1.5"
declare -x DATALAB_SETTINGS_OVERRIDES=""kernelManagerProxyPort":6000,"kernelManagerProxyHost":"172.28.0.3","jupyterArgs":["notebook","-y","--no-browser","--log-level=DEBUG","--debug","--NotebookApp.allow_origin=\"*\"","--NotebookApp.log_format=\"%(message)s\"","--NotebookApp.disable_check_xsrf=True","--NotebookApp.token=","--Session.key=\"\"","--Session.keyfile=\"\"","--ContentsManager.untitled_directory=\"Untitled Folder\"","--ContentsManager.untitled_file=\"Untitled File\"","--ContentsManager.untitled_notebook=\"Untitled Notebook\"","--KernelManager.autorestart=True","--ip=\"172.28.0.2\""]"
declare -x DEBIAN_FRONTEND="noninteractive"
declare -x ENV="/root/.bashrc"
declare -x GIT_PAGER="cat"
declare -x GLIBCPP_FORCE_NEW="1"
declare -x GLIBCXX_FORCE_NEW="1"
declare -x HOME="/root"
declare -x HOSTNAME="2ced809e9844"
declare -x JPY_PARENT_PID="57"
declare -x LANG="en_US.UTF-8"
declare -x LD_LIBRARY_PATH="/usr/lib64-nvidia"
declare -x LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4"
declare -x MPLBACKEND="module://ipykernel.pylab.backend_inline"
declare -x NCCL_VERSION="2.3.7"
declare -x NVIDIA_DRIVER_CAPABILITIES="compute,utility"
declare -x NVIDIA_REQUIRE_CUDA="cuda>=9.2"
declare -x NVIDIA_VISIBLE_DEVICES="all"
declare -x OLDPWD="/"
declare -x PAGER="cat"
declare -x PATH="/usr/local/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/opt/bin"
declare -x PWD="/content"
declare -x PYTHONPATH="/env/python"
declare -x SHELL="/bin/bash"
declare -x SHLVL="2"
declare -x TERM="xterm-color"
declare -x TF_FORCE_GPU_ALLOW_GROWTH="true"
declare -x _="/tools/node/bin/forever"
declare -x __EGL_VENDOR_LIBRARY_DIRS="/usr/lib64-nvidia:/usr/share/glvnd/egl_vendor.d/"









share|improve this question
























  • Possible duplicate of Is it possible to set environment variables in Google Colaboratory?

    – yellow01
    Nov 16 '18 at 19:03













2












2








2








I'm trying to use the Kaggle CLI API, and in order to do that, instead of using kaggle.json for authentication, I'm using environment variables to set the credentials.



!pip install --upgrade kaggle

!export KAGGLE_USERNAME=abcdefgh
!export KAGGLE_KEY=abcdefgh

!export -p


However, the printed list of env. variables doesn't contain the ones I set above.



declare -x CLICOLOR="1"
declare -x CLOUDSDK_CONFIG="/content/.config"
declare -x COLAB_GPU="1"
declare -x CUDA_PKG_VERSION="9-2=9.2.148-1"
declare -x CUDA_VERSION="9.2.148"
declare -x CUDNN_VERSION="7.4.1.5"
declare -x DATALAB_SETTINGS_OVERRIDES=""kernelManagerProxyPort":6000,"kernelManagerProxyHost":"172.28.0.3","jupyterArgs":["notebook","-y","--no-browser","--log-level=DEBUG","--debug","--NotebookApp.allow_origin=\"*\"","--NotebookApp.log_format=\"%(message)s\"","--NotebookApp.disable_check_xsrf=True","--NotebookApp.token=","--Session.key=\"\"","--Session.keyfile=\"\"","--ContentsManager.untitled_directory=\"Untitled Folder\"","--ContentsManager.untitled_file=\"Untitled File\"","--ContentsManager.untitled_notebook=\"Untitled Notebook\"","--KernelManager.autorestart=True","--ip=\"172.28.0.2\""]"
declare -x DEBIAN_FRONTEND="noninteractive"
declare -x ENV="/root/.bashrc"
declare -x GIT_PAGER="cat"
declare -x GLIBCPP_FORCE_NEW="1"
declare -x GLIBCXX_FORCE_NEW="1"
declare -x HOME="/root"
declare -x HOSTNAME="2ced809e9844"
declare -x JPY_PARENT_PID="57"
declare -x LANG="en_US.UTF-8"
declare -x LD_LIBRARY_PATH="/usr/lib64-nvidia"
declare -x LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4"
declare -x MPLBACKEND="module://ipykernel.pylab.backend_inline"
declare -x NCCL_VERSION="2.3.7"
declare -x NVIDIA_DRIVER_CAPABILITIES="compute,utility"
declare -x NVIDIA_REQUIRE_CUDA="cuda>=9.2"
declare -x NVIDIA_VISIBLE_DEVICES="all"
declare -x OLDPWD="/"
declare -x PAGER="cat"
declare -x PATH="/usr/local/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/opt/bin"
declare -x PWD="/content"
declare -x PYTHONPATH="/env/python"
declare -x SHELL="/bin/bash"
declare -x SHLVL="2"
declare -x TERM="xterm-color"
declare -x TF_FORCE_GPU_ALLOW_GROWTH="true"
declare -x _="/tools/node/bin/forever"
declare -x __EGL_VENDOR_LIBRARY_DIRS="/usr/lib64-nvidia:/usr/share/glvnd/egl_vendor.d/"









share|improve this question
















I'm trying to use the Kaggle CLI API, and in order to do that, instead of using kaggle.json for authentication, I'm using environment variables to set the credentials.



!pip install --upgrade kaggle

!export KAGGLE_USERNAME=abcdefgh
!export KAGGLE_KEY=abcdefgh

!export -p


However, the printed list of env. variables doesn't contain the ones I set above.



declare -x CLICOLOR="1"
declare -x CLOUDSDK_CONFIG="/content/.config"
declare -x COLAB_GPU="1"
declare -x CUDA_PKG_VERSION="9-2=9.2.148-1"
declare -x CUDA_VERSION="9.2.148"
declare -x CUDNN_VERSION="7.4.1.5"
declare -x DATALAB_SETTINGS_OVERRIDES=""kernelManagerProxyPort":6000,"kernelManagerProxyHost":"172.28.0.3","jupyterArgs":["notebook","-y","--no-browser","--log-level=DEBUG","--debug","--NotebookApp.allow_origin=\"*\"","--NotebookApp.log_format=\"%(message)s\"","--NotebookApp.disable_check_xsrf=True","--NotebookApp.token=","--Session.key=\"\"","--Session.keyfile=\"\"","--ContentsManager.untitled_directory=\"Untitled Folder\"","--ContentsManager.untitled_file=\"Untitled File\"","--ContentsManager.untitled_notebook=\"Untitled Notebook\"","--KernelManager.autorestart=True","--ip=\"172.28.0.2\""]"
declare -x DEBIAN_FRONTEND="noninteractive"
declare -x ENV="/root/.bashrc"
declare -x GIT_PAGER="cat"
declare -x GLIBCPP_FORCE_NEW="1"
declare -x GLIBCXX_FORCE_NEW="1"
declare -x HOME="/root"
declare -x HOSTNAME="2ced809e9844"
declare -x JPY_PARENT_PID="57"
declare -x LANG="en_US.UTF-8"
declare -x LD_LIBRARY_PATH="/usr/lib64-nvidia"
declare -x LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4"
declare -x MPLBACKEND="module://ipykernel.pylab.backend_inline"
declare -x NCCL_VERSION="2.3.7"
declare -x NVIDIA_DRIVER_CAPABILITIES="compute,utility"
declare -x NVIDIA_REQUIRE_CUDA="cuda>=9.2"
declare -x NVIDIA_VISIBLE_DEVICES="all"
declare -x OLDPWD="/"
declare -x PAGER="cat"
declare -x PATH="/usr/local/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/opt/bin"
declare -x PWD="/content"
declare -x PYTHONPATH="/env/python"
declare -x SHELL="/bin/bash"
declare -x SHLVL="2"
declare -x TERM="xterm-color"
declare -x TF_FORCE_GPU_ALLOW_GROWTH="true"
declare -x _="/tools/node/bin/forever"
declare -x __EGL_VENDOR_LIBRARY_DIRS="/usr/lib64-nvidia:/usr/share/glvnd/egl_vendor.d/"






google-colaboratory kaggle






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 18:11









Bob Smith

7,60032130




7,60032130










asked Nov 14 '18 at 17:53









Arpit GogiaArpit Gogia

132




132












  • Possible duplicate of Is it possible to set environment variables in Google Colaboratory?

    – yellow01
    Nov 16 '18 at 19:03

















  • Possible duplicate of Is it possible to set environment variables in Google Colaboratory?

    – yellow01
    Nov 16 '18 at 19:03
















Possible duplicate of Is it possible to set environment variables in Google Colaboratory?

– yellow01
Nov 16 '18 at 19:03





Possible duplicate of Is it possible to set environment variables in Google Colaboratory?

– yellow01
Nov 16 '18 at 19:03












2 Answers
2






active

oldest

votes


















2














I think you want to do something like:



import os
os.environ['KAGGLE_USERNAME'] = ...
os.environ['KAGGLE_KEY'] = ...


The reason is that !export will assign the environment variable in an ephemeral sub-shell. But, you want to update the environment for the Python subprocess that spawns those sub-shells.



enter image description here






share|improve this answer























  • Thanks! This worked. +1 for the explanation too!

    – Arpit Gogia
    Nov 14 '18 at 19:01


















1














If you like %magic, you can also use %env to make it a bit shorter.



%env KAGGLE_USERNAME=abcdefgh


If the value is in a variable you can also use



%env KAGGLE_USERNAME=$username





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306150%2fsetting-environment-variables-in-google-colab%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    I think you want to do something like:



    import os
    os.environ['KAGGLE_USERNAME'] = ...
    os.environ['KAGGLE_KEY'] = ...


    The reason is that !export will assign the environment variable in an ephemeral sub-shell. But, you want to update the environment for the Python subprocess that spawns those sub-shells.



    enter image description here






    share|improve this answer























    • Thanks! This worked. +1 for the explanation too!

      – Arpit Gogia
      Nov 14 '18 at 19:01















    2














    I think you want to do something like:



    import os
    os.environ['KAGGLE_USERNAME'] = ...
    os.environ['KAGGLE_KEY'] = ...


    The reason is that !export will assign the environment variable in an ephemeral sub-shell. But, you want to update the environment for the Python subprocess that spawns those sub-shells.



    enter image description here






    share|improve this answer























    • Thanks! This worked. +1 for the explanation too!

      – Arpit Gogia
      Nov 14 '18 at 19:01













    2












    2








    2







    I think you want to do something like:



    import os
    os.environ['KAGGLE_USERNAME'] = ...
    os.environ['KAGGLE_KEY'] = ...


    The reason is that !export will assign the environment variable in an ephemeral sub-shell. But, you want to update the environment for the Python subprocess that spawns those sub-shells.



    enter image description here






    share|improve this answer













    I think you want to do something like:



    import os
    os.environ['KAGGLE_USERNAME'] = ...
    os.environ['KAGGLE_KEY'] = ...


    The reason is that !export will assign the environment variable in an ephemeral sub-shell. But, you want to update the environment for the Python subprocess that spawns those sub-shells.



    enter image description here







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 14 '18 at 18:15









    Bob SmithBob Smith

    7,60032130




    7,60032130












    • Thanks! This worked. +1 for the explanation too!

      – Arpit Gogia
      Nov 14 '18 at 19:01

















    • Thanks! This worked. +1 for the explanation too!

      – Arpit Gogia
      Nov 14 '18 at 19:01
















    Thanks! This worked. +1 for the explanation too!

    – Arpit Gogia
    Nov 14 '18 at 19:01





    Thanks! This worked. +1 for the explanation too!

    – Arpit Gogia
    Nov 14 '18 at 19:01













    1














    If you like %magic, you can also use %env to make it a bit shorter.



    %env KAGGLE_USERNAME=abcdefgh


    If the value is in a variable you can also use



    %env KAGGLE_USERNAME=$username





    share|improve this answer



























      1














      If you like %magic, you can also use %env to make it a bit shorter.



      %env KAGGLE_USERNAME=abcdefgh


      If the value is in a variable you can also use



      %env KAGGLE_USERNAME=$username





      share|improve this answer

























        1












        1








        1







        If you like %magic, you can also use %env to make it a bit shorter.



        %env KAGGLE_USERNAME=abcdefgh


        If the value is in a variable you can also use



        %env KAGGLE_USERNAME=$username





        share|improve this answer













        If you like %magic, you can also use %env to make it a bit shorter.



        %env KAGGLE_USERNAME=abcdefgh


        If the value is in a variable you can also use



        %env KAGGLE_USERNAME=$username






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 3:00









        Korakot ChaovavanichKorakot Chaovavanich

        3,32621436




        3,32621436



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306150%2fsetting-environment-variables-in-google-colab%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto