Confusing behavior of bash cell magics in Jupyter Notebook (Windows 10, Git Bash)





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm getting odd behavior when trying to use bash cell magics in Jupyter Notebooks on Windows 10, with Git Bash installed.



Cell magics seem to work fine for some bash programs (e.g. which, echo), but not others (e.g. head).



Use of a ! in lieu of bash cell magics works for some commands, but not others. This inconsistency kills notebook compatibility across different operating systems.



Does anyone have any insight into what's happening here?



Here are some examples:



Input:



%%bash
which bash


Output:



/bin/bash


Input:



!which bash


Output:



'which' is not recognized as an internal or external command, operable program or batch file.


Input:



%%bash
head file.csv


Output:



Input:



!head file.csv


Output:



Row,Column,*Target Name,*Sample Name


Input:



%%bash
echo pizza


Output:



pizza


Input:



!echo pizza


Output:



pizza









share|improve this question























  • I have a somewhat similar problem, did you ever get the to the bottom of this? stackoverflow.com/questions/51548928/…

    – quantum285
    Jul 26 '18 at 23:48











  • Nope! No progress. Admittedly, it's low priority, as the problem is being experienced by some undergrads in our lab. We've just made them switch to using lab computers running Ubuntu instead of their personal Windows laptops.

    – kubu4
    Jul 28 '18 at 4:26











  • I found that '!' uses the default windows shell whereas '%%bash' uses bash. So a workaround is to use '%%cmd' to use all of the commands you can use with '!' but then you face the problems that arise due to the difference between bash and batch. I've also taken the approach of using Ubuntu VMs also. Not sure if anything I said helps at all but just sharing..

    – quantum285
    Jul 29 '18 at 0:04











  • You say Git Bash is installed, but is Jupyter Notebook being launched from Git Bash or from another prompt, e.g., Anaconda?

    – Karl Baker
    Jan 4 at 7:34











  • Launching via Git Bash. Thanks for clarifying that point!

    – kubu4
    Jan 5 at 21:49


















0















I'm getting odd behavior when trying to use bash cell magics in Jupyter Notebooks on Windows 10, with Git Bash installed.



Cell magics seem to work fine for some bash programs (e.g. which, echo), but not others (e.g. head).



Use of a ! in lieu of bash cell magics works for some commands, but not others. This inconsistency kills notebook compatibility across different operating systems.



Does anyone have any insight into what's happening here?



Here are some examples:



Input:



%%bash
which bash


Output:



/bin/bash


Input:



!which bash


Output:



'which' is not recognized as an internal or external command, operable program or batch file.


Input:



%%bash
head file.csv


Output:



Input:



!head file.csv


Output:



Row,Column,*Target Name,*Sample Name


Input:



%%bash
echo pizza


Output:



pizza


Input:



!echo pizza


Output:



pizza









share|improve this question























  • I have a somewhat similar problem, did you ever get the to the bottom of this? stackoverflow.com/questions/51548928/…

    – quantum285
    Jul 26 '18 at 23:48











  • Nope! No progress. Admittedly, it's low priority, as the problem is being experienced by some undergrads in our lab. We've just made them switch to using lab computers running Ubuntu instead of their personal Windows laptops.

    – kubu4
    Jul 28 '18 at 4:26











  • I found that '!' uses the default windows shell whereas '%%bash' uses bash. So a workaround is to use '%%cmd' to use all of the commands you can use with '!' but then you face the problems that arise due to the difference between bash and batch. I've also taken the approach of using Ubuntu VMs also. Not sure if anything I said helps at all but just sharing..

    – quantum285
    Jul 29 '18 at 0:04











  • You say Git Bash is installed, but is Jupyter Notebook being launched from Git Bash or from another prompt, e.g., Anaconda?

    – Karl Baker
    Jan 4 at 7:34











  • Launching via Git Bash. Thanks for clarifying that point!

    – kubu4
    Jan 5 at 21:49














0












0








0








I'm getting odd behavior when trying to use bash cell magics in Jupyter Notebooks on Windows 10, with Git Bash installed.



Cell magics seem to work fine for some bash programs (e.g. which, echo), but not others (e.g. head).



Use of a ! in lieu of bash cell magics works for some commands, but not others. This inconsistency kills notebook compatibility across different operating systems.



Does anyone have any insight into what's happening here?



Here are some examples:



Input:



%%bash
which bash


Output:



