How to Fix PyCharm Import Error and Setup Your Interpreter

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys so in this video I'm gonna be trying to show you how to fix the pie charm import error now I say trying to because there's tons of different reasons why this might be breaking but I'm gonna be showing you the most common reasons in this video so please please please be patient and actually launch through the entirety of this video I guarantee if you're here you've probably been searching the internet for multiple hours and all you have to do is actually sit down stay focused for 10 minutes or ever long this video is gonna be and I promise I'm gonna try my best to show you all the different reasons why this might not be working so please don't skip through this just sit and watch and if I don't show your common error it's probably coming later in the video all right so let's go ahead and get started so you've opened up height ram you've tried to run your program and you get module not found can't import module whatever it is import there what we're gonna do now is go through how to fix this so the first thing we're gonna do is open up our command prompt and make sure that we've actually installed this module so we'll quickly just to test that this module is actually installed what we're gonna do is type pip install and then the name of the module so in this case I'm trying to import pygame and maybe that's the one that I'm getting an error with so I'm gonna do pip install pygame and see if that is installed or not if it says requirement already satisfied you've installed it but we want to do one other thing as well to make sure that we've installed this in the correct Python version which is type pip 3 install and then the name of the module as well now if one of these commands fails don't stress out about it but just try both pip and pip 3 and now try to import your module again and this might have fixed the problem for you now I'm assuming you guys have probably already tried this and this hasn't worked now what this means is you have more than one Python version on your machine and when you're typing pip you're not installing it into the Python version that you're using in pycharm so I'm going to show you how we can fix that now just quickly if pip did not work for you and this command did not work what you need to do is click on the card that I'm gonna leave in the top right hand corner which is gonna say how to install pagi now I know this is not probably like you're like well PI X on the module I want it tells you how to fix this pip command so go through that and then come back to this video if it's still not working alright so now what we're gonna do is figure out what's going on here and how many versions of Python we have why this isn't working in PyCharm now keep in mind when I say different versions I'm also talking about virtual environments so what we're gonna do is we're gonna go to our programs tab on windows and again this is kind of a windows-based tutorial what we're gonna do is scroll down and we're going to look for Python so if I can go find P and here it is so I see that right now I have one version of Python and it says python 3.7 now if you have more than one version this is an immediate red flag that first of all you probably don't need all those versions so go ahead and under stall uninstall the ones you don't need but that means you're probably using the wrong one inside of pycharm so just keep in mind what ones you have there and what is the most recent version of the version you want to be using because that's gonna be important for the rest of this tutorial now if you have anaconda and ideally those count as different versions alright and if you have just different versions of ideally again different versions alright okay so now what we're gonna do is figure out what version of python we actually installed these packages into now when you install python what ends up happening is you add some commands to your path which allows you to type well python in this console so what you're gonna do is go ahead and type python and see what version comes up now if you get a version that starts with a 2 what you're gonna do is you're gonna type quit to get out of this console and try typing python 3 okay if python 3 doesn't work that's fine that means you only have python to install but if python 3 does work that means you have a version of python 2 as well as a version of python 3 so we're gonna go ahead and type python and keep track of what version this is so in this case - three point seven point two and this is this means when you type PIPP or you type pip3 what's happening is you're installing those packages into python version whatever it is that you saw in this case three point seven point two and that's the version of python that we want to be using from inside of hydra so now time to go to pi try and pick this version of Python so what we're gonna do and there's different ways to do this is try first of all modifying our configurations which is on how I'm assuming you're running this if you're not don't worry I'm showing another method in a second we're gonna go to edit configurations and we're gonna select our Python interpreter here now if you see a bunch of different interpreters and you realize right away that you're not using that version that you saw from the terminal go ahead and select the correct version so in this case I need to be using Python 3.7 so I'm gonna select Python 3.7 but if for some reason you don't have any interpreters there or you don't see the version hold tight for one second and I'm gonna show you how we can get to it so I'm gonna select that now but if we don't see that what we're gonna do is go to file settings and then go to project and then project interpreter now you may see a list of interpreters here might say it's 3.6 3.7 whatever it is again if you see them here select the correct version so in this case python 3.7 go ahead hit apply you should be good to go to run your code you might have to change the configuration option to be that interpreter as well now if you don't see these here what you're gonna do is go to this gear icon and click on at and now we're gonna add this Python interpreter to our project and here's where we go into a few little side branches because this will be a little bit different depending on what versions you have and if you're using anaconda or not so if you're using a regular Python virtual environment by just typing virtual env or what that's how you've set it up you're gonna go to existing environment and you're gonna select that environment on your computer it's gonna be dependent on where you saved it so you're gonna have to find that and select that environment and select the Python interpreter now if you're using a condon vironment what we're gonna do is go to the existing environment we're going to click on these three dots if you don't see the environment you're using already which you probably won't and we're gonna find the conda environment that we're using so i'm gonna go to c drive here i'm gonna go to users and tomate and this is just my user this will be where your default anaconda is installed because that's where what we're looking for right now I'm gonna scroll down until I find anaconda three and what I'm gonna do now is go into env s now inside of here you should see a list of the virtual environments that you have if you have any and what we're gonna do now is we're going to select the virtual environment that we wish to use so I assume you guys know how to use virtual environments if you've installed the stuff into them so select the correct one we're gonna go down and we're going to select Python W Exe so let's say chatbots so what I want to use I'm gonna go into chat bot I'm gonna select select Python W exe and then click OK now if you're using anaconda but you did not create a virtual environment so all you're doing is you have one version of Python it's called Conda it's called anaconda what you've probably done when you installed your packages and it is installed it into what's known as the base directory now the base directory can be found or the interpreter for that if you open up this anaconda folder you scroll down and you select Python W Exe so don't go in OT n BS folder just select Python W Exe so if that's what you've done go ahead select okay and then you should again be ready to go PI trem might take a second to reboot and get ready to use that all right now last step if you're not using virtual environments you're not using anaconda what you're gonna do now is select what's known as the system interpreter so here again click this to see if your python version shows up 3.7 3.6 whatever it is that you need if it doesn't click on these three dots go to c drive and find the python version that you're using now this is gonna determine this is gonna be determined on where you saved your python version i don't know the default install location but it's really easy to look up you could probably just google python default install location go there and again select python Exe and if there is one a python w exe then that will set the interpreter for your project and you'll be able to use that version of python from PyCharm so once we've done that we've selected our correct version if this is still not working I don't know what to tell you guys because these are the most common errors that I there's probably something actually wrong with the module or package that you're using if none of this has fixed it for you so just quickly last kind of steps here in case this again is still not working you've gone through you've selected your Python interpreter and you've configured it in here inside of this configuration tab you've selected the correct one and then you've tried to run your program and it still doesn't work I'd recommend first off restarting your computer and from there you're gonna have to consult stack overflow and see what else you can do because these are the most common errors on why you get that PyCharm import error so again please don't freak out freak out on me if this doesn't work for you guys I've been trying my best to help people out I get tons of comments every day so hopefully this can help even a few of you just figure out that pycharm import error and if it did please make sure you leave a like and subscribe to the channel it really does mean a lot and help me out that being said I will see you guys in another video
Info
Channel: Tech With Tim
Views: 348,768
Rating: 4.765367 out of 5
Keywords: tech with tim, pycharm import error, pycharm import error no module named, pycharm interpreter setup, how to fix pycharm interpreter, how to fix pycharm, how to fix pycharm import, how to set up pycharm interpreter, pycharm import modules, python import error, python importerror no module named
Id: RvbUqf3Tb1s
Channel Id: undefined
Length: 9min 47sec (587 seconds)
Published: Tue Jun 25 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.