Running python script on ubuntu machine using ./myscript.py

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
3
down vote

favorite












I am running a python script named myscript.py on ubuntu machine. I usually use python command to run python scripts as below.



python main.py


Recently, I downloaded a python script from a Github repository ( if need to look into the repository can find it at https://github.com/gsrivas4/mnist-gan) which asks to run script using './' as below.



./main.py


Running python scripts second way is new to me. I am confused about when can we use './' to run scripts and is this method to run scripts used for other languages as well. Usually, I would expect name of binary such as python which will start a process before I add the name of script. This script will be fed to the process. Also, I want to understand what is the meaning of './' when we run scripts. I feel this is trivial question, but could not find much help online.



I also tried making one of my python file executable and then ran it. However, running it using ./ gave me errors for any python library import commands.







share|improve this question





















  • Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
    – Jesse_b
    Apr 28 at 20:12











  • @Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
    – GAURAV SRIVASTAVA
    Apr 28 at 20:13










  • Does the python script you are getting errors with have a hashbang pointing to python?
    – Jesse_b
    Apr 28 at 20:14










  • @Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
    – GAURAV SRIVASTAVA
    Apr 28 at 20:19














up vote
3
down vote

favorite












I am running a python script named myscript.py on ubuntu machine. I usually use python command to run python scripts as below.



python main.py


Recently, I downloaded a python script from a Github repository ( if need to look into the repository can find it at https://github.com/gsrivas4/mnist-gan) which asks to run script using './' as below.



./main.py


Running python scripts second way is new to me. I am confused about when can we use './' to run scripts and is this method to run scripts used for other languages as well. Usually, I would expect name of binary such as python which will start a process before I add the name of script. This script will be fed to the process. Also, I want to understand what is the meaning of './' when we run scripts. I feel this is trivial question, but could not find much help online.



I also tried making one of my python file executable and then ran it. However, running it using ./ gave me errors for any python library import commands.







share|improve this question





















  • Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
    – Jesse_b
    Apr 28 at 20:12











  • @Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
    – GAURAV SRIVASTAVA
    Apr 28 at 20:13










  • Does the python script you are getting errors with have a hashbang pointing to python?
    – Jesse_b
    Apr 28 at 20:14










  • @Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
    – GAURAV SRIVASTAVA
    Apr 28 at 20:19












up vote
3
down vote

favorite









up vote
3
down vote

favorite











I am running a python script named myscript.py on ubuntu machine. I usually use python command to run python scripts as below.



python main.py


Recently, I downloaded a python script from a Github repository ( if need to look into the repository can find it at https://github.com/gsrivas4/mnist-gan) which asks to run script using './' as below.



./main.py


Running python scripts second way is new to me. I am confused about when can we use './' to run scripts and is this method to run scripts used for other languages as well. Usually, I would expect name of binary such as python which will start a process before I add the name of script. This script will be fed to the process. Also, I want to understand what is the meaning of './' when we run scripts. I feel this is trivial question, but could not find much help online.



I also tried making one of my python file executable and then ran it. However, running it using ./ gave me errors for any python library import commands.







share|improve this question













I am running a python script named myscript.py on ubuntu machine. I usually use python command to run python scripts as below.



python main.py


Recently, I downloaded a python script from a Github repository ( if need to look into the repository can find it at https://github.com/gsrivas4/mnist-gan) which asks to run script using './' as below.



./main.py


Running python scripts second way is new to me. I am confused about when can we use './' to run scripts and is this method to run scripts used for other languages as well. Usually, I would expect name of binary such as python which will start a process before I add the name of script. This script will be fed to the process. Also, I want to understand what is the meaning of './' when we run scripts. I feel this is trivial question, but could not find much help online.



I also tried making one of my python file executable and then ran it. However, running it using ./ gave me errors for any python library import commands.









share|improve this question












share|improve this question




share|improve this question








edited Apr 29 at 12:49









Jeff Schaller

31.1k846105




31.1k846105









asked Apr 28 at 20:06









GAURAV SRIVASTAVA

185




185











  • Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
    – Jesse_b
    Apr 28 at 20:12











  • @Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
    – GAURAV SRIVASTAVA
    Apr 28 at 20:13










  • Does the python script you are getting errors with have a hashbang pointing to python?
    – Jesse_b
    Apr 28 at 20:14










  • @Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
    – GAURAV SRIVASTAVA
    Apr 28 at 20:19
















  • Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
    – Jesse_b
    Apr 28 at 20:12











  • @Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
    – GAURAV SRIVASTAVA
    Apr 28 at 20:13










  • Does the python script you are getting errors with have a hashbang pointing to python?
    – Jesse_b
    Apr 28 at 20:14










  • @Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
    – GAURAV SRIVASTAVA
    Apr 28 at 20:19















Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
– Jesse_b
Apr 28 at 20:12





Probably related: Does the shebang determine the shell which runs the script? and What does the ./ mean (dot slash) in linux?
– Jesse_b
Apr 28 at 20:12













@Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
– GAURAV SRIVASTAVA
Apr 28 at 20:13




@Jesse_b my_script.py is just an example. I am running ./main.py. I will edit my question to make the point clear.
– GAURAV SRIVASTAVA
Apr 28 at 20:13












Does the python script you are getting errors with have a hashbang pointing to python?
– Jesse_b
Apr 28 at 20:14




Does the python script you are getting errors with have a hashbang pointing to python?
– Jesse_b
Apr 28 at 20:14












@Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
– GAURAV SRIVASTAVA
Apr 28 at 20:19




@Jesse_b No there is not hashbang in my script which gives errors. I was unaware of hashbang. I am reading about it now.
– GAURAV SRIVASTAVA
Apr 28 at 20:19










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










./ is simply a relative path indicating the current working directory. When executing a file that is not in your PATH it's necessary to prefix it with either the full path or a relative path, ./ is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py



The reason your python script gets errors when you execute it as:



./script.py


rather than:



python script.py


is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)




To get your script to execute properly using python add the following to the first line in the script:



#!/usr/bin/env python





share|improve this answer





















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440642%2frunning-python-script-on-ubuntu-machine-using-myscript-py%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    ./ is simply a relative path indicating the current working directory. When executing a file that is not in your PATH it's necessary to prefix it with either the full path or a relative path, ./ is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py



    The reason your python script gets errors when you execute it as:



    ./script.py


    rather than:



    python script.py


    is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)




    To get your script to execute properly using python add the following to the first line in the script:



    #!/usr/bin/env python





    share|improve this answer

























      up vote
      1
      down vote



      accepted










      ./ is simply a relative path indicating the current working directory. When executing a file that is not in your PATH it's necessary to prefix it with either the full path or a relative path, ./ is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py



      The reason your python script gets errors when you execute it as:



      ./script.py


      rather than:



      python script.py


      is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)




      To get your script to execute properly using python add the following to the first line in the script:



      #!/usr/bin/env python





      share|improve this answer























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted






        ./ is simply a relative path indicating the current working directory. When executing a file that is not in your PATH it's necessary to prefix it with either the full path or a relative path, ./ is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py



        The reason your python script gets errors when you execute it as:



        ./script.py


        rather than:



        python script.py


        is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)




        To get your script to execute properly using python add the following to the first line in the script:



        #!/usr/bin/env python





        share|improve this answer













        ./ is simply a relative path indicating the current working directory. When executing a file that is not in your PATH it's necessary to prefix it with either the full path or a relative path, ./ is the most simple method of doing this, but it would also work if you used a full path like /path/to/script.py



        The reason your python script gets errors when you execute it as:



        ./script.py


        rather than:



        python script.py


        is because you do not have a hashbang(shebang) interpreter line at the top telling it which interpreter to use when executing the script. It's likely trying to execute it with bash or whatever shell you are using to execute the script. (See Which shell interpreter runs a script with no shebang?)




        To get your script to execute properly using python add the following to the first line in the script:



        #!/usr/bin/env python






        share|improve this answer













        share|improve this answer



        share|improve this answer











        answered Apr 28 at 20:24









        Jesse_b

        10.3k22658




        10.3k22658






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f440642%2frunning-python-script-on-ubuntu-machine-using-myscript-py%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?