python: can't open file 'Functions.py': [Errno 2





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







0















I am trying to run my sample code containing functions but get the following error when running from the command line.




python: can't open file 'Functions.py': [Errno 2




I have checked my environment variables and also reviewed my code. I am currently using JetBrains Pycharm 2018.3.2 version, could this be the issue?










share|improve this question




















  • 1





    what are you typing in the cmd?

    – Alexis
    Jan 3 at 10:04






  • 1





    Please post your code

    – Giordano
    Jan 3 at 10:06











  • Hereunder is the code and the command on CMD def My1st(): firstVar = 1 secondVar = 2 result = firstVar + secondVar print("The result is " + result) if name == "main": My1st() C:UsersUserPycharmProjectsFirstProJec>python Functions.py

    – Samuel Masemola
    Jan 3 at 10:16













  • Please edit your answer to add this additional info as it makes it easier for others to see and answer your question.

    – Jamie Scott
    Jan 3 at 10:20


















0















I am trying to run my sample code containing functions but get the following error when running from the command line.




python: can't open file 'Functions.py': [Errno 2




I have checked my environment variables and also reviewed my code. I am currently using JetBrains Pycharm 2018.3.2 version, could this be the issue?










share|improve this question




















  • 1





    what are you typing in the cmd?

    – Alexis
    Jan 3 at 10:04






  • 1





    Please post your code

    – Giordano
    Jan 3 at 10:06











  • Hereunder is the code and the command on CMD def My1st(): firstVar = 1 secondVar = 2 result = firstVar + secondVar print("The result is " + result) if name == "main": My1st() C:UsersUserPycharmProjectsFirstProJec>python Functions.py

    – Samuel Masemola
    Jan 3 at 10:16













  • Please edit your answer to add this additional info as it makes it easier for others to see and answer your question.

    – Jamie Scott
    Jan 3 at 10:20














0












0








0








I am trying to run my sample code containing functions but get the following error when running from the command line.




python: can't open file 'Functions.py': [Errno 2




I have checked my environment variables and also reviewed my code. I am currently using JetBrains Pycharm 2018.3.2 version, could this be the issue?










share|improve this question
















I am trying to run my sample code containing functions but get the following error when running from the command line.




python: can't open file 'Functions.py': [Errno 2




I have checked my environment variables and also reviewed my code. I am currently using JetBrains Pycharm 2018.3.2 version, could this be the issue?







python pycharm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 14:33









Juan Leni

3,26612940




3,26612940










asked Jan 3 at 10:00









Samuel MasemolaSamuel Masemola

33




33








  • 1





    what are you typing in the cmd?

    – Alexis
    Jan 3 at 10:04






  • 1





    Please post your code

    – Giordano
    Jan 3 at 10:06











  • Hereunder is the code and the command on CMD def My1st(): firstVar = 1 secondVar = 2 result = firstVar + secondVar print("The result is " + result) if name == "main": My1st() C:UsersUserPycharmProjectsFirstProJec>python Functions.py

    – Samuel Masemola
    Jan 3 at 10:16













  • Please edit your answer to add this additional info as it makes it easier for others to see and answer your question.

    – Jamie Scott
    Jan 3 at 10:20














  • 1





    what are you typing in the cmd?

    – Alexis
    Jan 3 at 10:04






  • 1





    Please post your code

    – Giordano
    Jan 3 at 10:06











  • Hereunder is the code and the command on CMD def My1st(): firstVar = 1 secondVar = 2 result = firstVar + secondVar print("The result is " + result) if name == "main": My1st() C:UsersUserPycharmProjectsFirstProJec>python Functions.py

    – Samuel Masemola
    Jan 3 at 10:16













  • Please edit your answer to add this additional info as it makes it easier for others to see and answer your question.

    – Jamie Scott
    Jan 3 at 10:20








1




1





what are you typing in the cmd?

– Alexis
Jan 3 at 10:04





what are you typing in the cmd?

– Alexis
Jan 3 at 10:04




1




1





Please post your code

– Giordano
Jan 3 at 10:06





Please post your code

– Giordano
Jan 3 at 10:06













Hereunder is the code and the command on CMD def My1st(): firstVar = 1 secondVar = 2 result = firstVar + secondVar print("The result is " + result) if name == "main": My1st() C:UsersUserPycharmProjectsFirstProJec>python Functions.py

– Samuel Masemola
Jan 3 at 10:16







Hereunder is the code and the command on CMD def My1st(): firstVar = 1 secondVar = 2 result = firstVar + secondVar print("The result is " + result) if name == "main": My1st() C:UsersUserPycharmProjectsFirstProJec>python Functions.py

