{"id":129932,"date":"2022-11-21T18:02:26","date_gmt":"2022-11-21T18:02:26","guid":{"rendered":"https:\/\/blog.finxter.com\/?p=911808"},"modified":"2022-11-21T18:02:26","modified_gmt":"2022-11-21T18:02:26","slug":"fixed-modulenotfounderror-no-module-named-git-python","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2022\/11\/21\/fixed-modulenotfounderror-no-module-named-git-python\/","title":{"rendered":"(Fixed) ModuleNotFoundError: No Module Named \u2018git\u2019 | Python"},"content":{"rendered":"\n<div class=\"kk-star-ratings kksr-auto kksr-align-left kksr-valign-top\" data-payload='{&quot;align&quot;:&quot;left&quot;,&quot;id&quot;:&quot;911808&quot;,&quot;slug&quot;:&quot;default&quot;,&quot;valign&quot;:&quot;top&quot;,&quot;ignore&quot;:&quot;&quot;,&quot;reference&quot;:&quot;auto&quot;,&quot;class&quot;:&quot;&quot;,&quot;count&quot;:&quot;1&quot;,&quot;legendonly&quot;:&quot;&quot;,&quot;readonly&quot;:&quot;&quot;,&quot;score&quot;:&quot;5&quot;,&quot;best&quot;:&quot;5&quot;,&quot;gap&quot;:&quot;5&quot;,&quot;greet&quot;:&quot;Rate this post&quot;,&quot;legend&quot;:&quot;5\\\/5 - (1 vote)&quot;,&quot;size&quot;:&quot;24&quot;,&quot;width&quot;:&quot;142.5&quot;,&quot;_legend&quot;:&quot;{score}\\\/{best} - ({count} {votes})&quot;,&quot;font_factor&quot;:&quot;1.25&quot;}'>\n<div class=\"kksr-stars\">\n<div class=\"kksr-stars-inactive\">\n<div class=\"kksr-star\" data-star=\"1\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"2\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"3\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"4\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" data-star=\"5\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"kksr-stars-active\" style=\"width: 142.5px;\">\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<div class=\"kksr-star\" style=\"padding-right: 5px\">\n<div class=\"kksr-icon\" style=\"width: 24px; height: 24px;\"><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div class=\"kksr-legend\" style=\"font-size: 19.2px;\"> 5\/5 &#8211; (1 vote) <\/div>\n<\/div>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"565\" height=\"144\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-238.png\" alt=\"\" class=\"wp-image-911815\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-238.png 565w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-238-300x76.png 300w\" sizes=\"auto, (max-width: 565px) 100vw, 565px\" \/><\/figure>\n<\/div>\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>Quick Fix:<\/strong> Python raises the <code>ModuleNotFoundError: No module named 'git'<\/code> when you haven&#8217;t installed <code>GitPython<\/code> explicitly with <code>pip install GitPython<\/code> or <code>pip3 install GitPython<\/code> (Python 3). Or you may have different <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/how-to-check-your-python-version\/\" data-type=\"post\" data-id=\"1371\" target=\"_blank\">Python versions<\/a> on your computer, and <code>GitPython<\/code> is not installed for the particular version you&#8217;re using.<\/p>\n<p>You&#8217;ll learn how to fix this error below after diving into the concrete problem first.<\/p>\n<h2>Problem Formulation<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"683\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-239-1024x683.png\" alt=\"\" class=\"wp-image-911935\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-239-1024x683.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-239-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-239-768x513.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-239.png 1248w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>You&#8217;ve just learned about the awesome capabilities of the <code><a rel=\"noreferrer noopener\" href=\"https:\/\/gitpython.readthedocs.io\/en\/stable\/index.html\" data-type=\"URL\" data-id=\"https:\/\/gitpython.readthedocs.io\/en\/stable\/index.html\" target=\"_blank\">GitPython<\/a><\/code> library, and you want to try it out, so you start your code with the following statement:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import git<\/pre>\n<p>or even something like:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from git import Repo<\/pre>\n<p>This is supposed to import the git library into your <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-virtual-environments-with-venv-a-step-by-step-guide\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/python-virtual-environments-with-venv-a-step-by-step-guide\/\" target=\"_blank\">(virtual) environment<\/a>. However, it only throws the following <code>ModuleNotFoundError: No module named 'git'<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"1,5\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> import git\nTraceback (most recent call last): File \"&lt;pyshell#6>\", line 1, in &lt;module> import git\nModuleNotFoundError: No module named 'git'<\/pre>\n<h2>Solution Idea 1: Install Library GitPython<\/h2>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"682\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-240-1024x682.png\" alt=\"\" class=\"wp-image-911940\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-240-1024x682.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-240-300x200.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-240-768x511.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2022\/11\/image-240.png 1248w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>The most likely reason is that Python doesn&#8217;t provide <code>GitPython<\/code> in its standard library. You need to install it first!<\/p>\n<p>Before being able to import the <code>GitPython<\/code> module, you need to install it using Python&#8217;s package manager <code>pip<\/code>. <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/how-to-install-pip-on-windows\/\" data-type=\"post\" data-id=\"21552\" target=\"_blank\">Make sure pip is installed on your machine.<\/a><\/p>\n<p>To fix this error, you can run the following command in your Windows shell:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ pip install GitPython<\/pre>\n<p>This simple command installs <code>GitPython<\/code> in your virtual environment on Windows, Linux, and MacOS. <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/is-pip-pypi-case-sensitive\/\" data-type=\"post\" data-id=\"876064\" target=\"_blank\">Uppercase or lowercase library name<\/a> doesn&#8217;t matter. <\/p>\n<p>This assumes that your <code>pip<\/code> version is updated. If it isn&#8217;t, use the following two commands in your terminal, command line, or shell (there&#8217;s no harm in doing it anyways):<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ python -m pip install &#8211; upgrade pip\n$ pip install GitPython<\/pre>\n<p class=\"has-base-background-color has-background\"><img decoding=\"async\" src=\"https:\/\/s.w.org\/images\/core\/emoji\/14.0.0\/72x72\/1f4a1.png\" alt=\"\ud83d\udca1\" class=\"wp-smiley\" style=\"height: 1em; max-height: 1em;\" \/> <strong>Note<\/strong>: Don&#8217;t copy and paste the <code>$<\/code> symbol. This is just to illustrate that you run it in your shell\/terminal\/command line. <\/p>\n<p>Also, try the following variant if you run Python 3 on your computer:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pip3 install GitPython<\/pre>\n<\/p>\n<h2>Solution Idea 2: Fix the Path<\/h2>\n<p>The error might persist even after you have installed the <code>GitPython<\/code> library. This likely happens because <code>pip<\/code> is installed but doesn&#8217;t reside in the path you can use. Although <code>pip<\/code> may be installed on your system the script is unable to locate it. Therefore, it is unable to install the library using <code>pip<\/code> in the correct path.<\/p>\n<p>To fix the problem with the path in Windows follow the steps given next. <\/p>\n<p><strong>Step 1<\/strong>: Open the folder where you installed Python by opening the command prompt and typing <code>where python<\/code><\/p>\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"594\" height=\"121\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-35.png\" alt=\"\" class=\"wp-image-28221\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-35.png 594w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-35-300x61.png 300w\" sizes=\"auto, (max-width: 594px) 100vw, 594px\" \/><\/figure>\n<p><strong>Step 2<\/strong>: Once you have opened the <code>Python<\/code> folder, browse and open the <code>Scripts<\/code> folder and copy its location. Also verify that the folder contains the <code>pip<\/code> file.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"212\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-37-1024x212.png\" alt=\"\" class=\"wp-image-28224\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-37-1024x212.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-37-300x62.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-37-768x159.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-37.png 1328w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p><strong>Step 3<\/strong>: Now open the <code>Scripts<\/code> directory in the command prompt using the <code>cd<\/code> command and the location that you copied previously. <\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"800\" height=\"140\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-38.png\" alt=\"\" class=\"wp-image-28225\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-38.png 800w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-38-300x53.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/image-38-768x134.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/figure>\n<\/div>\n<p><strong>Step 4<\/strong>: Now install the library using <code>pip install GitPython<\/code> command. Here&#8217;s an analogous example:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"594\" height=\"163\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/04\/pip-path.gif\" alt=\"\" class=\"wp-image-28226\"\/><\/figure>\n<\/div>\n<p>After having followed the above steps, execute our script once again. And you should get the desired output.<\/p>\n<h2>Other Solution Ideas<\/h2>\n<ul>\n<li>The <code data-enlighter-language=\"generic\" class=\"EnlighterJSRAW\">ModuleNotFoundError<\/code> may appear due to <strong>relative imports<\/strong>. You can learn everything about relative imports and how to create your own module in <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/how-to-write-a-python-module-package\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/how-to-write-a-python-module-package\/\" target=\"_blank\">this article<\/a>. <\/li>\n<li>You may have mixed up Python and pip versions on your machine. In this case, to install <code>GitPython<\/code> for Python 3, you may want to try <code>python3 -m pip install GitPython<\/code> or even <code>pip3 install GitPython<\/code> instead of <code>pip install GitPython<\/code><\/li>\n<li>If you face this issue server-side, you may want to try the command <code>pip install &#8211; user GitPython<\/code><\/li>\n<li>If you&#8217;re using Ubuntu, you may want to try this command: <code>sudo apt install GitPython<\/code><\/li>\n<li>You can also check out <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/how-to-fix-importerror-cannot-import-name-x-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/how-to-fix-importerror-cannot-import-name-x-in-python\/\" target=\"_blank\">this article<\/a> to learn more about possible problems that may lead to an error when importing a library. <\/li>\n<\/ul>\n<h2>Understanding the &#8220;import&#8221; Statement<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import git<\/pre>\n<p>In Python, the <code>import<\/code> statement serves two main purposes:<\/p>\n<ul>\n<li>Search the module by its name, load it, and initialize it.<\/li>\n<li>Define a name in the local namespace within the scope of the <code>import<\/code> statement. This local name is then used to reference the accessed module throughout the code.<\/li>\n<\/ul>\n<h2>What&#8217;s the Difference Between ImportError and ModuleNotFoundError?<\/h2>\n<p>What&#8217;s the difference between <code>ImportError<\/code> and <code>ModuleNotFoundError<\/code>? <\/p>\n<p>Python defines an <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.python.org\/3\/library\/exceptions.html#exception-hierarchy\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/exceptions.html#exception-hierarchy\" target=\"_blank\">error hierarchy<\/a>, so some error classes <a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/inheritance-in-python-harry-potter-example\/\" data-type=\"post\" data-id=\"2179\" target=\"_blank\">inherit<\/a> from other error classes. In our case, the <code>ModuleNotFoundError<\/code> is a subclass of the <code>ImportError<\/code> class.<\/p>\n<p>You can see this in this screenshot from the <a href=\"https:\/\/docs.python.org\/3\/library\/exceptions.html#exception-hierarchy\" data-type=\"URL\" data-id=\"https:\/\/docs.python.org\/3\/library\/exceptions.html#exception-hierarchy\" target=\"_blank\" rel=\"noreferrer noopener\">docs<\/a>:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"906\" height=\"385\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/12\/image-37.png\" alt=\"\" class=\"wp-image-77708\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/12\/image-37.png 906w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/12\/image-37-300x127.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2021\/12\/image-37-768x326.png 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/figure>\n<\/div>\n<p>You can also check this relationship using the <code><a href=\"https:\/\/blog.finxter.com\/python-issubclass\/\" data-type=\"post\" data-id=\"23648\" target=\"_blank\" rel=\"noreferrer noopener\">issubclass()<\/a><\/code> built-in function:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">>>> issubclass(ModuleNotFoundError, ImportError)\nTrue<\/pre>\n<p>Specifically, Python raises the <code>ModuleNotFoundError<\/code> if the module (e.g., <code>git<\/code>) cannot be found. If it can be found, there may be a problem loading the module or some specific files within the module. In those cases, Python would raise an <code>ImportError<\/code>.<\/p>\n<p class=\"has-text-align-left has-black-color has-text-color has-background\" style=\"background-color:#fff8e6\">If an import statement cannot import a module, it raises an <span class=\"has-inline-color has-contrast-color\"><code>ImportError<\/code><\/span>. This may occur because of a faulty installation or an invalid path. In <a href=\"https:\/\/blog.finxter.com\/check-python-version-in-your-script-a-helpful-illustrated-guide\/\" data-type=\"post\" data-id=\"9010\" target=\"_blank\" rel=\"noreferrer noopener\">Python 3.6 or newer<\/a>, this will usually raise a <span class=\"has-inline-color has-contrast-color\"><code>ModuleNotFoundError<\/code><\/span>.<\/p>\n<h2>Related Videos<\/h2>\n<p>The following video shows you how to resolve the <code>ImportError<\/code>:<\/p>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube\"><a href=\"https:\/\/blog.finxter.com\/fixed-modulenotfounderror-no-module-named-git-python\/\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/plugins\/wp-youtube-lyte\/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2F20sWJ2sImVo%2Fhqdefault.jpg\" alt=\"YouTube Video\"><\/a><figcaption><\/figcaption><\/figure>\n<p>The following video shows you how to <a href=\"https:\/\/blog.finxter.com\/how-to-call-a-function-from-another-file-in-python\/\" data-type=\"URL\" data-id=\"https:\/\/blog.finxter.com\/how-to-call-a-function-from-another-file-in-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">import a function from another folder<\/a>&#8212;doing it the wrong way often results in the <code>ModuleNotFoundError<\/code>:<\/p>\n<figure class=\"wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube\"><a href=\"https:\/\/blog.finxter.com\/fixed-modulenotfounderror-no-module-named-git-python\/\"><img decoding=\"async\" src=\"https:\/\/blog.finxter.com\/wp-content\/plugins\/wp-youtube-lyte\/lyteCache.php?origThumbUrl=https%3A%2F%2Fi.ytimg.com%2Fvi%2FL8N4mkq-tgo%2Fhqdefault.jpg\" alt=\"YouTube Video\"><\/a><figcaption><\/figcaption><\/figure>\n<h2>How to Fix &#8220;ModuleNotFoundError: No module named &#8216;git&#8217;&#8221; in PyCharm<\/h2>\n<p>If you create a new Python project in <a rel=\"noreferrer noopener\" title=\"PyCharm \u2013 A Simple Illustrated Guide\" href=\"https:\/\/blog.finxter.com\/pycharm-a-simple-illustrated-guide\/\" target=\"_blank\">PyCharm <\/a>and try to import the <code>GitPython<\/code> library, it&#8217;ll raise the following error message:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"raw\" data-enlighter-theme=\"\" data-enlighter-highlight=\"4\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Traceback (most recent call last): File \"C:\/Users\/...\/main.py\", line 1, in &lt;module> import git\nModuleNotFoundError: No module named 'git' Process finished with exit code 1<\/pre>\n<p>The reason is that each PyCharm project, per default, creates a <a title=\"Python Virtual Environments with Conda \u2014 Why the Buzz?\" rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/python-virtual-environments-conda\/\" target=\"_blank\">virtual environment<\/a> in which you can install custom Python modules. But the virtual environment is initially empty&#8212;even if you&#8217;ve already installed <code>GitPython<\/code> on your computer!<\/p>\n<p>Here&#8217;s a screenshot exemplifying this for the <code><a rel=\"noreferrer noopener\" href=\"https:\/\/blog.finxter.com\/pandas-quickstart\/\" data-type=\"post\" data-id=\"16511\" target=\"_blank\">pandas<\/a><\/code> library. It&#8217;ll look similar for <code>GitPython<\/code>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"653\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-1024x653.png\" alt=\"\" class=\"wp-image-16587\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-1024x653.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-300x191.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-768x490.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12-150x96.png 150w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-12.png 1108w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>The fix is simple: Use the <a href=\"https:\/\/blog.finxter.com\/how-to-install-a-library-on-pycharm\/\" data-type=\"post\" data-id=\"22469\" target=\"_blank\" rel=\"noreferrer noopener\">PyCharm installation<\/a> tooltips to install Pandas in your virtual environment&#8212;two clicks and you&#8217;re good to go!<\/p>\n<p>First, right-click on the <code>pandas<\/code> text in your editor:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"656\" src=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-1024x656.png\" alt=\"\" class=\"wp-image-16593\" srcset=\"https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-1024x656.png 1024w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-300x192.png 300w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-768x492.png 768w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14-150x96.png 150w, https:\/\/blog.finxter.com\/wp-content\/uploads\/2020\/11\/image-14.png 1102w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n<p>Second, click &#8220;<code>Show Context Actions<\/code>&#8221; in your context menu. In the new menu that arises, click &#8220;Install Pandas&#8221; and wait for PyCharm to finish the installation. <\/p>\n<p>The code will run after your installation completes successfully. <\/p>\n<p>As an alternative, you can also open the <code>Terminal<\/code> tool at the bottom and type:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">$ pip install GitPython<\/pre>\n<p>If this doesn&#8217;t work, you may want to set the Python interpreter to another version using the following tutorial: <a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/help\/pycharm\/2016.1\/configuring-python-interpreter-for-a-project.html\" target=\"_blank\">https:\/\/www.jetbrains.com\/help\/pycharm\/2016.1\/configuring-python-interpreter-for-a-project.html<\/a><\/p>\n<p>You can also manually install a new library such as <code>GitPython<\/code> in PyCharm using the following procedure:<\/p>\n<ul>\n<li>Open <code><strong>File &gt; Settings &gt; Project<\/strong><\/code> from the PyCharm menu.<\/li>\n<li>Select your current project.<\/li>\n<li>Click the <code><strong>Python Interpreter<\/strong><\/code> tab within your project tab.<\/li>\n<li>Click the small <code><strong>+<\/strong><\/code> symbol to add a new library to the project.<\/li>\n<li>Now type in the library to be installed, in your example Pandas, and click <code><strong>Install Package<\/strong><\/code>.<\/li>\n<li>Wait for the installation to terminate and close all popup windows.<\/li>\n<\/ul>\n<p>Here&#8217;s an analogous example:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" src=\"https:\/\/media.giphy.com\/media\/VQoZIvOyP23tVvQlW0\/source.gif\" alt=\"\"\/><\/figure>\n<\/div>\n<p>Here&#8217;s a full guide on how to install a library on PyCharm. <\/p>\n<ul>\n<li><a href=\"https:\/\/blog.finxter.com\/how-to-install-a-library-on-pycharm\/\" data-type=\"post\" data-id=\"22469\" target=\"_blank\" rel=\"noreferrer noopener\">How to Install a Library on PyCharm<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>5\/5 &#8211; (1 vote) Quick Fix: Python raises the ModuleNotFoundError: No module named &#8216;git&#8217; when you haven&#8217;t installed GitPython explicitly with pip install GitPython or pip3 install GitPython (Python 3). Or you may have different Python versions on your computer, and GitPython is not installed for the particular version you&#8217;re using. You&#8217;ll learn how to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[857],"tags":[73,468,528],"class_list":["post-129932","post","type-post","status-publish","format-standard","hentry","category-python-tut","tag-programming","tag-python","tag-tutorial"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/129932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=129932"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/129932\/revisions"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=129932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=129932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=129932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}