pipenv: Homebrew installation broken on Python < 3.7

This is probably related to #2296, but I’m currently unable to upgrade pipenv past 2018.6.25 using Homebrew.

I have my Python pinned at 3.6.5 with brew switch python 3.6.5_1 && brew pin python

Because of this I have to --build-from-source for any upgrade to a brew-installed package that depends on python as the bottles are built on Python 3.7.

After brew upgrade pipenv --build-from-source I get the following error:

pipenv --help
Traceback (most recent call last):
  File "/usr/local/Cellar/pipenv/2018.10.9/libexec/bin/pipenv", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/local/Cellar/pipenv/2018.10.9/libexec/lib/python3.6/site-packages/pkg_resources/__init__.py", line 26, in <module>
    import zipfile
ModuleNotFoundError: No module named 'zipfile'

Switching back to 2018.6.25 resolves the issue, but it’d be nice to get on the latest version.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 16 (4 by maintainers)

Most upvoted comments

Thanks @amancevice 😃 I finally managed to make it work with pipenv. For documentation here are the steps:

  • brew uninstall pipenv
  • brew install pipenv
  • brew install python 3.6.4_4
  • Create a symlink ln -s /usr/local/Cellar/python/3.6.4_4/bin/python3 /usr/local/opt/python/bin/python3.6 because pipenv will ttry to find it here…
  • now use the destructive command pipenv shell --python /usr/local/Cellar/python/3.6.4_4/bin/python3 a new virtualenv will be created
  • You can now use pipenv cli pipenv shell or pipenv install with the python 3.6 version

@amancevice In my case I did not have to use pyenv. The only annoying thing is that you need to find where brew will install python distribution.

Closing since there isn’t really anything to track in this repo. Feel free to reopen (or raise a new issue) if cooperation from us is needed to resolve this issue.

I don’t believe any of the maintainers contribute to the Homebrew formula. We try to fix things when they are broken, but none of us have much more stake in the formula than, say, you do.

I do have some personal experience with Homebrew, and your walkthrough does help explain things a lot. Thanks! Based on the above information, I feel your patch to the post-install hook makes sense. It makes things better in certain situations (i.e. yours), and does not break existing situations. Unfortunately, we don’t really have a say on this topic; you’ll need to convince the Homebrew maintainers to get it in 😦

OK, I’ve isolated the problem to this line in post_install:

inreplace lib_python_path/"orig-prefix.txt",
          Formula["python"].opt_prefix, Formula["python"].prefix.realpath

If I understand correctly, this line is replacing text in the file lib_python_path/"orig-prefix.txt"; specifically its replacing the value of Formula["python"].opt_prefix with the value of Formula["python"].prefix.realpath.

The problem is that Formula["python"].prefix.realpath points to 3.7.0 (or whatever the current version of the python formula is) and not my linked 3.6.5.

@ebb-earl-co if you’re luck it’ll be as simple as:

brew switch pipenv 2018.6.25

Typing brew switch pipenv by itself will show you all the versions you have installed. These get cleaned up on brew cleanup so if you run a tight ship it’s probably long gone.

If it’s gone you’ll have to rewind your Homebrew tap to when it was the latest version. You can do this using the same logic as above for Python, but you’ll need to find the correct checksum by grepping the logs. I’ll walk you through it:

# Update brew (it's a good idea to always do this when beginning work on Homebrew)
brew update

# Navigate to the core repository
cd $(brew --repo homebrew/core)

# Search the log for checksum at `pipenv 2018.6.25`
git log --oneline | grep 'pipenv 2018.6.25'

# The checksum snippet is `9e1733c5c`

# Checkout the pipenv formula at this point in history
git checkout 9e1733c5c ./Formula/pipenv.rb

# Try installing the formula with
brew install pipenv

# If that doesn't work it might be because the package was bottled for a different Python version
# Try this:
brew install pipenv --build-from-source

# Fix your homebrew tap
git reset @ ./Formula/pipenv.rb
git checkout ./Formula/pipenv.rb

Be sure to pin your pipenv to prevent unwanted upgrades with brew pin pipenv.