标签归档:git

Python在git bash的命令行中不起作用

问题:Python在git bash的命令行中不起作用

Python无法在git bash(Windows)中运行。当我在命令行中键入python时,它带我进入空白行,而无需说它像在Powershell中一样已经输入了python 2.7.10。它不会给我错误消息,但是python不会运行。

我已经确定PATH中的环境变量包括在内c:\python27。我还能检查什么?


发生此问题的会话如下所示:

user@hostname MINGW64 ~
$ type python
python is /c/Python27/python

user@hostname MINGW64 ~
$ python

…坐在那里而不返回提示。

Python will not run in git bash (Windows). When I type python in the command line, it takes me to a blank line without saying that it has entered python 2.7.10 like its does in Powershell. It doesn’t give me an error message, but python just doesn’t run.

I have already made sure the environmental variables in PATH included c:\python27. What else can I check?


A session wherein this issue occurs looks like the following:

user@hostname MINGW64 ~
$ type python
python is /c/Python27/python

user@hostname MINGW64 ~
$ python

…sitting there without returning to the prompt.


回答 0

只需在Windows的git shell中输入- alias python='winpty python.exe',就可以了,您将拥有python可执行文件的别名。请享用

PS有关永久别名的添加,请参见下文,

cd ~
touch .bashrc

然后打开.bashrc,从上方添加命令并保存文件。您需要通过控制台创建文件,否则无法使用适当的名称保存文件。您还需要重新启动外壳以应用更改。

Just enter this in your git shell on windows – > alias python='winpty python.exe', that is all and you are going to have alias to the python executable. Enjoy

P.S. For permanent alias addition see below,

cd ~
touch .bashrc

then open .bashrc, add your command from above and save the file. You need to create the file through the console or you cannot save it with the proper name. You also need to restart the shell to apply the change.


回答 1

我在答案列表中没有看到下一个选项,但可以通过“ -i”键获得交互式提示:

$ python -i
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55)
Type "help", "copyright", "credits" or "license" for more information.
>>> 

I don’t see next option in a list of answers, but I can get interactive prompt with “-i” key:

$ python -i
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55)
Type "help", "copyright", "credits" or "license" for more information.
>>> 

回答 2

这是MSys2中的一个已知错误,该错误提供了Git Bash使用的终端。您可以通过运行不支持ncurses的Python构建或使用WinPTY解决该问题,方法如下:

要在mintty或Cygwin sshd中运行Windows控制台程序,请在命令行之前添加console.exe:

$ build/console.exe c:/Python27/python.exe
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 10 + 20
30
>>> exit()

用于msys预构建二进制文件可能与Git Bash一起使用。(如果发布此答案以来已经过了很长时间,请检查是否有较新的版本!)。


从Windows 2.7.1的Git开始,也尝试使用winpty c:Python27/python.exe;。WinPTY可能是现成的。

This is a known bug in MSys2, which provides the terminal used by Git Bash. You can work around it by running a Python build without ncurses support, or by using WinPTY, used as follows:

To run a Windows console program in mintty or Cygwin sshd, prepend console.exe to the command-line:

$ build/console.exe c:/Python27/python.exe
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 10 + 20
30
>>> exit()

The prebuilt binaries for msys are likely to work with Git Bash. (Do check whether there’s a newer version if significant time has passed since this answer was posted!).


As of Git for Windows 2.7.1, also try using winpty c:Python27/python.exe; WinPTY may be included out-of-the-box.


回答 3

我是Windows 10用户,我只接受默认值就已在系统中安装了GIT

阅读以上答案后,我得到了2个解决方案,并且这2个解决方案可完美地在GIT bash上运行,并帮助我在GIT bash 上执行Python语句。

我要附加3张我的GIT图像 bash终端的。第一个有问题,第二个有解决方案。

问题 -光标在按下python命令后才等待

解决方案1

winpty <path-to-python-installation-dir>/python.exeGIT bash终端上执行。

注意:请勿C:\Users\AdminGIT bash中使用类似路径样式,而应使用/C/Users/Admin

就我而言,我winpty /C/Users/SJV/Anaconda2/python.exeGIT bash 上执行了命令

或者,如果您不知道用户名,请执行winpty /C/Users/$USERNAME/Anaconda2/python.exe

解决方案2

只需输入即可python -i

谢谢。

I am windows 10 user and I have installed GIT in my system by just accepting the defaults.

After reading the above answers, I got 2 solutions for my own and these 2 solutions perfectly works on GIT bash and facilitates me to execute Python statements on GIT bash.

I am attaching 3 images of my GIT bash terminal. 1st with problem and the latter 2 as solutions.

PROBLEM – Cursor is just waiting after hitting python command

SOLUTION 1

Execute winpty <path-to-python-installation-dir>/python.exe on GIT bash terminal.

Note: Do not use C:\Users\Admin like path style in GIT bash, instead use /C/Users/Admin.

In my case, I executed winpty /C/Users/SJV/Anaconda2/python.exe command on GIT bash

Or if you do not know your username then execute winpty /C/Users/$USERNAME/Anaconda2/python.exe

SOLUTION 2

Just type python -i and that is it.

Thanks.


回答 4

尝试python -i代替python,这是一个游标。

Try python -i instead of python, it’s a cursor thing.


回答 5

除了@ Charles-Duffy的答案外,您还可以直接使用winpty,而无需安装/下载任何其他内容。赶紧跑winpty c:/Python27/python.exe。可以在Git \ usr \ bin中找到实用程序winpty.exe。我正在为Windows v2.7.1使用Git

@ Charles-Duffy的预编译二进制文件的版本为0.1.1(根据文件名),而随附的二进制文件的版本为0.2.2。

In addition to the answer of @Charles-Duffy, you can use winpty directly without installing/downloading anything extra. Just run winpty c:/Python27/python.exe. The utility winpty.exe can be found at Git\usr\bin. I’m using Git for Windows v2.7.1

The prebuilt binaries from @Charles-Duffy is version 0.1.1(according to the file name), while the included one is 0.2.2


回答 6

Git Bash解决方法-使用别名启动Python 2和Python 3

。(对我来说)这是在Win 10上直接从Git Bash直接运行Python(Python 2.7和Python 3.x)的最佳解决方案=>将别名添加到Git Bash用于的别名文件中。

Git Bash别名文件aliass.sh它位于:

C:\path where you installed Git\etc\profile.d\aliases.sh

1)(使用Atom等文字编辑器打开)aliases.sh

例如:在我的情况下,文件位于 C:\Software\Develop\Git\etc\profile.d\aliases.sh

2)为Python添加别名

就我而言python.exe安装在:

C:\Networking\Network Automation\Python 2.7\python.exe
C:\Networking\Network Automation\Python 3.7\python.exe

所以,你必须创建2别名,一个为Python 2我命名python2)和其他的Python 3我命名只是Python)的Git Bash使用Linux的文件结构,就需要改变“\”“/” ,如果你路径与我的示例网络自动化类似,您可以使用“”

“网络自动化”例如。

winpty是将调用可执行文件的魔术命令。

因此,在aliases.sh的开头添加这些行

alias python2='winpty C/Networking/"Network Automation"/"Python 2.7"/python.exe'
alias python='winpty C/Networking/"Network Automation"/"Python 3.7"/python.exe'

