Pipx: homebrew?

Created on 3 Jan 2019  ·  24Comments  ·  Source: pipxproject/pipx

would you consider making a homebrew formula? that might make installation simpler on macOS. a homebrew formula for a python app will be contained within its own virtualenv

Most helpful comment

Merged! https://github.com/Homebrew/homebrew-core/commit/e3e53ec6baac499fc7679199cfbe140e9e6559cd

Please run brew install pipx to try it out.

@cs01 next step will be updating the readme to add brew install pipx for macOS and updating your make publish command. I'll use @sloria's release_homebrew script as a base.

PRs to come!

All 24 comments

I am planning on making a pipx-bootstrap package on PyPI to avoid the curl method (https://github.com/cs01/pipx/issues/44).

I think the hardest part of the installation is modifying the PATH and opening a new terminal. What do you think would be made easier by moving to brew?

Just saw this thread... To your question @cs01 what are the benefits of moving to brew: Beeing able to install something with brew means its all in the same package manager: E.g. you can list all your installed packages making it easier to migrate to a new machine.

ps: Thanks for pipx. It's awsome!

Thank you!

I have no objection to someone adding it to brew, but I won’t be able to take that on myself. Also note that standard installation is now more straightforward with just “pip install pipx” so if you add it to brew there is no need for the bootstrap command.

The advantage of a Homebrew installer would be that pipx could be installed in /usr/local/bin/pipx with the other homebrew-installed binaries.

Currently, if you install pipx is installed using Homebrew-installed python3:

python3 -m pip install --user pipx

The pipx binary gets installed to $HOME/Library/Python/3.7/bin/pipx, which isn't in $PATH by default.

I'm currently working around this by installing pipx with pipx...

python3 -m pip install --user pipx
python3 -m pipx install pipx

And ensuring that $HOME/.local/bin is at the front of $PATH:

export PATH="$HOME/.local/bin:$PATH"

It's fairly straightforward to create a Homebrew formula from a Python package. Here's the formula for doitlive: https://github.com/Homebrew/homebrew-core/blob/master/Formula/doitlive.rb .

I then use this script to update the Homebrew formula after I make a PyPI release: https://github.com/sloria/doitlive/blob/dev/release_homebrew.sh

@cs01 Would you be up for adding this to your release workflow?

PR's welcome to build it into the publish target of the makefile. That way I can keep running the same command, and homebrew will be updated.

hi @sloria do you want to submit a PR for adding this to homebrew or should I take a stab at it?

@cs01 The biggest reason as far as I can tell is that the second command in the README: pipx ensurepath will fail if $HOME/.local/bin isn't already in the PATH.

It's a circular dependency

Could you explain more about what the issue with pipx ensurepath is? Maybe the homebrew formula could have the equivalent of pipx ensurepath built into it?

Btw, not sure if this is relevant, but pipx no longer installs itself to $HOME/.local/bin, it just installs itself to site-packages.

Not sure if this is related but the instructions in the pipx README.md say to use pip install --user pipx.

If you are using HomeBrew built Python the --user argument is disabled due to a bug in distuils.
https://docs.brew.sh/Homebrew-and-Python

@iain2k thanks for sharing! pipx technically does not require a --user install. I wrote that because I thought it would get around common issues on mac and avoid polluting the global environment.

For anyone else reading, I would like to set expectations on this appropriately: I welcome having pipx on homebrew but want to completely rely on someone owning the pipx/homebrew experience.

I want my involvement to be make publish (as it currently is). Any homebrew issues that come up would be owned by someone else. Is anyone interested in volunteering for this?

re:

Btw, not sure if this is relevant, but pipx no longer installs itself to $HOME/.local/bin, it just installs itself to site-packages.

Right, so the README states to run pip install --user pipx which means it will get installed in $HOME/.local/bin. If the user doesn't already have this in their PATH, the next command, pipx ensurepath would fail


re: automatically running ensurepath
I believe homebrew has a strict policy against modifying a user's shell profile automatically so pipx ensurepath cannot be done there. The general practice is to list it under the "Caveats" which is printed at install time. This is similar to how pip install --user pipx works right now where a warning is printed if the $HOME/.local/bin is not in the PATH.

The experience would be identical in terms of the printed warning except for the fact that the pipx tool is guaranteed to be on the PATH via homebrew. This way, the pipx ensurepath command or pipx --help etc. will always work.

If the user missess the caveat to add $HOME/.local/bin the first time, running any pipx command can notify them to do so since pipx is guaranteed to be in the PATH.


re: maintainance

yep, if @sloria doesn't want it, I'll volunteer to maintain. I use the tool a fair amount and I've been evangalizing it at work. would love to add support for homebrew since we install the majority of our CLI tools in this way.

@AlJohri All yours--I won't have time to work on this.

which means it will get installed in $HOME/.local/bin

Is this true? On my computer it installs to ~/Library/Python/VERSION/bin

What does

python -c "import site; print(site.USER_BASE + '/bin')"

output for you?


re: automatically running ensurepath

I will defer to you to work through those details and dogfood them on your coworkers 😄


I'll volunteer to maintain. I use the tool a fair amount and I've been evangalizing it at work. would love to add support for homebrew since we install the majority of our CLI tools in this way.

Nice, thanks so much!

@cs01 you got it! 😄

Is this true?

My default python installed via asdf (similar to pyenv) has path of ~/.local/bin. Homebrew python has path of: ~Library/Python/3.7/bin (this folder does not exist).

asdf python

$ asdf list
nodejs
  11.10.0
  11.5.0
python
  2.7.15
  3.7.2
ruby
  2.5.3

$ which python
/Users/al/.asdf/shims/python

$ python --version
Python 3.7.2

$ python -c "import site; print(site.USER_BASE + '/bin')"
/Users/al/.local/bin

homebrew python

$ /usr/local/bin/python3 -c "import site; print(site.USER_BASE + '/bin')"
/Users/al/Library/Python/3.7/bin

$ stat /Users/al/Library/Python/3.7/bin
stat: /Users/al/Library/Python/3.7/bin: stat: No such file or directory

Screen Shot 2019-04-13 at 1 37 14 AM

ran into an issue where pipx ensurepath can see the PATH is set properly but pipx install <package> doesn't when installed via my test homebrew formula.

will work through debugging but just throwing this here in case its immediately obvious to someone

I think I've identified the issue. ~Homebrew requires creating an isolated virtualenv for any python app.~ For some reason, creating a venv as pipx does, when it is already inside a virtualenv, has odd behavior.

The two virtualenvs (the homebrew isolated virtualenv for pipx) and the venv that pipx creates for a single package become linked.

Looking for a way around this...

Got it working. Solution was to not use hombrew's virtualenv creation mechanism. Here's the pull request: https://github.com/Homebrew/homebrew-core/pull/39020

Merged! https://github.com/Homebrew/homebrew-core/commit/e3e53ec6baac499fc7679199cfbe140e9e6559cd

Please run brew install pipx to try it out.

@cs01 next step will be updating the readme to add brew install pipx for macOS and updating your make publish command. I'll use @sloria's release_homebrew script as a base.

PRs to come!

Nice, thanks!

I just tried running brew install pipx but got Error: No available formula with the name "pipx".

@cs01 try running brew update and then brew install pipx? maybe you have export HOMEBREW_NO_AUTO_UPDATE=1 set so it didn't automatically update

lol wait nevermind, there was a small issue! https://github.com/Homebrew/homebrew-core/pull/39483

should be good momentarily, I'll post here when its merged.

On macOS, as stated by some earlier, I had to

export PATH=$HOME/Library/Python/3.7/bin:$PATH

To make the command pipx work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pawamoy picture pawamoy  ·  9Comments

floatingpurr picture floatingpurr  ·  5Comments

castarco picture castarco  ·  3Comments

alexey-tereshenkov-oxb picture alexey-tereshenkov-oxb  ·  5Comments

z0rc picture z0rc  ·  10Comments