我试着用pipenv。我运行命令pip install pipenv,运行成功:

...
Successfully built pipenv pathlib shutilwhich pythonz-bd virtualenv-clone
Installing collected packages: virtualenv, pathlib, shutilwhich, backports.shutil-get-terminal-size, pythonz-bd, virtualenv-clone, pew, first, six, click, pip-tools, certifi, chardet, idna, urllib3, requests, pipenv
...

但是,当我在一个新的根项目目录中运行命令pipenv install时,我收到以下消息:-bash: pipenv: command not found。我怀疑我可能需要修改我的.bashrc,但我不清楚该向文件中添加什么,或者修改是否有必要。


当前回答

发生这种情况是因为您没有在全局(系统范围)安装它。为了让它在你的路径中可用,你需要使用sudo安装它,就像这样:

$ sudo pip install pipenv

其他回答

在这种情况下,您只需要将二进制路径添加到bash中。如果你正在使用ZSH,例如,你需要编辑。ZSHRC文件作为admind,然后在上面的评论中添加@charlax提到的代码:

PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"

对于那些使用sudo pip3安装它的pipenv,则需要使用python3 -m pipenv shell或python3.9 -m pipenv shell

发生这种情况是因为您没有在全局(系统范围)安装它。为了让它在你的路径中可用,你需要使用sudo安装它,就像这样:

$ sudo pip install pipenv

如何使pipenv一个基本命令

使用Python3的Pipenv需要以“$ python -m Pipenv[命令]”或“$ Python3 -m Pipenv[命令]”的方式运行;开头的"python"命令根据你在shell中激活python的方式而有所不同。修复并设置为"$ pipenv[命令]":[Git Bash中的示例]

$ cd ~
$ code .bash_profile

第一行是必要的,因为它允许您访问.bash_profile文件。第二行在VSCode中打开.bash_profile,因此插入默认代码编辑器的命令。 在这一点上,你会想要(在.bash_profile中)编辑文件,添加这行代码:

alias pipenv='python -m pipenv'

然后保存文件并在Git Bash中输入:

$ source .bash_profile

然后你可以在任何地方使用pipenv作为命令,例如: $ pipenv shell 将工作。

这种使用方法适用于在Git Bash中创建命令。例如:

alias python='winpty python.exe'

在.bash_profile中输入: $ source .bash_profile 将允许Python以“Python”的形式运行。

不客气

在旧pip版本的某些情况下:

sudo easy_install pip
sudo pip install pipenv