Python 导入错误:重新格式化笔记本电脑后没有名为 git 的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28483253/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ImportError: No module named git after reformatting laptop
提问by JavaDeveloper
My laptop has been formatted and new OS was installed, and since then I get this error: ImportError: No module named git
我的笔记本电脑已经格式化并安装了新的操作系统,从那时起我收到了这个错误:ImportError: No module named git
This refers to a python code which simply imports git.
这是指简单地导入 git 的 python 代码。
Location of git before my laptop was formatted: /usr/local/bin/git Location of git after the laptop was formatted: /usr/bin/git
我的笔记本电脑格式化前的 git 位置:/usr/local/bin/git 笔记本电脑格式化后的 git 位置:/usr/bin/git
How / what do I change in my python code to refer to right path ?
我如何/如何更改我的 python 代码以引用正确的路径?
采纳答案by Martijn Pieters
The git
module is not the same thingas the git
command line executable. They happen to have the same name and cover related tasks, but they are distinct software packages.
该git
模块是不一样的东西作为git
命令行可执行文件。它们碰巧具有相同的名称并涵盖相关任务,但它们是不同的软件包。
I'm going to assume that the git
module your code is importing is the one provided by the GitPython project. You'll need to install that project, see their installation instructions:
我将假设git
您的代码正在导入的模块是GitPython 项目提供的模块。您需要安装该项目,请参阅他们的安装说明:
# pip install gitpython
回答by Thibaud Hulin
In my cas, I installed pythong2-git, it solved my problem.
在我的 cas 中,我安装了 pythong2-git,它解决了我的问题。
sudo apt-get install python3-git
回答by Andrei Tarnauceanu
In my case apt install python-gitfixed the issue.
在我的情况下apt install python-git解决了这个问题。
回答by user3273675
You can try this.
你可以试试这个。
GitPython's git repo is available on GitHub, which can be browsed at:
GitPython 的 git repo 在 GitHub 上可用,可以在以下位置浏览:
https://github.com/gitpython-developers/GitPythonand cloned using:
https://github.com/gitpython-developers/GitPython并使用以下方法克隆:
$ git clone https://github.com/gitpython-developers/GitPythongit-python
$ git clone https://github.com/gitpython-developers/GitPythongit-python
Initialize all submodules to obtain the required dependencies with:
初始化所有子模块以获取所需的依赖项:
$ cd git-python $ git submodule update --init --recursive
$ cd git-python $ git submodule update --init --recursive