3)添加或修改其他别名(如果需要)

我还修改了ll别名,以显示所有文件并在人类可读的列表中:

alias ll='ls -lah'

4)保存aliases.sh文件


5)好!关闭并重新启动您的Git Bash

现在,您可以永久地从Git shell直接启动两个Python,只需编写

$ python ->启动Python 3

$ python2 ->启动Python 2

$ ll ->输入ls -lah快速显示您的详细文件列表

干杯,哈利

Git Bash Workaround- Launch Python 2 & Python 3 with aliases

HI. This is (for me) the best solution to run both Python (Python 2.7 and Python 3.x) directly from Git Bash on Win 10 => adding aliases into the aliases file that Git Bash uses for.

Git Bash aliases file is aliases.sh. It is located in:

C:\path where you installed Git\etc\profile.d\aliases.sh

1) Open (with a text editor like Atom or other) the aliases.sh

for ex: in my case the file is in C:\Software\Develop\Git\etc\profile.d\aliases.sh

2) Add your alias for Python

In my case the python.exe are installed in:

C:\Networking\Network Automation\Python 2.7\python.exe
C:\Networking\Network Automation\Python 3.7\python.exe

So you must create 2 aliases, one for Python 2 (I named python2) and the other for Python 3 (I named just python) Git Bash uses linux file structure so you need to change the “\” for “/” and if you have a path like my example Network Automation you put it with ” “

“Network Automation”, for ex.

winpty is the magic command that will call the executable.

So add these lines at the beginning of aliases.sh

alias python2='winpty C/Networking/"Network Automation"/"Python 2.7"/python.exe'
alias python='winpty C/Networking/"Network Automation"/"Python 3.7"/python.exe'

3) Add or Modify other aliases (if you want)

I modified also the ll alias to show all the files and in a human readable list:

alias ll='ls -lah'

4) Save the aliases.sh file


5) OK!!! close and relaunch your Git Bash

Now, permanently you could launch both Python directly from Git shell just writting

$ python -> launch Python 3

$ python2 -> launch Python 2

$ ll -> enters a ls -lah to quickly show your detailed file list

Cheers, Harry


回答 7

您可以从以下位置更改Git Bash快捷方式的目标:

"C:\Program Files\Git\git-bash.exe" --cd-to-home 

"C:\Program Files\Git\git-cmd.exe" --no-cd --command=usr/bin/bash.exe -l -i

这是ConEmu用于启动git bash(版本16)的方式。最新版本正常启动它,这就是我到达那里的方式…

You can change target for Git Bash shortcut from:

"C:\Program Files\Git\git-bash.exe" --cd-to-home 

to

"C:\Program Files\Git\git-cmd.exe" --no-cd --command=usr/bin/bash.exe -l -i

This is the way ConEmu used to start git bash (version 16). Recent version starts it normally and it’s how I got there…


回答 8

类型:“ winpty python”,它将起作用

gitbash在运行以python开头的任何命令时都会遇到一些问题。这也适用于任何python manage.py命令。始终以“ winpty python manage.py”开头至少这对我有用。运行Windows 10。

type: ‘winpty python’ and it will work

gitbash has some issues when running any command that starts with python. this goes for any python manage.py commands as well. Always start with ‘winpty python manage.py’ At least this is what works for me. Running Windows 10.


回答 9

除了@Vitaliy Terziev答案

请尝试touch .bash_profile,然后将别名添加到文件中。

In addition to @Vitaliy Terziev answer

try touch .bash_profile and then add alias into the file.


回答 10

2个解决方法,而不是解决方案:在我的Git Bash中,以下命令挂起,并且我没有得到提示:

% python

所以我只用:

% winpty python

正如上面的某些人所指出的,您还可以使用:

% python -i

2 workarounds, rather than a solution: In my Git Bash, following command hangs and I don’t get the prompt back:

% python

So I just use:

% winpty python

As some people have noted above, you can also use:

% python -i

2020-07-14: Git 2.27.0 has added optional experimental support for pseudo consoles, which allow running Python from the command line:

See attached session.


回答 11

我正在Windows 10上通过Visual Studio Code使用MINGW64,并尝试安装node-sass(需要python2)。我在Github上跟随了felixrieseberg / windows-build-tools#56,它解决了我的问题。

这是一个特例,但如果有人遇到相同的问题,我将在此发布:

npm --add-python-to-path='true' --debug install --global windows-build-tools

这会将python和其他必需的构建工具安装到%USERPROFILE%\.windows-build-tools\python27

I am using MINGW64 via Visual Studio Code on Windows 10 and trying to install node-sass (which requires python2). I followed felixrieseberg/windows-build-tools #56 on Github which solved my issue.

This is a special case, but I’m posting in case someone has the same problem:

npm --add-python-to-path='true' --debug install --global windows-build-tools

This installs python and other required build tools to %USERPROFILE%\.windows-build-tools\python27.


回答 12

对于以gitbash作为默认终端的vscode中的python版本3.7.3,我处理了一段时间,然后遵循@Vitaliy Terziev建议将别名添加到.bashrc中,但具有以下规范:

别名python =“’/ c / Users /我的用户名/AppData/Local/Programs/Python/Python37/python.exe”’

注意单引号和双引号的组合,因为“我的用户名”空格。

对我来说,“ winpty”无法解析vscode中的python路径。

For python version 3.7.3 in vscode with gitbash as the default terminal I was dealing with this for a while and then followed @Vitaliy Terziev advice of adding the alias to .bashrc but with the following specification:

alias python=’“/c/Users/my user name/AppData/Local/Programs/Python/Python37/python.exe”’

Notice the combination of single and double quotes because of “my user name” spaces.

For me, “winpty” couldn’t resolve python path in vscode.


回答 13

此问题的另一个示例是在Windows中使用git bash(MINGW64,Mintty)中的AWS Elastic Beanstalk命令行界面(awsebcli,eb cli)(使用git版本2.19.0.windows.1)。

我之所以发布此帖子,是因为我花了一段时间才能找到此处的eb-cli具体问题。

需要用户输入的命令(例如eb init或)似乎导致冻结/挂起。实际上,我想控制台未使用请求用户输入的文本进行更新。此外,eb config saveeb deploy仅在命令完成后才更新控制台文本,因此直到完成后我才能看到进度更新。

如在git for Windows发行说明(针对v2.19.0)和Xun Yang的答案中所述,一种解决方法是运行

