Recent Blog Posts

Python - Why your module is not being recognized

Python ModuleNotFound Error ( Solution)




Oh well if you are a beginner then this post is just perfect to solve your error. Hey there Python lovers, I am back again with some wholesome coding content. Ever faced the ModuleNotFound error in the Python console?. Well, there can be several reasons for the error to come, and let's understand the possible things because this error is occurring not only for this specific package but any other package I install using vscode or cmd.


CAUSES OF THE ERROR - 


Installation Directory - Make sure your modules are installed in the correct directory in Python 

Python Version - Sometimes Python version can cause issues with module import and even your pip version is crucial in this scenario so be sure to upgrade your pip by the command python -m pip install --upgrade pip
in the command prompt,  Oh yeah, and also be sure to install the wheel dependencies.

Module Name Mismatch - The most common mistake comes here, to avoid this make sure you type the module named correctly while installing the module and be sure to check it from the official Python website.

SOLUTION

The best solution here is to use a virtual environment instead of the default global one as a sandbox environment provides isolation of the project and avoids
conflicts between dependencies of different projects. Now, let's get to setting up a virtual environment to solve this error.


In your vscode terminal, type -

|python -m venv ./myenv
and just press enter, Now you will notice a folder of myenv being created at 
your directory GUI in vscode. Now selecting your interpreter comes into picture 
, Press ctrl+shift+P and search enter interpreter path and click on it, After  
clicking on it, click on Find.. and locate to the venv folder and just locate into the script's folder in the myenv select the python application as the interpreter, and then just try opening a new terminal. 
We have successfully set up a virtual environment Now try downloading your desired module again and Yeah it is solved!

Happy coding :), and also if you encounter an error that this script is malicious or the AMSI is being triggered then simply open the PowerShell terminal as administrator and then run the following command into it to bypass the ExecutionPolicy of scripts


|Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Bypass



  This will allow it to run for all the users...


Now, Let's save the discussion for the vscode IDE for the next blog, if you have any questions related to the IDE be sure to comment down below
I will make sure to answer each of the comments.




Any questions regarding anything? Comment down below!








Comments