Python Pipenv:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46391721/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 17:36:19  来源:igfitidea点击:

Pipenv: Command Not Found

pythonpython-3.xpippipenv

提问by lgants

I'm new to Python development and attempting to use pipenv. I ran the command pip install pipenv, which ran successfully:

我是 Python 开发的新手并尝试使用 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
...

However, when I run the command pipenv installin a fresh root project directory I receive the following message: -bash: pipenv: command not found. I suspect that I might need to modify my .bashrc, but I'm unclear about what to add to the file or if modification is even necessary.

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

采纳答案by dethos

That happens because you are not installing it globally (system wide). For it to be available in your pathyou need to install it using sudo, like this:

发生这种情况是因为您没有在全局(系统范围内)安装它。要使其在您的应用程序中可用,您path需要使用 安装它sudo,如下所示:

$ sudo pip install pipenv

回答by tuan ly

This fixed it for me:

这为我修复了它:

sudo -H pip install -U pipenv

回答by charlax

If you've done a user installation, you'll need to add the right folder to your PATHvariable.

如果您已完成用户安装,则需要将正确的文件夹添加到您的PATH变量中。

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

See pipenv's installation instructions

pipenv的安装说明

回答by user9563571

I tried this:

我试过这个:

python -m pipenv # for python2

python -m pipenv # for python2

python3 -m pipenv # for python3

python3 -m pipenv # for python3

Hope this can help you.

希望这可以帮到你。

回答by John Pang

I have same problem with pipenvon Mac OS X 10.13 High Seirra, another Mac works just fine. I use Heroku to deploy my Django servers, some in 2.7 and some in 3.6. So, I need both 2.7 and 3.6. When HomeBrew install Python, it keeps pythonpoints to original 2.7, and python3points to 3.6.

pipenv在 Mac OS X 10.13 High Seirra 上有同样的问题,另一台 Mac 工作得很好。我使用 Heroku 来部署我的 Django 服务器,一些在 2.7 中,一些在 3.6 中。所以,我需要 2.7 和 3.6。HomeBrew 安装 Python 时,保持python指向原来的 2.7,python3指向 3.6。

The problem might due to $ pip install pipenv. I checked /usr/local/bin and pipenv isn't there. So, I tried a full uninstall:

问题可能是由于$ pip install pipenv. 我检查了 /usr/local/bin 并且 pipenv 不在那里。所以,我尝试了完全卸载:

$ pip uninstall pipenv

Cannot uninstall requirement pipenv, not installed
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

$ pip3 uninstall pipenv
Skipping pipenv as it is not installed.

Then reinstall and works now:

然后重新安装并立即工作:

$ pip3 install pipenv
Collecting pipenv

回答by Claudio Santos

OSX GUYS, OVER HERE!!!

OSX 伙计们,在这里!!!

As @charlax answered (for me the best one), you can use a more dynamic command to set PATH, buuut for mac users this could not work, sometimes your USER_BASE path got from site is wrong, so you need to find out where your python installation is.

正如@charlax 回答的那样(对我来说是最好的),您可以使用更动态的命令来设置 PATH,但对于 mac 用户来说这不起作用,有时您从站点获得的 USER_BASE 路径是错误的,因此您需要找出您的位置python安装是。

$ which python3
/usr/local/bin/python3.6

you'll get a symlink, then you need to find the source's symlink.

你会得到一个符号链接,然后你需要找到源的符号链接。

$ ls -la /usr/local/bin/python3.6
  lrwxr-xr-x  1 root  wheel  71 Mar 14 17:56 /usr/local/bin/python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

(this ../../../means root)

(这../../../意味着根)

So you found the python path (/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6), then you just need to put in you ~/.bashrc as follows:

所以你找到了python路径( /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6),那么你只需要把你的 ~/.bashrc 如下:

export PATH="$PATH:/Library/Frameworks/Python.framework/Versions/3.6/bin"

export PATH="$PATH:/Library/Frameworks/Python.framework/Versions/3.6/bin"

回答by Hanxue

Where Python store packages

Python 存储包的地方