winpty eb <command>(而不是eb <command>

正如本git Windows发行版中所建议的那样,替代方法可能是使用Windows本机控制台而不是mintty(在git安装过程中选择)。

Another example of this issue is using the AWS Elastic Beanstalk command line interface (awsebcli, eb cli) from the git bash (MINGW64, Mintty) in windows (using git version 2.19.0.windows.1).

I’m just posting this because it took me a while to end up here, searching for eb-cli specific issues.

Commands such as eb init or eb config save, which require user input, appear to cause a freeze/hang. In reality I guess the console is not updated with the text requesting user input. Moreover, eb deploy only updates the console text after the command has finished, so I don’t get to see progress updates until finished.

As mentioned in the git for windows release notes (for v2.19.0) and e.g. in Xun Yang’s answer, a workaround is to run

winpty eb <command> (instead of just eb <command>)

A alternative, as suggested in this git for windows issue, could be to use the windows native console instead of mintty (option during git installation).


回答 14

如前所述,上面为我工作的一个别名是以下别名:(我正在使用anaconda,因此首先找到python路径在哪里,然后将其添加到git bash上的别名中)。1.在anaconda终端上,我运行:where python 2.在git bash上,我运行:alias python='winpty "C:\ProgramData\Anaconda3\envs\your_env_name\python.exe"' 3.完成。Python是使用别名在git Bash内部定义的。

感谢(Vitaliy Terziev&hygull)的非常有益的回答。

The one worked for me is as mentioned earlier in these great answers above is the alias as follows: (I’m using anaconda, so first find where is the python path, then add it into the alias on git bash). 1. on anaconda terminal I run: where python 2. on git bash I run: alias python='winpty "C:\ProgramData\Anaconda3\envs\your_env_name\python.exe"' 3. Done. Python is defined inside the git Bash using the alias.

Thanks to (Vitaliy Terziev & hygull) for their very helpful answers.


回答 15

  1. python.exe -i可以,但是在发送“ ^ Z”(CTRL + Z)退出交互模式时遇到了问题。因此,winpty python.exe在Windows的Git Bash中使用似乎更好。

  2. 使用~/bin目录制作环绕/引用文件(如~/bin/python),该文件可在任何地方访问(您可以使用,如使用不同的版本参考~/bin/python37)。
    文件中的代码:

#!/usr/bin/env bash
# maybe declare env vars here like
# export PYTHONHOME=/c/Users/%USERNAME%/.python/Python36
# export PATH="${PATH}:/c/Users/%USERNAME%/.python/Python36"

# replace %USERNAME%,
# or use "~" instead of "/c/Users/%USERNAME%" if it works
winpty /c/Users/%USERNAME%/.python/Python36/python.exe ${@}

我只是不喜欢这些“魔术”别名,您总是忘记它的来源,有时在某些情况下会导致问题。

  1. 使用~/bin/python文件和-i参数:
#!/usr/bin/env bash
if [ -z "${@}" ]; then
    # empty args, use interactive mode
    /c/Users/%USERNAME%/.python/Python36/python.exe -i
else
    /c/Users/%USERNAME%/.python/Python36/python.exe ${@}
fi
  1. python.exe -i works but got issues in exiting from the interactive mode by sending “^Z” (CTRL+Z). So, seem better to use winpty python.exe in Git Bash for Windows.

  2. Use ~/bin directory to make a wrap/reference file (like ~/bin/python) which will be accessible everywhere (you may use different version reference like ~/bin/python37).
    Code inside the file:

#!/usr/bin/env bash
# maybe declare env vars here like
# export PYTHONHOME=/c/Users/%USERNAME%/.python/Python36
# export PATH="${PATH}:/c/Users/%USERNAME%/.python/Python36"

# replace %USERNAME%,
# or use "~" instead of "/c/Users/%USERNAME%" if it works
winpty /c/Users/%USERNAME%/.python/Python36/python.exe ${@}

I just don’t like these “magic” aliases which you’re always forgetting where it’s coming from, and sometimes leads to issues in some cases.

  1. Use ~/bin/python file and -i parameter:
#!/usr/bin/env bash
if [ -z "${@}" ]; then
    # empty args, use interactive mode
    /c/Users/%USERNAME%/.python/Python36/python.exe -i
else
    /c/Users/%USERNAME%/.python/Python36/python.exe ${@}
fi

回答 16

键入命令PY而不是Python。调用解释器(python.org)。

Type the command PY instead of Python. Invoking the Interpreter (python.org).


回答 17

看看这个答案:

Git Bash无法运行我的python文件吗?

Git Bash中的路径应设置为:

PATH=$PATH:/c/Python27/

Have a look at this answer:

Git Bash won’t run my python files?

the path in Git Bash should be set like this:

PATH=$PATH:/c/Python27/

是否可以使用pip从私有GitHub存储库安装软件包?

问题:是否可以使用pip从私有GitHub存储库安装软件包?

我正在尝试从私有GitHub存储库安装Python软件包。对于公共存储库,我可以发出以下正常运行的命令:

pip install git+git://github.com/django/django.git

但是,如果我尝试将其用于私有存储库:

pip install git+git://github.com/echweb/echweb-utils.git

我得到以下输出:

Downloading/unpacking git+git://github.com/echweb/echweb-utils.git
Cloning Git repository git://github.com/echweb/echweb-utils.git to /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build
Complete output from command /usr/local/bin/git clone git://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build:
fatal: The remote end hung up unexpectedly

Cloning into /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build...

----------------------------------------
Command /usr/local/bin/git clone git://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build failed with error code 128

我猜这是因为我试图在不提供任何身份验证的情况下访问私有存储库。因此,我尝试使用Git + ssh希望pip使用我的SSH公钥进行身份验证:

pip install git+ssh://github.com/echweb/echweb-utils.git

这给出以下输出:

Downloading/unpacking git+ssh://github.com/echweb/echweb-utils.git
Cloning Git repository ssh://github.com/echweb/echweb-utils.git to /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build
Complete output from command /usr/local/bin/git clone ssh://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build:
Cloning into /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build...

Permission denied (publickey).

fatal: The remote end hung up unexpectedly

----------------------------------------
Command /usr/local/bin/git clone ssh://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build failed with error code 128

我正在努力实现的目标是否可能?如果是这样,我该怎么办?

I am trying to install a Python package from a private GitHub repository. For a public repository, I can issue the following command which works fine:

pip install git+git://github.com/django/django.git

However, if I try this for a private repository:

pip install git+git://github.com/echweb/echweb-utils.git

I get the following output:

Downloading/unpacking git+git://github.com/echweb/echweb-utils.git
Cloning Git repository git://github.com/echweb/echweb-utils.git to /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build
Complete output from command /usr/local/bin/git clone git://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build:
fatal: The remote end hung up unexpectedly

Cloning into /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build...

----------------------------------------
Command /usr/local/bin/git clone git://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-VRsIoo-build failed with error code 128

I guess this is because I am trying to access a private repository without providing any authentication. I therefore tried to use Git + ssh hoping that pip would use my SSH public key to authenticate:

pip install git+ssh://github.com/echweb/echweb-utils.git

This gives the following output:

Downloading/unpacking git+ssh://github.com/echweb/echweb-utils.git
Cloning Git repository ssh://github.com/echweb/echweb-utils.git to /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build
Complete output from command /usr/local/bin/git clone ssh://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build:
Cloning into /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build...

Permission denied (publickey).

fatal: The remote end hung up unexpectedly

----------------------------------------
Command /usr/local/bin/git clone ssh://github.com/echweb/echweb-utils.git /var/folders/cB/cB85g9P7HM4jcPn7nrvWRU+++TI/-Tmp-/pip-DQB8s4-build failed with error code 128

Is what I am trying to achieve even possible? If so, how can I do it?


回答 0

您可以使用git+sshURI方案,但是必须设置用户名:

pip install git+ssh://git@github.com/echweb/echweb-utils.git

git@在URI中看到该部分了吗?

PS:另请参阅有关部署密钥

PPS:在我的安装中,“ git + ssh” URI方案仅适用于“可编辑”的要求:

pip install -e URI#egg=EggName

切记:在命令中使用遥控器的地址之前:,请将要git remote -v打印的/字符更改为字符pip

$ git remote -v
origin  git@github.com:echweb/echweb-utils.git (fetch)
                      ^ change this to a '/' character

如果您忘记了,则会收到此错误:

ssh: Could not resolve hostname github.com:echweb:
         nodename nor servname provided, or not known

You can use the git+ssh URI scheme, but you must set a username:

pip install git+ssh://git@github.com/echweb/echweb-utils.git

Do you see the git@ part into the URI?

PS: Also read about deploy keys.

PPS: In my installation, the “git+ssh” URI scheme works only with “editable” requirements:

pip install -e URI#egg=EggName

Remember: Change the : character that git remote -v prints to a / character before using the remote’s address in the pip command:

$ git remote -v
origin  git@github.com:echweb/echweb-utils.git (fetch)
                      ^ change this to a '/' character

If you forget, you will get this error:

ssh: Could not resolve hostname github.com:echweb:
         nodename nor servname provided, or not known

回答 1

作为另一项技术,如果您在本地克隆了专用存储库,则可以执行以下操作:

pip install git+file://c:/repo/directory

更现代的是,您可以执行此操作(这-e将意味着您不必在更改被反映之前就提交更改):

pip install -e C:\repo\directory

As an additional technique, if you have the private repository cloned locally, you can do:

pip install git+file://c:/repo/directory

More modernly, you can just do this (and the -e will mean you don’t have to commit changes before they’re reflected):

pip install -e C:\repo\directory

回答 2

您可以使用HTTPS URL直接执行此操作,如下所示:

pip install git+https://github.com/username/repo.git

例如,这也可以仅将这一行添加到Django项目中的requirements.txt中。

You can do it directly with the HTTPS URL like this:

pip install git+https://github.com/username/repo.git

This also works just appending that line in the requirements.txt in a Django project, for instance.


回答 3

它也可以与Bitbucket一起使用

pip install git+ssh://git@bitbucket.org/username/projectname.git

在这种情况下,Pip将使用您的SSH密钥。

It also works with Bitbucket:

pip install git+ssh://git@bitbucket.org/username/projectname.git

Pip will use your SSH keys in this case.


回答 4

需求文件的语法在此处给出:

https://pip.pypa.io/zh_CN/latest/reference/pip_install.html#requirements-file-format

因此,例如,使用:

-e git+http://github.com/rwillmer/django-behave#egg=django-behave

如果您希望源在安装后继续存在。

要不就

git+http://github.com/rwillmer/django-behave#egg=django-behave

如果您只想安装它。

The syntax for the requirements file is given here:

https://pip.pypa.io/en/latest/reference/pip_install.html#requirements-file-format

So for example, use:

-e git+http://github.com/rwillmer/django-behave#egg=django-behave

if you want the source to stick around after installation.

Or just

git+http://github.com/rwillmer/django-behave#egg=django-behave

if you just want it to be installed.


回答 5

我发现使用令牌比使用SSH密钥容易得多。我在这方面找不到很多好的文档,因此我主要是通过反复试验来遇到此解决方案。此外,从pip和setuptools安装有一些细微的差异。但是这种方式对两者都适用。

GitHub尚未提供(目前,截至2016年8月)提供了一种获取私有存储库zip / tarball的简便方法。因此,您需要指向setuptools来告诉setuptools您指向的是Git存储库:

from setuptools import setup
import os
# Get the deploy key from https://help.github.com/articles/git-automation-with-oauth-tokens/
github_token = os.environ['GITHUB_TOKEN']

setup(
    # ...
    install_requires='package',
    dependency_links = [
    'git+https://{github_token}@github.com/user/{package}.git/@{version}#egg={package}-0'
        .format(github_token=github_token, package=package, version=master)
        ]

这里有几点注意事项:

  • 对于私有存储库,您需要通过GitHub进行身份验证;我发现的最简单的方法是创建OAuth令牌,将其放入您的环境中,然后将其包含在URL中
  • 即使在PyPI上没有任何软件包,您也需要在链接末尾包含一些版本号(在此处0)。这必须是实际数字,而不是单词。
  • 您需要以 git+序号告诉setuptools它是克隆存储库,而不是指向zip / tarball
  • version 可以是分支,标签或提交哈希
  • --process-dependency-links如果从pip安装,则需要提供

I found it much easier to use tokens than SSH keys. I couldn’t find much good documentation on this, so I came across this solution mainly through trial and error. Further, installing from pip and setuptools have some subtle differences; but this way should work for both.

GitHub don’t (currently, as of August 2016) offer an easy way to get the zip / tarball of private repositories. So you need to point setuptools to tell setuptools that you’re pointing to a Git repository:

from setuptools import setup
import os
# Get the deploy key from https://help.github.com/articles/git-automation-with-oauth-tokens/
github_token = os.environ['GITHUB_TOKEN']

setup(
    # ...
    install_requires='package',
    dependency_links = [
    'git+https://{github_token}@github.com/user/{package}.git/@{version}#egg={package}-0'
        .format(github_token=github_token, package=package, version=master)
        ]

A couple of notes here:

  • For private repositories, you need to authenticate with GitHub; the simplest way I found is to create an OAuth token, drop that into your environment, and then include it with the URL
  • You need to include some version number (here is 0) at the end of the link, even if there’s isn’t any package on PyPI. This has to be a actual number, not a word.
  • You need to preface with git+ to tell setuptools it’s to clone the repository, rather than pointing at a zip / tarball
  • version can be a branch, a tag, or a commit hash
  • You need to supply --process-dependency-links if installing from pip

回答 6

我想出了一种自动“点安装”不需要密码提示的GitLab私有存储库的方法。这种方法使用GitLab“部署密钥”和SSH配置文件,因此您可以使用个人SSH密钥以外的其他密钥进行部署(在我的情况下,由“机器人”使用)。也许有人会使用GitHub进行验证。

创建一个新的SSH密钥:

ssh-keygen -t rsa -C "GitLab_Robot_Deploy_Key"

该文件应显示为~/.ssh/GitLab_Robot_Deploy_Key~/.ssh/GitLab_Robot_Deploy_Key.pub

~/.ssh/GitLab_Robot_Deploy_Key.pub文件的内容复制并粘贴到GitLab的“部署密钥”对话框中。

测试新的部署密钥

以下命令告诉SSH使用新的部署密钥来建立连接。成功后,您将收到消息:“欢迎使用GitLab,用户名!”

ssh -T -i ~/.ssh/GitLab_Robot_Deploy_Key git@gitlab.mycorp.com

创建SSH配置文件

接下来,使用编辑器创建~/.ssh/config文件。添加以下内容。“主机”值可以是您想要的任何值(请记住它,因为稍后会使用它)。HostName是您的GitLab实例的URL。IdentifyFile是您在第一步中创建的SSH密钥文件的路径。

Host GitLab
  HostName gitlab.mycorp.com
  IdentityFile ~/.ssh/GitLab_Robot_Deploy_Key

将SSH指向配置文件

oxyum为我们提供了通过SSH使用pip的方法:

pip install git+ssh://git@gitlab.mycorp.com/my_name/my_repo.git

我们只需要对其稍作修改即可使SSH使用我们的新Deploy Key。为此,我们将SSH指向SSH配置文件中的Host条目。只需将命令中的“ gitlab.mycorp.com”替换为我们在SSH配置文件中使用的主机名即可:

pip install git+ssh://git@GitLab/my_name/my_repo.git

该软件包现在应该安装,没有任何密码提示。

参考文献A
参考文献B

I figured out a way to automagically ‘pip install’ a GitLab private repository that requires no password prompt. This approach uses GitLab “Deploy Keys” and an SSH configuration file, so you can deploy using keys other than your personal SSH keys (in my case, for use by a ‘bot). Perhaps someone kind soul can verify using GitHub.

Create a New SSH key:

ssh-keygen -t rsa -C "GitLab_Robot_Deploy_Key"

The file should show up as ~/.ssh/GitLab_Robot_Deploy_Key and ~/.ssh/GitLab_Robot_Deploy_Key.pub.

Copy and paste the contents of the ~/.ssh/GitLab_Robot_Deploy_Key.pub file into the GitLab “Deploy Keys” dialog.

Test the New Deploy Key

The following command tells SSH to use your new deploy key to set up the connection. On success, you should get the message: “Welcome to GitLab, UserName!”

ssh -T -i ~/.ssh/GitLab_Robot_Deploy_Key git@gitlab.mycorp.com

Create the SSH Configuration File

Next, use an editor to create a ~/.ssh/config file. Add the following contents. The ‘Host’ value can be anything you want (just remember it, because you’ll be using it later). The HostName is the URL to your GitLab instance. The IdentifyFile is path to the SSH key file you created in the first step.

Host GitLab
  HostName gitlab.mycorp.com
  IdentityFile ~/.ssh/GitLab_Robot_Deploy_Key

Point SSH to the Configuration file

oxyum gave us the recipe for using pip with SSH:

pip install git+ssh://git@gitlab.mycorp.com/my_name/my_repo.git

We just need to modify it a bit to make SSH use our new Deploy Key. We do that by pointing SSH to the Host entry in the SSH configuration file. Just replace the ‘gitlab.mycorp.com’ in the command to the host name we used in the SSH configuration file:

pip install git+ssh://git@GitLab/my_name/my_repo.git

The package should now install without any password prompt.

Reference A
Reference B


回答 7

从GitHub安装时,我可以使用:

pip install git+ssh://git@github.com/<username>/<projectname>.git#egg=<eggname>

但是,由于我必须以pip as身份运行sudo,所以SSH密钥不再可与GitHub一起使用,并且“ git clone”在“权限被拒绝(公共密钥)”上失败。使用git+https允许我以sudo的身份运行命令,并让GitHub询问我的用户名/密码。

sudo pip install git+https://github.com/<username>/<projectname>.git#egg=<eggname>

When I was installing from GitHub I was able to use:

pip install git+ssh://git@github.com/<username>/<projectname>.git#egg=<eggname>

But, since I had to run pip as sudo, the SSH keys were not working with GitHub any more, and “git clone” failed on “Permission denied (publickey)”. Using git+https allowed me to run the command as sudo, and have GitHub ask me for my user/password.

sudo pip install git+https://github.com/<username>/<projectname>.git#egg=<eggname>

回答 8

您还可以通过提供登录凭据(登录名和密码,或部署令牌)通过git + https://github.com / … URL 安装私有存储库依赖关系,以使用该文件卷曲.netrc

echo "machine github.com login ei-grad password mypasswordshouldbehere" > ~/.netrc
pip install "git+https://github.com/ei-grad/my_private_repo.git#egg=my_private_repo"

You can also install a private repository dependency via git+https://github.com/… URL by providing login credentials (login and password, or deploy token) for curl with the .netrc file:

echo "machine github.com login ei-grad password mypasswordshouldbehere" > ~/.netrc
pip install "git+https://github.com/ei-grad/my_private_repo.git#egg=my_private_repo"

回答 9

如果要从CI服务器等中的需求文件中安装依赖项,可以执行以下操作:

git config --global credential.helper 'cache'
echo "protocol=https
host=example.com
username=${GIT_USER}
password=${GIT_PASS}
" | git credential approve
pip install -r requirements.txt

就我而言,我使用GIT_USER=gitlab-ci-tokenGIT_PASS=${CI_JOB_TOKEN}

该方法具有明显的优势。您只有一个包含所有依赖项的需求文件。

If you want to install dependencies from a requirements file within a CI server or alike, you can do this:

git config --global credential.helper 'cache'
echo "protocol=https
host=example.com
username=${GIT_USER}
password=${GIT_PASS}
" | git credential approve
pip install -r requirements.txt

In my case, I used GIT_USER=gitlab-ci-token and GIT_PASS=${CI_JOB_TOKEN}.

This method has a clear advantage. You have a single requirements file which contains all of your dependencies.


回答 10

如果您不想使用SSH,则可以在HTTPS URL中添加用户名和密码。

下面的代码假定您在工作目录中有一个包含密码的名为“ pass”的文件。

export PASS=$(cat pass)
pip install git+https://<username>:$PASS@github.com/echweb/echweb-utils.git

If you don’t want to use SSH, you could add the username and password in the HTTPS URL.

The code below assumes that you have a file called “pass” in the working directory that contains your password.

export PASS=$(cat pass)
pip install git+https://<username>:$PASS@github.com/echweb/echweb-utils.git

回答 11

oxyum的解决方案可以解决此问题。我只想指出,如果您使用进行安装,则需要小心,sudo因为密钥也必须存储为root(例如,/root/.ssh)。

然后你可以输入

sudo pip install git+ssh://git@github.com/echweb/echweb-utils.git

oxyum’s solution is OK for this answer. I just want to point out that you need to be careful if you are installing using sudo as the keys must be stored for root too (for example, /root/.ssh).

Then you can type

sudo pip install git+ssh://git@github.com/echweb/echweb-utils.git

回答 12

如果您在GitHub,GitLab等上拥有自己的库/软件包,则必须添加一个标签以提交该库的具体版本,例如v2.0,然后可以安装软件包:

pip install git+ssh://link/name/repo.git@v2.0

这对我有用。其他解决方案对我不起作用。

If you have your own library/package on GitHub, GitLab, etc., you have to add a tag to commit with a concrete version of the library, for example, v2.0, and then you can install your package:

pip install git+ssh://link/name/repo.git@v2.0

This works for me. Other solutions haven’t worked for me.


回答 13

这是一种对我有用的快速方法。只需分叉存储库,并使用您自己的GitHub帐户进行安装即可

pip install git+https://github.com/yourName/repoName

Here’s a quick method that worked for me. Simply fork the repo and install it from your own GitHub account with

pip install git+https://github.com/yourName/repoName

回答 14

只需从原始git clone命令(或从git remote -v)复制遥控器。您将获得如下内容:

  • 位桶: git+ssh://git@bitbucket.org:your_account/my_pro.git

  • 的GitHub: git+ssh://git@github.com:your_account/my_pro.git

接下来,您需要替换:/旁边的域名。

因此,使用以下命令进行安装:

pip install git+ssh://git@bitbucket.org/your_account/my_pro.git

Just copy the remote from the original git clone command (or from git remote -v). You will get something like this:

  • Bitbucket: git+ssh://git@bitbucket.org:your_account/my_pro.git

  • GitHub: git+ssh://git@github.com:your_account/my_pro.git

Next, you need to replace : with / next to the domain name.

So install using:

pip install git+ssh://git@bitbucket.org/your_account/my_pro.git

回答 15

你可以试试

pip install git+git@gitlab.mycorp.com/my_name/my_repo.git

没有ssh:...。这对我行得通。

You may try

pip install git+git@gitlab.mycorp.com/my_name/my_repo.git

without ssh:.... That works for me.


从git repo分支安装pip

问题:从git repo分支安装pip

尝试pip安装仓库的特定分支。Google告诉我

点安装git + https://github.com/user/repo.git@branch

分支的名称是issue/34/oscar-0.6我这样做的,pip install https://github.com/tangentlabs/django-oscar-paypal.git@/issue/34/oscar-0.6但是它返回了404。

如何安装此分支?

Trying to pip install a repo’s specific branch. Google tells me to

pip install git+https://github.com/user/repo.git@branch

The branch’s name is issue/34/oscar-0.6 so I did pip install https://github.com/tangentlabs/django-oscar-paypal.git@/issue/34/oscar-0.6 but its returning a 404.

How do I install this branch?


回答 0

在url前缀之前git+(请参阅VCS支持):

pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6

并指定分支名称,但不要以/。开头。

Prepend the url prefix git+ (See VCS Support):

pip install git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6

And specify the branch name without the leading /.


回答 1

将git +与pip一起使用来克隆存储库可能非常慢(例如,使用https://github.com/django/django@stable/1.6.x进行测试,这将需要几分钟的时间)。我发现与GitHub和BitBucket兼容的最快的东西是:

pip install https://github.com/user/repository/archive/branch.zip

成为django master的对象:

pip install https://github.com/django/django/archive/master.zip

对于django stable / 1.7.x:

pip install https://github.com/django/django/archive/stable/1.7.x.zip

使用BitBucket,它具有相同的可预测模式:

pip install https://bitbucket.org/izi/django-admin-tools/get/default.zip

在这里,master分支通常被命名为default。这将使您的requirements.txt安装速度更快。

其他一些答案提到将要安装的软件包放入您的时所需的变体requirements.txt。请注意,这个档案的语法,领先-e和落后#egg=blah-blah不是必需的,你可以只是简单粘贴URL,所以你requirements.txt的样子:

https://github.com/user/repository/archive/branch.zip

Using pip with git+ to clone a repository can be extremely slow (test with https://github.com/django/django@stable/1.6.x for example, it will take a few minutes). The fastest thing I’ve found, which works with GitHub and BitBucket, is:

pip install https://github.com/user/repository/archive/branch.zip

which becomes for django master:

pip install https://github.com/django/django/archive/master.zip

for django stable/1.7.x:

pip install https://github.com/django/django/archive/stable/1.7.x.zip

With BitBucket it’s about the same predictable pattern:

pip install https://bitbucket.org/izi/django-admin-tools/get/default.zip

Here, the master branch is generally named default. This will make your requirements.txt installing much faster.

Some other answers mention variations required when placing the package to be installed into your requirements.txt. Note that with this archive syntax, the leading -e and trailing #egg=blah-blah are not required, and you can just simply paste the URL, so your requirements.txt looks like:

https://github.com/user/repository/archive/branch.zip

回答 2

使用ssh凭证从专用存储库安装的说明:

$ pip install git+ssh://git@github.com/myuser/foo.git@my_version

Instructions to install from private repo using ssh credentials:

$ pip install git+ssh://git@github.com/myuser/foo.git@my_version

回答 3

只是要添加一个额外的内容,如果要在pip文件中安装它,可以这样添加:

-e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal

但是它将被保存为鸡蛋。

Just to add an extra, if you want to install it in your pip file it can be added like this:

-e git+https://github.com/tangentlabs/django-oscar-paypal.git@issue/34/oscar-0.6#egg=django-oscar-paypal

It will be saved as an egg though.


回答 4

您使用了egg文件的安装过程。该程序支持安装了gitgit+httpgit+httpsgit+sshgit+gitgit+file。其中提到了一些。

可以使用分支,标签或哈希值进行安装是很好的。

@Steve_K指出,使用“ git +”安装可能会很慢,并建议通过zip文件进行安装:

pip install https://github.com/user/repository/archive/branch.zip

或者,建议您使用该.whl文件(如果存在)进行安装。

pip install https://github.com/user/repository/archive/branch.whl

这是一种非常新的格式,比egg文件更新。它需要wheel和setuptools> = 0.8软件包。您可以在这里找到更多。

You used the egg files install procedure. This procedure supports installing over git, git+http, git+https, git+ssh, git+git and git+file. Some of these are mentioned.

It’s good you can use branches, tags, or hashes to install.

@Steve_K noted it can be slow to install with “git+” and proposed installing via zip file:

pip install https://github.com/user/repository/archive/branch.zip

Alternatively, I suggest you may install using the .whl file if this exists.

pip install https://github.com/user/repository/archive/branch.whl

It’s pretty new format, newer than egg files. It requires wheel and setuptools>=0.8 packages. You can find more in here.


回答 5

这就像魅力一样工作:

pip3 install git+https://github.com/deepak1725/fabric8-analytics-worker.git@develop

哪里:

发展:分支

fabric8-analytics-worker.git:回购

deepak1725:用户

This worked like charm:

pip3 install git+https://github.com/deepak1725/fabric8-analytics-worker.git@develop

Where :

develop: Branch

fabric8-analytics-worker.git : Repo

deepak1725: user


Gitsome-增强型Git/GitHub命令行界面(CLI)。GitHub和GitHub企业的官方集成:https://github.com/works-with/category/desktop-tools

一个Official Integration对于GitHub和GitHub Enterprise

为什么gitsome

Git命令行

虽然标准的Git命令行是管理基于Git的repo的一个很好的工具,但是它可以很难记住这个用法地址为:

  • 150多个瓷器和管道命令
  • 无数特定于命令的选项
  • 标签和分支等资源

Git命令行不与GitHub集成,强制您在命令行和浏览器之间切换

gitsome-具有自动完成功能的增压Git/GitHub CLI

gitsome旨在通过专注于以下方面来增强您的标准git/shell界面:

  • 提高易用性
  • 提高工作效率

深度GitHub集成

并不是所有的GitHub工作流都能在终端中很好地工作;gitsome试图将目标对准那些这样做的人

gitsome包括29个与一起使用的GitHub集成命令ALL外壳:

$ gh <command> [param] [options]

gh命令以及Git-Extrashub解锁更多GitHub集成的命令!

带有交互式帮助的Git和GitHub自动完成程序

您可以运行可选壳牌:

 $ gitsome

要启用自动完成交互式帮助对于以下内容:

通用自动补全程序

gitsome自动完成以下内容:

  • Shell命令
  • 文件和目录
  • 环境变量
  • 手册页
  • python

要启用其他自动完成,请查看Enabling Bash Completions部分

鱼式自动建议

gitsome支持鱼式自动建议。使用right arrow完成建议的关键

Python REPL

gitsome由以下人员提供动力xonsh,它支持Python REPL

在shell命令旁边运行Python命令:

附加内容xonsh功能可在xonsh tutorial

命令历史记录

gitsome跟踪您输入的命令并将其存储在~/.xonsh_history.json使用向上和向下箭头键循环查看命令历史记录

可自定义的突出显示

可以控制用于突出显示的ansi颜色,方法是更新~/.gitsomeconfig文件

颜色选项包括:

'black', 'red', 'green', 'yellow',
'blue', 'magenta', 'cyan', 'white'

对于无颜色,请将值设置为Nonewhite在某些终端上可能显示为浅灰色

可用的平台

gitsome适用于Mac、Linux、Unix、Windows,以及Docker

待办事项

并不是所有的GitHub工作流都能在终端中很好地工作;gitsome试图将目标对准那些这样做的人

  • 添加其他GitHub API集成

gitsome才刚刚开始。请随意……contribute!

索引

GitHub集成命令

安装和测试

杂项

GitHub集成命令语法

用法:

$ gh <command> [param] [options]

GitHub集成命令列表

  configure            Configure gitsome.
  create-comment       Create a comment on the given issue.
  create-issue         Create an issue.
  create-repo          Create a repo.
  emails               List all the user's registered emails.
  emojis               List all GitHub supported emojis.
  feed                 List all activity for the given user or repo.
  followers            List all followers and the total follower count.
  following            List all followed users and the total followed count.
  gitignore-template   Output the gitignore template for the given language.
  gitignore-templates  Output all supported gitignore templates.
  issue                Output detailed information about the given issue.
  issues               List all issues matching the filter.
  license              Output the license template for the given license.
  licenses             Output all supported license templates.
  me                   List information about the logged in user.
  notifications        List all notifications.
  octo                 Output an Easter egg or the given message from Octocat.
  pull-request         Output detailed information about the given pull request.
  pull-requests        List all pull requests.
  rate-limit           Output the rate limit.  Not available for Enterprise.
  repo                 Output detailed information about the given filter.
  repos                List all repos matching the given filter.
  search-issues        Search for all issues matching the given query.
  search-repos         Search for all repos matching the given query.
  starred              Output starred repos.
  trending             List trending repos for the given language.
  user                 List information about the given user.
  view                 View the given index in the terminal or a browser.

GitHub集成命令参考:COMMANDS.md

请参阅GitHub Integration Commands Reference in COMMANDS.md对于详细讨论所有GitHub集成命令、参数、选项和示例

请查看下一节,了解快速参考

GitHub集成命令快速参考

配置gitsome

要与GitHub正确集成,您必须首先配置gitsome

$ gh configure

对于GitHub Enterprise用户,使用-e/--enterprise标志:

$ gh configure -e

列表源

列出您的新闻源

$ gh feed

列出用户的活动摘要

查看您的活动订阅源或其他用户的活动订阅源,也可以选择使用寻呼机-p/--pager这个pager option可用于许多命令

$ gh feed donnemartin -p

列出回购的活动提要

$ gh feed donnemartin/gitsome -p

列出通知

$ gh notifications

列出拉式请求

查看您的回购的所有拉式请求:

$ gh pull-requests

过滤问题

查看您提到的所有未决问题:

$ gh issues --issue_state open --issue_filter mentioned

查看所有问题,只筛选分配给您的问题,而不考虑状态(打开、关闭):

$ gh issues --issue_state all --issue_filter assigned

有关过滤和州限定词的更多信息,请访问gh issues参考位置COMMANDS.md

过滤星级报告

$ gh starred "repo filter"

搜索问题和报告

搜索问题

+1最多的搜索问题:

$ gh search-issues "is:open is:issue sort:reactions-+1-desc" -p

评论最多的搜索问题:

$ gh search-issues "is:open is:issue sort:comments-desc" -p

使用“需要帮助”标签搜索问题:

$ gh search-issues "is:open is:issue label:\"help wanted\"" -p

已标记您的用户名的搜索问题@donnemartin

$ gh search-issues "is:issue donnemartin is:open" -p

搜索您所有未解决的私人问题:

$ gh search-issues "is:open is:issue is:private" -p

有关查询限定符的更多信息,请访问searching issues reference

搜索报告

搜索2015年或之后创建的所有Python repos,>=1000星:

$ gh search-repos "created:>=2015-01-01 stars:>=1000 language:python" --sort stars -p

有关查询限定符的更多信息,请访问searching repos reference

列出趋势报告和开发人员

查看趋势回购:

$ gh trending [language] [-w/--weekly] [-m/--monthly] [-d/--devs] [-b/--browser]

查看趋势DEV(目前仅浏览器支持DEV):

$ gh trending [language] --devs --browser

查看内容

这个view命令

查看前面列出的通知、拉取请求、问题、回复、用户等,HTML格式适合您的终端,也可以选择在您的浏览器中查看:

$ gh view [#] [-b/--browser]

这个issue命令

查看问题:

$ gh issue donnemartin/saws/1

这个pull-request命令

查看拉取请求:

$ gh pull-request donnemartin/awesome-aws/2

设置.gitignore

列出所有可用的.gitignore模板:

$ gh gitignore-templates

设置您的.gitignore

$ gh gitignore-template Python > .gitignore

设置LICENSE

列出所有可用的LICENSE模板:

$ gh licenses

设置您的或LICENSE

$ gh license MIT > LICENSE

召唤十月猫

在十月猫那天打电话说出给定的信息或复活节彩蛋:

$ gh octo [say]

查看配置文件

查看用户的配置文件

$ gh user octocat

查看您的个人资料

使用查看您的个人资料gh user [YOUR_USER_ID]命令或使用以下快捷方式:

$ gh me

创建评论、问题和报告

创建评论:

$ gh create-comment donnemartin/gitsome/1 -t "hello world"

创建问题:

$ gh create-issue donnemartin/gitsome -t "title" -b "body"

创建回购:

$ gh create-repo gitsome

选项:在寻呼机中查看

许多gh命令支持-p/--pager在寻呼机中显示结果的选项(如果可用)

用法:

$ gh <command> [param] [options] -p
$ gh <command> [param] [options] --pager

选项:在浏览器中查看

许多gh命令支持-b/--browser在默认浏览器(而不是终端)中显示结果的选项

用法:

$ gh <command> [param] [options] -b
$ gh <command> [param] [options] --browser

请参阅COMMANDS.md有关所有GitHub集成命令、参数、选项和示例的详细列表

记住这些命令有困难吗?看看手边的autocompleter with interactive help来指导您完成每个命令

注意,您可以将gitsome与其他实用程序(如Git-Extras

安装

PIP安装

gitsome托管在PyPI将安装以下命令gitsome

$ pip3 install gitsome

您还可以安装最新的gitsome来自GitHub源,可能包含尚未推送到PyPI的更改:

$ pip3 install git+https://github.com/donnemartin/gitsome.git

如果您没有安装在virtualenv,您可能需要运行sudo

$ sudo pip3 install gitsome

pip3

根据您的设置,您可能还希望运行pip3使用-H flag

$ sudo -H pip3 install gitsome

对于大多数Linux用户来说,pip3可以使用python3-pip套餐

例如,Ubuntu用户可以运行:

$ sudo apt-get install python3-pip

看这个ticket有关更多详细信息,请参阅

虚拟环境安装

您可以将Python包安装在virtualenv要避免依赖项或权限的潜在问题,请执行以下操作

如果您是Windows用户,或者如果您想了解更多有关virtualenv,看看这个guide

安装virtualenvvirtualenvwrapper

$ pip3 install virtualenv
$ pip3 install virtualenvwrapper
$ export WORKON_HOME=~/.virtualenvs
$ source /usr/local/bin/virtualenvwrapper.sh

创建gitsomevirtualenv并安装gitsome

$ mkvirtualenv gitsome
$ pip3 install gitsome

如果pip安装不起作用,您可能默认运行的是Python2。检查您正在运行的Python版本:

$ python --version

如果上面的调用结果是Python 2,请找到Python 3的路径:

$ which python3  # Python 3 path for mkvirtualenv's --python option

如果需要,安装Python 3。调用时设置Python版本mkvirtualenv

$ mkvirtualenv --python [Python 3 path from above] gitsome
$ pip3 install gitsome

如果要激活gitsomevirtualenv稍后再次运行:

$ workon gitsome

要停用gitsomevirtualenv,运行:

$ deactivate

作为Docker容器运行

您可以在Docker容器中运行gitome,以避免安装Python和pip3当地的。要安装Docker,请查看official Docker documentation

一旦安装了docker,您就可以运行gitome:

$ docker run -ti --rm mariolet/gitsome

您可以使用Docker卷让gitome访问您的工作目录、本地的.gitSomeconfig和.gitconfig:

$ docker run -ti --rm -v $(pwd):/src/              \
   -v ${HOME}/.gitsomeconfig:/root/.gitsomeconfig  \
   -v ${HOME}/.gitconfig:/root/.gitconfig          \
   mariolet/gitsome

如果您经常运行此命令,则可能需要定义别名:

$ alias gitsome="docker run -ti --rm -v $(pwd):/src/              \
                  -v ${HOME}/.gitsomeconfig:/root/.gitsomeconfig  \
                  -v ${HOME}/.gitconfig:/root/.gitconfig          \
                  mariolet/gitsome"

要从源构建Docker映像,请执行以下操作:

$ git clone https://github.com/donnemartin/gitsome.git
$ cd gitsome
$ docker build -t gitsome .

启动gitsome

安装后,运行可选的gitsome带有交互式帮助的自动完成程序:

$ gitsome

运行可选的gitsomeShell将为您提供自动完成、交互式帮助、鱼式建议、Python REPL等

正在运行gh命令

运行GitHub集成命令:

$ gh <command> [param] [options]

注意:运行gitsome不需要执行外壳程序gh命令。之后installinggitsome你可以跑gh来自任何shell的命令

运行gh configure命令

要与GitHub正确集成,gitsome必须正确配置:

$ gh configure

针对GitHub企业用户

使用-e/--enterprise标志:

$ gh configure -e

要查看更多详细信息,请访问gh configure部分

启用Bash完成

默认情况下,gitsome查看以下内容locations to enable bash completions

要添加其他bash完成,请更新~/.xonshrc包含bash完成位置的文件

如果~/.xonshrc不存在,请创建它:

$ touch ~/.xonshrc

例如,如果在/usr/local/etc/my_bash_completion.d/completion.bash,将以下行添加到~/.xonshrc

$BASH_COMPLETIONS.append('/usr/local/etc/my_bash_completion.d/completion.bash')

您将需要重新启动gitsome要使更改生效,请执行以下操作

正在启用gh在外部完成制表符gitsome

你可以跑gh外部的命令gitsome外壳完成器。要启用gh此工作流的制表符完成,请将gh_complete.sh本地文件

让bash知道可以完成gh当前会话中的命令:

$ source /path/to/gh_complete.sh

要为所有终端会话启用制表符完成,请将以下内容添加到您的bashrc文件:

source /path/to/gh_complete.sh

重新加载您的bashrc

$ source ~/.bashrc

提示:.是的缩写source,因此您可以改为运行以下命令:

$ . ~/.bashrc

对于Zsh用户

zsh包括与bash完成兼容的模块

下载gh_complete.sh文件,并将以下内容附加到您的.zshrc

autoload bashcompinit
bashcompinit
source /path/to/gh_complete.sh

重新加载您的zshrc

 $ source ~/.zshrc

可选:安装PILPillow

将化身显示为gh megh user命令需要安装可选的PILPillow依赖性

Windows*和Mac:

$ pip3 install Pillow

*请参阅Windows Support有关化身限制的部分

Ubuntu用户,看看这些instructions on askubuntu

支持的Python版本

  • Python 3.4
  • Python 3.5
  • Python 3.6
  • Python 3.7

gitsome由以下人员提供动力xonsh,它当前不支持Python2.x,如本文中所讨论的ticket

支持的平台

  • Mac OS X
    • 在OS X 10.10上测试
  • Linux、Unix
    • 在Ubuntu 14.04 LTS上测试
  • 窗口
    • 在Windows 10上测试

Windows支持

gitsome已在Windows 10上进行了测试,cmdcmder

虽然您可以使用标准的Windows命令提示符,但使用这两种命令提示符都可能会有更好的体验cmderconemu

纯文本化身

命令gh usergh me将永远拥有-t/--text_avatar标志已启用,因为img2txt不支持Windows上的ANSI头像

配置文件

在Windows上,.gitsomeconfig 文件可在以下位置找到%userprofile%例如:

C:\Users\dmartin\.gitsomeconfig

开发人员安装

如果您有兴趣为gitsome,请运行以下命令:

$ git clone https://github.com/donnemartin/gitsome.git
$ cd gitsome
$ pip3 install -e .
$ pip3 install -r requirements-dev.txt
$ gitsome
$ gh <command> [param] [options]

pip3

如果您在安装时收到一个错误,提示您需要Python 3.4+,这可能是因为您的pip命令是为旧版本的Python配置的。要解决此问题,建议安装pip3

$ sudo apt-get install python3-pip

看这个ticket有关更多详细信息,请参阅

持续集成

有关持续集成的详细信息,请访问Travis CI

单元测试和代码覆盖率

在活动的Python环境中运行单元测试:

$ python tests/run_tests.py

使用运行单元测试tox在多个Python环境中:

$ tox

文档

源代码文档将很快在Readthedocs.org请查看source docstrings

运行以下命令构建文档:

$ scripts/update_docs.sh

贡献

欢迎投稿!

回顾Contributing Guidelines有关如何执行以下操作的详细信息,请执行以下操作:

  • 提交问题
  • 提交拉式请求

学分

联系信息

请随时与我联系,讨论任何问题、问题或评论

我的联系信息可以在我的GitHub page

许可证

我在开放源码许可下向您提供此存储库中的代码和资源。因为这是我的个人存储库,您获得的我的代码和资源的许可证来自我,而不是我的雇主(Facebook)

Copyright 2016 Donne Martin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.