PyCharm set Configuration and Interpreter | Why won't PyCharm Execute my Code?

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
you've probably clicked on this video because you could not get pychomp to run your Python scripts if that is your problem you've come to the right place in this video we're going to go through how to set up the right configuration and choose the right interpreter so let me show you the minimum configuration that you need in order to get your python script running and while we do that I'll explain everything that you need to know about python configurations and The Interpreter look at this sample project in pychon all it has is a main.pi file that has one line of code that says print hello there are two things that you should notice first I'm getting an error message that says I have an invalid python interpreter selected and second you'll see that I don't have any configuration set The Interpreter interprets the code that you write if you're writing your scripts in Python then The Interpreter is going to be in Python executable file called python.exe the configuration on the other hand tells pycharm all it needs to know in order to run your script and that includes The Interpreter so let's start and configure the correct python interpreter if you have the same error message that I do you can click on it and then click on ADD interpreter if you don't have this error message another way to get to this window is by clicking on file then settings and then under the project with your project name click on python interpreter and then on this small gear icon you can click on ADD and you're now in the exact same window that I was in when I clicked on the error message you now have two options you can either create a new virtual environment that includes a python executable file that you can use as your interpreter or you can choose an existing environment such as your global environment to do that I could simply click on existing environment and then click on the three dots and then choose the location of where my python is installed on on my computer which would be over here under C python39 python.exe but trust me when I say that it is always better to use a virtual environment to run your projects if you don't know why I'll be leaving a link in the description with a video that explains why but we're going to go on new environment and create a new virtual environment we're going to leave the default settings as they are and then press on OK within the python interpreter field you can now see the path towards the python executable within your virtual environment now how do I know that this is within my virtual environment that is because it says v e n v over here so that stands for virtual environment now we can press on OK and you'll notice that we get a new folder within our file Tree on the left hand side of our screen if we open up this file and then open up the scripts you will see that one of them is called python.exe and that is exactly The Interpreter that we have set now that we've set the correct python interpreter you'll see that the error message is gone the next thing we need to do is we need to set up a configuration if you have set the python interpreter correctly then setting up the configuration is very simple all you have to do is right click within your editor and then click on run that will automatically set the right python configuration you can see this because the program has run successfully after all it says hello in the terminal and in addition to that in the configurations box in the top right hand corner there is now a configuration set if that didn't work for you then don't worry we're going to go through the process manually so let's go ahead and remove the configuration Again by clicking on it then clicking on edit configurations pressing the minus sign and then pressing on apply now okay and you will see that it says add configuration again telling us that we don't have one if we now want to create a configuration manually we have to click on ADD configuration first and then on add new run configuration then in the window that pops up we want to click on python because we're running a python script in the window that has opened up we can now set the configuration let's start by giving our configuration the name main now let's move on to the script path the script path is the path to the script that you're trying to execute to choose it you click on the small folder icon then within the window that opens up you have to try and find the script that you're trying to execute for me I have the sample project open and I am trying to execute the script main.pi so I'm going to click on it and press on OK you'll notice that once you have set the script path the working directory set automatically if you go back in the video you'll notice that before I set the script path the working directory was empty but now it is set automatically in addition you should make sure that the correct python interpreter is set that if you have created a python interpreter like we did earlier then you will see that the correct python interpreter is set by default but just make sure that the path that you see in this field corresponds to the path to the python interpreter that you created earlier and then you can click on apply and you will see that after you click on OK the main configuration is set in the small box over here on the top right hand corner and you can now press on the screen triangle to run your script and in the terminal output you'll see that the script is run successfully if this video helped you out then let me know by leaving a like down below and feel free to share this video with anyone who is having trouble getting their scripts to run in Python
Info
Channel: Max on Tech
Views: 42,042
Rating: undefined out of 5
Keywords:
Id: OajNS-WHiUI
Channel Id: undefined
Length: 5min 42sec (342 seconds)
Published: Sun Mar 05 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.