Before jumping into the command that will install pipenv, it is worth understanding where pipinstalls Python packages.

在进入将安装的命令之前pipenv,有必要了解pipPython 包的安装位置

Global site-packagesis where Python installs packages that will be available to all users and all Python applications on the system. You can check the global site package with the command

全局站点包是 Python 安装包的地方,这些包可供系统上的所有用户和所有 Python 应用程序使用。可以使用命令查看全局站点包

python -m site

For example, on Linux with Python 3.7 the path is usually

例如,在使用 Python 3.7 的 Linux 上,路径通常是

/usr/lib/python3.7/dist-packages/setuptools

User site-packagesis where Python installs packages available only for you. But the packages will still be visible to all Python projects that you create. You can get the path with

用户站点包是 Python 安装仅供您使用的包的地方。但是这些包仍然对您创建的所有 Python 项目可见。你可以得到路径

python -m site --user-base

On Linux with Python 3.7 the path is usually

在使用 Python 3.7 的 Linux 上,路径通常是

~/.local/lib/python3.7/site-packages

Using Python 3.x

使用 Python 3.x

On most Linux and other Unices, usually Python 2 and Python 3 is installed side-by-side. The default Python 3 executable is almost always python3. pipmay be available as either of the following, depending on your Linux distribution

在大多数 Linux 和其他 Unices 上,通常 Python 2 和 Python 3 是并行安装的。默认的 Python 3 可执行文件几乎总是python3. pip根据您的 Linux 发行版,可以作为以下任何一种使用

pip3
python3-pip
python36-pip
python3.6-pip

Linux

Linux

Avoid using pipwith sudo! Yes, it's the most convenient way to install Python packages and the executable is available at /usr/local/bin/pipenv, but it also mean that specific package is always visible for all users, and all Python projects that you create. Instead, use per-user site packages instead with --user

避免pipsudo! 是的,这是安装 Python 包的最便捷方式,可执行文件位于/usr/local/bin/pipenv,但这也意味着特定包始终对所有用户以及您创建的所有 Python 项目可见。相反,使用每个用户的站点包代替--user

pip3 install --user pipenv

pipenvis available at

pipenv可在

~/.local/bin/pipenv

macOS

苹果系统

On macOS, Homebrew is the recommended way to install Python. You can easily upgrade Python, install multiple versions of Python and switch between versions using Homebrew.

在 macOS 上,Homebrew 是安装 Python 的推荐方式。您可以使用 Homebrew 轻松升级 Python、安装多个版本的 Python 以及在版本之间切换。

If you are using Homebrew'ed Python, pip install --useris disabled. The global site-package is located at

如果您使用的是 Homebrew 的 Python,pip install --user则禁用。全局站点包位于

/usr/local/lib/python3.y/site-packages

and you can safely install Python packages here. Python 3.y also searches for modules in:

你可以在这里安全地安装 Python 包。Python 3.y 还会在以下位置搜索模块:

 /Library/Python/3.y/site-packages
 ~/Library/Python/3.y/lib/python/site-packages

Windows

视窗

For legacy reasons, Python is installed in C:\Python37. The Python executable is usually named py.exe, and you can run pipwith py -m pip.

出于遗留原因,Python 安装在C:\Python37. Python 可执行文件通常命名为py.exe,您可以pip使用py -m pip.

Global site packages is installed in

全局站点包安装在

C:\Python37\lib\site-packages

Since you don't usually share your Windows devices, it is also OK to install a package globally

由于您通常不共享您的 Windows 设备,因此也可以全局安装一个包

py -m pip install pipenv

pipenvis now available at

pipenv现在可以在

C:\Python37\Scripts\pipenv.exe

I don't recommend install Python packages in Windows with --user, because the default user site-package directory is in your Windows roaming profile

我不建议在 Windows 中安装 Python 包--user,因为默认用户 site-package 目录在你的 Windows 漫游配置文件中

C:\Users\user\AppData\Roaming\Python\Python37\site-packages 

The roaming profile is used in Terminal Services (Remote Desktop, Citrix, etc) and when you log on / off in a corporate environment. Slow login, logoff and reboot in Windows can be caused by a large roaming profile.