/bin/bash


Input:



!which bash


Output:



'which' is not recognized as an internal or external command, operable program or batch file.


Input:



%%bash
head file.csv


Output:



Input:



!head file.csv


Output:



Row,Column,*Target Name,*Sample Name


Input:



%%bash
echo pizza


Output:



pizza


Input:



!echo pizza


Output:



pizza









share|improve this question














I'm getting odd behavior when trying to use bash cell magics in Jupyter Notebooks on Windows 10, with Git Bash installed.



Cell magics seem to work fine for some bash programs (e.g. which, echo), but not others (e.g. head).



Use of a ! in lieu of bash cell magics works for some commands, but not others. This inconsistency kills notebook compatibility across different operating systems.



Does anyone have any insight into what's happening here?



Here are some examples:



Input:



%%bash
which bash


Output:



/bin/bash


Input:



!which bash


Output:



'which' is not recognized as an internal or external command, operable program or batch file.


Input:



%%bash
head file.csv


Output:



Input:



!head file.csv


Output:



Row,Column,*Target Name,*Sample Name


Input:



%%bash
echo pizza


Output:



pizza


Input:



!echo pizza


Output:



pizza






jupyter-notebook git-bash






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Aug 9 '17 at 14:44









kubu4kubu4

688




688













  • I have a somewhat similar problem, did you ever get the to the bottom of this? stackoverflow.com/questions/51548928/…

    – quantum285
    Jul 26 '18 at 23:48











  • Nope! No progress. Admittedly, it's low priority, as the problem is being experienced by some undergrads in our lab. We've just made them switch to using lab computers running Ubuntu instead of their personal Windows laptops.

    – kubu4
    Jul 28 '18 at 4:26











  • I found that '!' uses the default windows shell whereas '%%bash' uses bash. So a workaround is to use '%%cmd' to use all of the commands you can use with '!' but then you face the problems that arise due to the difference between bash and batch. I've also taken the approach of using Ubuntu VMs also. Not sure if anything I said helps at all but just sharing..

    – quantum285
    Jul 29 '18 at 0:04











  • You say Git Bash is installed, but is Jupyter Notebook being launched from Git Bash or from another prompt, e.g., Anaconda?

    – Karl Baker
    Jan 4 at 7:34











  • Launching via Git Bash. Thanks for clarifying that point!

    – kubu4
    Jan 5 at 21:49



















  • I have a somewhat similar problem, did you ever get the to the bottom of this? stackoverflow.com/questions/51548928/…

    – quantum285
    Jul 26 '18 at 23:48











  • Nope! No progress. Admittedly, it's low priority, as the problem is being experienced by some undergrads in our lab. We've just made them switch to using lab computers running Ubuntu instead of their personal Windows laptops.

    – kubu4
    Jul 28 '18 at 4:26











  • I found that '!' uses the default windows shell whereas '%%bash' uses bash. So a workaround is to use '%%cmd' to use all of the commands you can use with '!' but then you face the problems that arise due to the difference between bash and batch. I've also taken the approach of using Ubuntu VMs also. Not sure if anything I said helps at all but just sharing..

    – quantum285
    Jul 29 '18 at 0:04











  • You say Git Bash is installed, but is Jupyter Notebook being launched from Git Bash or from another prompt, e.g., Anaconda?

    – Karl Baker
    Jan 4 at 7:34











  • Launching via Git Bash. Thanks for clarifying that point!

    – kubu4
    Jan 5 at 21:49

















I have a somewhat similar problem, did you ever get the to the bottom of this? stackoverflow.com/questions/51548928/…

– quantum285
Jul 26 '18 at 23:48





I have a somewhat similar problem, did you ever get the to the bottom of this? stackoverflow.com/questions/51548928/…

– quantum285
Jul 26 '18 at 23:48













Nope! No progress. Admittedly, it's low priority, as the problem is being experienced by some undergrads in our lab. We've just made them switch to using lab computers running Ubuntu instead of their personal Windows laptops.

– kubu4
Jul 28 '18 at 4:26





Nope! No progress. Admittedly, it's low priority, as the problem is being experienced by some undergrads in our lab. We've just made them switch to using lab computers running Ubuntu instead of their personal Windows laptops.

– kubu4
Jul 28 '18 at 4:26













