标签归档:pipenv

Pipenv:找不到命令

问题:Pipenv:找不到命令

我是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
...

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

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

...
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 install in 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.


回答 0

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

$ sudo pip install pipenv

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

$ sudo pip install pipenv

回答 1

这为我解决了:

sudo -H pip install -U pipenv

This fixed it for me:

sudo -H pip install -U pipenv

回答 2

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

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

看到 pipenv的安装说明

If you’ve done a user installation, you’ll need to add the right folder to your PATH variable.

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

See pipenv’s installation instructions


回答 3

我尝试了这个:

python -m pipenv # for python2

python3 -m pipenv # for python3

希望这可以帮到你。

I tried this:

python -m pipenv # for python2

python3 -m pipenv # for python3

Hope this can help you.


回答 4

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。

问题可能是由于$ 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.

然后重新安装即可立即使用:

$ pip3 install pipenv
Collecting pipenv

I have same problem with pipenv on 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 python points to original 2.7, and python3 points to 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 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

回答 5

OSX的家伙,在这里!!!

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

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

您将获得一个符号链接,然后需要找到源的符号链接。

$ 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

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

因此,您找到了python路径(/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6),然后只需将〜/ .bashrc放入其中,如下所示:

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

OSX GUYS, OVER HERE!!!

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.

$ 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:

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


回答 6

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

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

pip install --user pipenv

这应该在/home/username/.local中的用户级别安装pipenv,以使其与pip的全局版本不冲突。就我而言,在运行’–user’开关后仍然无法正常工作,因此我运行了更长的“修复我搞砸的东西”命令一次,以恢复系统管理的环境:

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

^在这里找到:升级pip后出错:无法导入名称’main’

然后执行以下操作:

mkdir /home/username/.local …如果还不存在

export PYTHONUSERBASE=/home/username/.local

确保导出生效(在此过程中,只对我进行一次咬合):

echo $PYTHONUSERBASE

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

参考文献:

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/zh_CN/stable/user_guide/#user-installs

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.

You can install pipenv at the user level:

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:

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

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

and then did the following:

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

export PYTHONUSERBASE=/home/username/.local

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

echo $PYTHONUSERBASE

Then, I ran the pip install --user pipenv and 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.

References:

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


回答 7

Python存储包的位置

在进入将要安装的命令之前pipenv,值得了解pip Python软件包的安装位置

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

python -m site

例如,在具有Python 3.7的Linux上,路径通常是

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

用户站点软件包是Python安装仅对您可用的软件包的地方。但是,这些包对您创建的所有Python项目仍然可见。您可以使用以下方法

python -m site --user-base

在具有Python 3.7的Linux上,路径通常是

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

使用Python 3.x

在大多数Linux和其他Unices上,通常并行安装Python 2和Python 3。默认的Python 3可执行文件几乎总是python3pip根据您的Linux发行版本,可能提供以下任一版本

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

的Linux

避免pipsudo!是的,这是安装Python软件包的最方便的方法,可执行文件位于/usr/local/bin/pipenv,但也意味着特定的软件包始终对所有用户和您创建的所有Python项目可见。而是使用按用户站点包,而不是--user

pip3 install --user pipenv

pipenv 在以下位置可用

~/.local/bin/pipenv

苹果系统

在macOS上,建议使用Homebrew来安装Python。您可以轻松升级Python,安装多个版本的Python,以及使用Homebrew在版本之间切换。

如果您使用的是自制软件的Python,则已pip install --user禁用。全局站点包位于

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

并且您可以在此处安全地安装Python软件包。Python 3.y还在以下位置搜索模块:

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

视窗

出于传统原因,Python安装在中C:\Python37。Python可执行文件通常被命名为py.exe,并且可以pip使用来运行py -m pip

全局站点包安装在

C:\Python37\lib\site-packages

由于通常不共享Windows设备,因此也可以在全局范围内安装软件包

py -m pip install pipenv

pipenv 现在可以在

C:\Python37\Scripts\pipenv.exe

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

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

在终端服务(远程桌面,Citrix等)中以及在公司环境中登录/注销时,将使用漫游配置文件。大型漫游配置文件可能导致Windows中缓慢的登录,注销和重新启动。

Where Python store packages

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

Global site-packages is 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 -m site

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

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

User site-packages is 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 -m site --user-base

On Linux with Python 3.7 the path is usually

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

Using 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. pip may be available as either of the following, depending on your Linux distribution

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

Linux

Avoid using pip with 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

pip3 install --user pipenv

pipenv is available at

~/.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.

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

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

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

 /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 pip with 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

py -m pip install pipenv

pipenv is now available at

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

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.


回答 8

我已将其固定为:

sudo -H pip install -U pipenv

This is fixed for me to:

sudo -H pip install -U pipenv

回答 9

安装pipenv(sudo pip install pipenv)后,尝试运行Windows XP时,始终出现“找不到命令”错误pipenv shell命令。

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

pip3 install pipenv
pipenv shell

After installing pipenv (sudo pip install pipenv), I kept getting the “Command Not Found” error when attempting to run the pipenv shell command.

I finally fixed it with the following code:

pip3 install pipenv
pipenv shell

回答 10

您可以考虑pipenv通过安装pipsi

curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get -pipsi.py | python3
pipsi install pew
pipsi install pipenv

不幸的是有一些问题与写作时的MacOS + python3,看到12。就我而言,我必须将bashprompt更改为#!/Users/einselbst/.local/venvs/pipsi/bin/python

You might consider installing pipenv via pipsi.

curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get -pipsi.py | python3
pipsi install pew
pipsi install pipenv

Unfortunately there are some issues with macOS + python3 at the time of writing, see 1, 2. In my case I had to change the bashprompt to #!/Users/einselbst/.local/venvs/pipsi/bin/python


回答 11

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

sudo easy_install pip
sudo pip install pipenv

In some cases of old pip version:

sudo easy_install pip
sudo pip install pipenv

回答 12

对于Windows用户,这可能是由于与virtualenv的安装冲突。对我来说,它在我先卸载virtualenv和pipenv,然后仅安装pipenv时起作用。

pip uninstall virtualenv
pip uninstall pipenv
pip install pipenv

现在pipenv install xxx为我工作

For window users this may be due to conflicting installation with virtualenv. For me it worked when I uninstalled virtualenv and pipenv first, and then install only pipenv.

pip uninstall virtualenv
pip uninstall pipenv
pip install pipenv

Now pipenv install xxx worked for me


回答 13

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

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

本质上在这里安装pipenv:

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

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

pip install --user pipenv

这似乎导致__init__.py上述目录中的文件包含正确显示pipenv命令的内容。

当有关此问题的所有其他发布和评论建议都失败时,一切都开始起作用。

pipenv软件包当然看起来很挑剔。

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

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

Essentially installs pipenv here:

/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__.py file in the above directory that has contents to correctly expose the pipenv command.

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

The pipenv package certainly seems quite picky.