– Samuel Masemola
Jan 3 at 10:16















Please edit your answer to add this additional info as it makes it easier for others to see and answer your question.

– Jamie Scott
Jan 3 at 10:20





Please edit your answer to add this additional info as it makes it easier for others to see and answer your question.

– Jamie Scott
Jan 3 at 10:20












3 Answers
3






active

oldest

votes


















1














Based on your comments, your code should be like this:



def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)


if __name__ == '__main__':
My1st()


Notice the concatenation in the print statement and the name attribute.
and then if you're on windows(as it looks like you are),



py Functions.py


should give you the output: 3






share|improve this answer
























  • I have made the change, but still get the same result. Could this be an issue with the environment?

    – Samuel Masemola
    Jan 3 at 10:33











  • @SamuelMasemola Probably no, how are you running the file now? Right click on the file (opened in the pyCharm) and click on Run 'Functions.py' and what do you get?

    – DirtyBit
    Jan 3 at 10:35






  • 1





    I have sorted the issue out now. The problem initially was when creating the file in the IDE using the Pycharm wizard and clicking on File instead of selecting Python File. Noticed this after directly checking the directory. Thank you all so much for the assistance and hope to provide more valuable input in future as I continue to learn and grow with Python :)

    – Samuel Masemola
    Jan 3 at 10:49











  • @SamuelMasemola cheers, you can mark the answer and close the question if it helped!

    – DirtyBit
    Jan 3 at 10:51



















0














Errno 2 points out at a file or directory not being found (in this case 'Functions.py'). Could you check whether your path to Functions.py is correct?






share|improve this answer
























  • Hi, I have checked the path. Tried using the command line and the IDE Terminal which both produce the same result. This is the path below. (venv) C:UsersUserPycharmProjectsFirstProJec>python Functions.py

    – Samuel Masemola
    Jan 3 at 10:20



















0














there was an error in below line of your code




print("The result is " + result)




the problem is that you can't concatenate string with int value



and also i am not able to understand you problem but below are some code that you may want from your problem statement.



def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)
if __name__ == "__main__" :
My1st()


OR



def My1st():
firstVar = 1
secondVar = 2
result = firstVar + secondVar
print("The result is ", result)

My1st()





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%2f54019988%2fpython-cant-open-file-functions-py-errno-2%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Based on your comments, your code should be like this:



    def My1st():
    firstVar = 1
    secondVar = 2
    result = firstVar + secondVar
    print("The result is ", result)


    if __name__ == '__main__':
    My1st()


    Notice the concatenation in the print statement and the name attribute.
    and then if you're on windows(as it looks like you are),



    py Functions.py


    should give you the output: 3






    share|improve this answer
























    • I have made the change, but still get the same result. Could this be an issue with the environment?

      – Samuel Masemola
      Jan 3 at 10:33











    • @SamuelMasemola Probably no, how are you running the file now? Right click on the file (opened in the pyCharm) and click on Run 'Functions.py' and what do you get?

      – DirtyBit
      Jan 3 at 10:35






    • 1





      I have sorted the issue out now. The problem initially was when creating the file in the IDE using the Pycharm wizard and clicking on File instead of selecting Python File. Noticed this after directly checking the directory. Thank you all so much for the assistance and hope to provide more valuable input in future as I continue to learn and grow with Python :)

      – Samuel Masemola
      Jan 3 at 10:49











    • @SamuelMasemola cheers, you can mark the answer and close the question if it helped!

      – DirtyBit
      Jan 3 at 10:51
















    1














    Based on your comments, your code should be like this:



    def My1st():
    firstVar = 1
    secondVar = 2
    result = firstVar + secondVar
    print("The result is ", result)


    if __name__ == '__main__':
    My1st()


    Notice the concatenation in the print statement and the name attribute.
    and then if you're on windows(as it looks like you are),



    py Functions.py


    should give you the output: 3






    share|improve this answer
























    • I have made the change, but still get the same result. Could this be an issue with the environment?

      – Samuel Masemola
      Jan 3 at 10:33











    • @SamuelMasemola Probably no, how are you running the file now? Right click on the file (opened in the pyCharm) and click on Run 'Functions.py' and what do you get?

      – DirtyBit
      Jan 3 at 10:35






    • 1





      I have sorted the issue out now. The problem initially was when creating the file in the IDE using the Pycharm wizard and clicking on File instead of selecting Python File. Noticed this after directly checking the directory. Thank you all so much for the assistance and hope to provide more valuable input in future as I continue to learn and grow with Python :)

      – Samuel Masemola
      Jan 3 at 10:49











    • @SamuelMasemola cheers, you can mark the answer and close the question if it helped!

      – DirtyBit
      Jan 3 at 10:51














    1












    1








    1







    Based on your comments, your code should be like this:



    def My1st():
    firstVar = 1
    secondVar = 2
    result = firstVar + secondVar
    print("The result is ", result)


    if __name__ == '__main__':
    My1st()


    Notice the concatenation in the print statement and the name attribute.
    and then if you're on windows(as it looks like you are),



    py Functions.py


    should give you the output: 3






    share|improve this answer













    Based on your comments, your code should be like this:



    def My1st():
    firstVar = 1
    secondVar = 2
    result = firstVar + secondVar
    print("The result is ", result)


    if __name__ == '__main__':
    My1st()


    Notice the concatenation in the print statement and the name attribute.
    and then if you're on windows(as it looks like you are),



    py Functions.py


    should give you the output: 3







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 3 at 10:21









    DirtyBitDirtyBit

    13k41943




    13k41943













    • I have made the change, but still get the same result. Could this be an issue with the environment?

      – Samuel Masemola
      Jan 3 at 10:33











    • @SamuelMasemola Probably no, how are you running the file now? Right click on the file (opened in the pyCharm) and click on Run 'Functions.py' and what do you get?

      – DirtyBit
      Jan 3 at 10:35






    • 1





      I have sorted the issue out now. The problem initially was when creating the file in the IDE using the Pycharm wizard and clicking on File instead of selecting Python File. Noticed this after directly checking the directory. Thank you all so much for the assistance and hope to provide more valuable input in future as I continue to learn and grow with Python :)

      – Samuel Masemola
      Jan 3 at 10:49











    • @SamuelMasemola cheers, you can mark the answer and close the question if it helped!

      – DirtyBit
      Jan 3 at 10:51



















    • I have made the change, but still get the same result. Could this be an issue with the environment?

      – Samuel Masemola
      Jan 3 at 10:33











    • @SamuelMasemola Probably no, how are you running the file now? Right click on the file (opened in the pyCharm) and click on Run 'Functions.py' and what do you get?

      – DirtyBit
      Jan 3 at 10:35






    • 1





      I have sorted the issue out now. The problem initially was when creating the file in the IDE using the Pycharm wizard and clicking on File instead of selecting Python File. Noticed this after directly checking the directory. Thank you all so much for the assistance and hope to provide more valuable input in future as I continue to learn and grow with Python :)

      – Samuel Masemola
      Jan 3 at 10:49











    • @SamuelMasemola cheers, you can mark the answer and close the question if it helped!

      – DirtyBit
      Jan 3 at 10:51

















    I have made the change, but still get the same result. Could this be an issue with the environment?

    – Samuel Masemola
    Jan 3 at 10:33





    I have made the change, but still get the same result. Could this be an issue with the environment?

    – Samuel Masemola
    Jan 3 at 10:33













    @SamuelMasemola Probably no, how are you running the file now? Right click on the file (opened in the pyCharm) and click on Run 'Functions.py' and what do you get?

    – DirtyBit
    Jan 3 at 10:35





    @SamuelMasemola Probably no, how are you running the file now? Right click on the file (opened in the pyCharm) and click on Run 'Functions.py' and what do you get?

    – DirtyBit
    Jan 3 at 10:35




    1




    1





    I have sorted the issue out now. The problem initially was when creating the file in the IDE using the Pycharm wizard and clicking on File instead of selecting Python File. Noticed this after directly checking the directory. Thank you all so much for the assistance and hope to provide more valuable input in future as I continue to learn and grow with Python :)

    – Samuel Masemola
    Jan 3 at 10:49





    I have sorted the issue out now. The problem initially was when creating the file in the IDE using the Pycharm wizard and clicking on File instead of selecting Python File. Noticed this after directly checking the directory. Thank you all so much for the assistance and hope to provide more valuable input in future as I continue to learn and grow with Python :)

    – Samuel Masemola
    Jan 3 at 10:49













    @SamuelMasemola cheers, you can mark the answer and close the question if it helped!

    – DirtyBit
    Jan 3 at 10:51





    @SamuelMasemola cheers, you can mark the answer and close the question if it helped!

    – DirtyBit
    Jan 3 at 10:51













    0














    Errno 2 points out at a file or directory not being found (in this case 'Functions.py'). Could you check whether your path to Functions.py is correct?






    share|improve this answer
























    • Hi, I have checked the path. Tried using the command line and the IDE Terminal which both produce the same result. This is the path below. (venv) C:UsersUserPycharmProjectsFirstProJec>python Functions.py

      – Samuel Masemola
      Jan 3 at 10:20
















    0














    Errno 2 points out at a file or directory not being found (in this case 'Functions.py'). Could you check whether your path to Functions.py is correct?






    share|improve this answer
























    • Hi, I have checked the path. Tried using the command line and the IDE Terminal which both produce the same result. This is the path below. (venv) C:UsersUserPycharmProjectsFirstProJec>python Functions.py

      – Samuel Masemola
      Jan 3 at 10:20














    0












    0








    0







    Errno 2 points out at a file or directory not being found (in this case 'Functions.py'). Could you check whether your path to Functions.py is correct?






    share|improve this answer













    Errno 2 points out at a file or directory not being found (in this case 'Functions.py'). Could you check whether your path to Functions.py is correct?







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jan 3 at 10:04









    Hot PotatoHot Potato

    1




    1













    • Hi, I have checked the path. Tried using the command line and the IDE Terminal which both produce the same result. This is the path below. (venv) C:UsersUserPycharmProjectsFirstProJec>python Functions.py

      – Samuel Masemola
      Jan 3 at 10:20



















    • Hi, I have checked the path. Tried using the command line and the IDE Terminal which both produce the same result. This is the path below. (venv) C:UsersUserPycharmProjectsFirstProJec>python Functions.py

      – Samuel Masemola
      Jan 3 at 10:20

















    Hi, I have checked the path. Tried using the command line and the IDE Terminal which both produce the same result. This is the path below. (venv) C:UsersUserPycharmProjectsFirstProJec>python Functions.py

    – Samuel Masemola
    Jan 3 at 10:20





    Hi, I have checked the path. Tried using the command line and the IDE Terminal which both produce the same result. This is the path below. (venv) C:UsersUserPycharmProjectsFirstProJec>python Functions.py

    – Samuel Masemola
    Jan 3 at 10:20











    0














    there was an error in below line of your code




    print("The result is " + result)




    the problem is that you can't concatenate string with int value



    and also i am not able to understand you problem but below are some code that you may want from your problem statement.



    def My1st():
    firstVar = 1
    secondVar = 2
    result = firstVar + secondVar
    print("The result is ", result)
    if __name__ == "__main__" :
    My1st()


    OR



    def My1st():
    firstVar = 1
    secondVar = 2
    result = firstVar + secondVar
    print("The result is ", result)

    My1st()





    share|improve this answer






























      0














      there was an error in below line of your code




      print("The result is " + result)




      the problem is that you can't concatenate string with int value



      and also i am not able to understand you problem but below are some code that you may want from your problem statement.



      def My1st():
      firstVar = 1
      secondVar = 2
      result = firstVar + secondVar
      print("The result is ", result)
      if __name__ == "__main__" :
      My1st()


      OR



      def My1st():
      firstVar = 1
      secondVar = 2
      result = firstVar + secondVar
      print("The result is ", result)

      My1st()





      share|improve this answer




























        0












        0








        0







        there was an error in below line of your code




        print("The result is " + result)




        the problem is that you can't concatenate string with int value



        and also i am not able to understand you problem but below are some code that you may want from your problem statement.



        def My1st():
        firstVar = 1
        secondVar = 2
        result = firstVar + secondVar
        print("The result is ", result)
        if __name__ == "__main__" :
        My1st()


        OR



        def My1st():
        firstVar = 1
        secondVar = 2
        result = firstVar + secondVar
        print("The result is ", result)

        My1st()





        share|improve this answer















        there was an error in below line of your code




        print("The result is " + result)




        the problem is that you can't concatenate string with int value



        and also i am not able to understand you problem but below are some code that you may want from your problem statement.



        def My1st():
        firstVar = 1
        secondVar = 2
        result = firstVar + secondVar
        print("The result is ", result)
        if __name__ == "__main__" :
        My1st()


        OR



        def My1st():
        firstVar = 1
        secondVar = 2
        result = firstVar + secondVar
        print("The result is ", result)

        My1st()






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 3 at 10:36

























        answered Jan 3 at 10:29









        Ranjan KumarRanjan Kumar

        214




        214






























            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%2f54019988%2fpython-cant-open-file-functions-py-errno-2%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

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            How to fix TextFormField cause rebuild widget in Flutter