漫游配置文件用于终端服务(远程桌面、Citrix 等)以及您在公司环境中登录/注销时。在 Windows 中登录、注销和重新启动缓慢可能是由大型漫游配置文件引起的。

回答by NetRay

Installing pipenv globally can have an adverse effect by overwriting the global/system-managed pip installation, thus resulting in import errors when trying to run pip.

通过覆盖全局/系统管理的 pip 安装,全局安装 pipenv 可能会产生不利影响,从而在尝试运行 pip 时导致导入错误。

You can install pipenv at the user level:

您可以在用户级别安装 pipenv:

pip install --user pipenv

pip install --user pipenv

This should install pipenv at a user-level in /home/username/.local so that it does not conflict with the global version of pip. In my case, that still did not work after running the '--user' switch, so I ran the longer 'fix what I screwed up' command once to restore the system managed environment:

这应该在 /home/username/.local 中的用户级别安装 pipenv,以便它不会与 pip 的全局版本冲突。在我的情况下,在运行“--user”开关后仍然不起作用,所以我运行了一次更长的“修复我搞砸的”命令来恢复系统管理环境:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

^ found here: Error after upgrading pip: cannot import name 'main'

^ 在此处找到:升级 pip 后出错:无法导入名称“main”

and then did the following:

然后做了以下事情:

mkdir /home/username/.local... if it doesn't already exist

mkdir /home/username/.local...如果它不存在

export PYTHONUSERBASE=/home/username/.local

export PYTHONUSERBASE=/home/username/.local

Make sure the export took effect (bit me once during this process):

确保导出生效(在此过程中咬我一次):

echo $PYTHONUSERBASE

echo $PYTHONUSERBASE

Then, I ran the pip install --user pipenvand all was well. I could then run pipenv from the CLI and it did not overwrite the global/system-managed pip module. Of course, this is specific to the user so you want to make sure you install pipenv this way while working as the user you wish to use pipenv.

然后,我跑了pip install --user pipenv,一切都很好。然后我可以从 CLI 运行 pipenv 并且它没有覆盖全局/系统管理的 pip 模块。当然,这是特定于用户的,因此您要确保在以希望使用 pipenv 的用户身份工作时以这种方式安装 pipenv。

References:

参考:

https://pipenv.readthedocs.io/en/latest/diagnose/#no-module-named-module-namehttps://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenvhttps://pip.pypa.io/en/stable/user_guide/#user-installs

https://pipenv.readthedocs.io/en/latest/diagnose/#no-module-named-module-name https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv https://pip.pypa.io/en/stable/user_guide/#user-installs

回答by podenborg

After installing pipenv (sudo pip install pipenv), I kept getting the "Command Not Found" error when attempting to run the pipenv shellcommand.

安装 pipenv ( sudo pip install pipenv) 后,我在尝试运行pipenv shell命令时不断收到“未找到命令”错误。

I finally fixed it with the following code:

我终于用以下代码修复了它:

pip3 install pipenv
pipenv shell

回答by Michael Coxon

On Mac OS X Catalina it appears to follow the Linux path. Using any of:

在 Mac OS X Catalina 上,它似乎遵循 Linux 路径。使用以下任何一种:

pip install pipenv
pip3 install pipenv
sudo pip install pipenv
sudo pip3 install pipenv

Essentially installs pipenv here:

基本上在这里安装 pipenv:

/Users/mike/Library/Python/3.7/lib/python/site-packages/pipenv

But its not the executable and so is never found. The only thing that worked for me was

但它不是可执行文件,因此从未找到。唯一对我有用的是

pip install --user pipenv

This seems to result in an __init__.pyfile in the above directory that has contents to correctly expose the pipenvcommand.

这似乎导致__init__.py上述目录中的文件具有正确公开pipenv命令的内容。

and everything started working, when all other posted and commented suggestions on this question failed.

当所有其他发布和评论的关于这个问题的建议都失败时,一切都开始工作了。

The pipenv package certainly seems quite picky.

pipenv 包当然看起来很挑剔。