I found that '!' uses the default windows shell whereas '%%bash' uses bash. So a workaround is to use '%%cmd' to use all of the commands you can use with '!' but then you face the problems that arise due to the difference between bash and batch. I've also taken the approach of using Ubuntu VMs also. Not sure if anything I said helps at all but just sharing..

– quantum285
Jul 29 '18 at 0:04





I found that '!' uses the default windows shell whereas '%%bash' uses bash. So a workaround is to use '%%cmd' to use all of the commands you can use with '!' but then you face the problems that arise due to the difference between bash and batch. I've also taken the approach of using Ubuntu VMs also. Not sure if anything I said helps at all but just sharing..

– quantum285
Jul 29 '18 at 0:04













You say Git Bash is installed, but is Jupyter Notebook being launched from Git Bash or from another prompt, e.g., Anaconda?

– Karl Baker
Jan 4 at 7:34





You say Git Bash is installed, but is Jupyter Notebook being launched from Git Bash or from another prompt, e.g., Anaconda?

– Karl Baker
Jan 4 at 7:34













Launching via Git Bash. Thanks for clarifying that point!

– kubu4
Jan 5 at 21:49





Launching via Git Bash. Thanks for clarifying that point!

– kubu4
Jan 5 at 21:49












1 Answer
1






active

oldest

votes


















0














In my experience, as long as Jupyter is launched from a bash-compliant command line such as Git Bash (MingW64) or possibly Ubuntu on Windows, bash commands prepended with ! work in Jupyter Notebook, even on Windows systems.



I'm running windows 10 Pro with Python installed via Anaconda, and bash works when I launch Jupyter via Git Bash, but does not when I launch from the Anaconda prompt. For example:



>>> !ls
database.sqlite
Weather Data Clustering using k-Means.ipynb

>>>!pip show lxml | grep Version
Version: 4.1.0





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%2f45593910%2fconfusing-behavior-of-bash-cell-magics-in-jupyter-notebook-windows-10-git-bash%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    In my experience, as long as Jupyter is launched from a bash-compliant command line such as Git Bash (MingW64) or possibly Ubuntu on Windows, bash commands prepended with ! work in Jupyter Notebook, even on Windows systems.



    I'm running windows 10 Pro with Python installed via Anaconda, and bash works when I launch Jupyter via Git Bash, but does not when I launch from the Anaconda prompt. For example:



    >>> !ls
    database.sqlite
    Weather Data Clustering using k-Means.ipynb

    >>>!pip show lxml | grep Version
    Version: 4.1.0





    share|improve this answer




























      0














      In my experience, as long as Jupyter is launched from a bash-compliant command line such as Git Bash (MingW64) or possibly Ubuntu on Windows, bash commands prepended with ! work in Jupyter Notebook, even on Windows systems.



      I'm running windows 10 Pro with Python installed via Anaconda, and bash works when I launch Jupyter via Git Bash, but does not when I launch from the Anaconda prompt. For example:



      >>> !ls
      database.sqlite
      Weather Data Clustering using k-Means.ipynb

      >>>!pip show lxml | grep Version
      Version: 4.1.0





      share|improve this answer


























        0












        0








        0







        In my experience, as long as Jupyter is launched from a bash-compliant command line such as Git Bash (MingW64) or possibly Ubuntu on Windows, bash commands prepended with ! work in Jupyter Notebook, even on Windows systems.



        I'm running windows 10 Pro with Python installed via Anaconda, and bash works when I launch Jupyter via Git Bash, but does not when I launch from the Anaconda prompt. For example:



        >>> !ls
        database.sqlite
        Weather Data Clustering using k-Means.ipynb

        >>>!pip show lxml | grep Version
        Version: 4.1.0





        share|improve this answer













        In my experience, as long as Jupyter is launched from a bash-compliant command line such as Git Bash (MingW64) or possibly Ubuntu on Windows, bash commands prepended with ! work in Jupyter Notebook, even on Windows systems.



        I'm running windows 10 Pro with Python installed via Anaconda, and bash works when I launch Jupyter via Git Bash, but does not when I launch from the Anaconda prompt. For example:



        >>> !ls
        database.sqlite
        Weather Data Clustering using k-Means.ipynb

        >>>!pip show lxml | grep Version
        Version: 4.1.0






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 4 at 7:45









        Karl BakerKarl Baker

        366115




        366115
































            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%2f45593910%2fconfusing-behavior-of-bash-cell-magics-in-jupyter-notebook-windows-10-git-bash%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







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas