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;
}
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
add a comment |
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
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
add a comment |
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
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
python pycharm
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
add a comment |
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
add a comment |
3 Answers
3
active
oldest
votes
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
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 onRun '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
add a comment |
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?
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
add a comment |
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()
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 onRun '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
add a comment |
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
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 onRun '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
add a comment |
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
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
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 onRun '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
add a comment |
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 onRun '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
add a comment |
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?
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
add a comment |
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?
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
add a comment |
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?
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?
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
add a comment |
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
add a comment |
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()
add a comment |
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()
add a comment |
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()
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()
edited Jan 3 at 10:36
answered Jan 3 at 10:29


Ranjan KumarRanjan Kumar
214
214
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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