packer.nvim icon indicating copy to clipboard operation
packer.nvim copied to clipboard

Luarocks fails to install on macOS BigSur

Open akinsho opened this issue 3 years ago • 26 comments

Just tried out my config (which I recently added a rock to) on my work mac (running BigSur not sure if that matters) and found that although the same install process seems to happen to setup luarocks via packer, the install process appears to finish but I don't think luarocks is correctly installed since further calls to install try to install luarocks again. The rock I also specified (penlight) is also not installed.

akinsho avatar Jan 26 '21 13:01 akinsho

Yeah, that's https://github.com/nvim-lua/plenary.nvim/issues/4 (and the same fix - setting env var MACOSX_DEPLOYMENT_TARGET to 10.15 - works to fix it). I'm considering setting that env var by default in packer, but I want to know how that value was found first, so I can have confidence I won't cause more problems by setting it.

wbthomason avatar Jan 26 '21 14:01 wbthomason

Note that you only need to set that variable once when you install the first rock (because that's when hererocks builds luajit, which requires the flag to build correctly). Once luajit is installed (locally), using rocks (and adding further rocks if they don't need a complicated build) works fine without it.

So doing this manually with MACOSX_DEPLOYMENT_TARGET=10.15 nvim and then calling PackerSync once should suffice (until you wipe the cache directory).

clason avatar Jan 27 '21 09:01 clason

@wbthomason that resolved the issue for me, I'm happy to close this or otherwise leave it here so you can track against doing something automagically for users or maybe to track against documenting the fix if not, whatever you prefer.

akinsho avatar Jan 27 '21 09:01 akinsho

Might be good to leave open (and pin?) for now, at least until the Readme is finalized with such instructions?

clason avatar Jan 27 '21 10:01 clason

Hi, I am having trouble running PackerSync I think it is related to this issue since it fails to spawn a plenary.nvim process and I am running macOS BigSur with the m1 chip.

Any ideas on how to solve this issue?

Error executing vim.schedule lua callback: .../site/pack/packer/start/plenary.nv
im/lua/plenary/job.lua:374: Failed to spawn process...

stack traceback:
        .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:374: in func
tion '_execute'
        .../site/pack/packer/start/plenary.nvim/lua/plenary/job.lua:417: in func
tion 'start'
        ...im/site/pack/packer/start/gitsigns.nvim/lua/gitsigns.lua:77: in funct
ion 'run_job'
        ...im/site/pack/packer/start/gitsigns.nvim/lua/gitsigns.lua:204: in func
tion 'ret'
        ...e/pack/packer/start/gitsigns.nvim/lua/gitsigns/async.lua:59: in funct
ion 'step'
        ...e/pack/packer/start/gitsigns.nvim/lua/gitsigns/async.lua:62: in funct
ion <...e/pack/packer/start/gitsigns.nvim/lua/gitsigns/async.lua:49>
        ...e/pack/packer/start/gitsigns.nvim/lua/gitsigns/async.lua:70: in funct
ion 'cb'
        vim.lua:243: in function <vim.lua:243>
NVIM v0.5.0-dev+nightly-17-gcc1851c9f
Build type: Release
LuaJIT 2.1.0-beta3

mherna avatar Feb 02 '21 18:02 mherna

@mherna: this error occurs when you run PackerSync? I'm a bit confused, as packer doesn't use plenary at all, and your stack trace seems to point to an issue in plenary.

wbthomason avatar Feb 03 '21 02:02 wbthomason

@wbthomason, thanks for the reply. I reinstalled neovim, and the issue got solved. Weirdly it was happening just when I ran PackerSync, which led me to believed it had something to with packer, but good to know that packer doesn't use plenary for future reference.

mherna avatar Feb 03 '21 12:02 mherna

@mherna Did you only reinstall neovim or did you also clean any packer packages in $HOME/.local/share/nvim/site/pack/start $HOME/.local/share/nvim/site/pack/opt ?

matu3ba avatar Feb 12 '21 23:02 matu3ba

@matu3ba I cleaned$HOME/.local/share/nvim/site/pack/start and $HOME/.local/share/nvim/site/pack/opt

mherna avatar Feb 13 '21 13:02 mherna

@wbthomason I feel like "clean $HOME/.local/share/nvim/site/pack/start and $HOME/.local/share/nvim/site/pack/opt" belongs to the FAQ. The alternative is to have logging+instructions, if you want to investigate further.

matu3ba avatar Feb 15 '21 18:02 matu3ba

Notes from discussion with @clason on Gitter/Matrix:

  1. The default for python_cmd is wrong on macOS; should be python3
  2. We should set the env var that fixes this problem by default (at least on macOS)
  3. packer may think that the hererocks install job succeeds even when it fails. Need to figure out why

wbthomason avatar Feb 17 '21 21:02 wbthomason

I think I'm getting something related to this:

Error in packer_compiled: ...vim/site/pack/packer/opt/packer.nvim/lua/packer/load.lua:10: attempt to index local 'plugin' (a nil value)
Please check your config for correctness

As far as I can tell, the hererocks installation craps out at some point but without an error. (I'm guessing, since I don't have a packer_hererocks directory in ~/.cache/nvim)

The PackerSync trick with MACOSX_DEPLOYMENT_TARGET doesn't seem to work for me, though 😞 Is there a way to manually install hererocks in that directory to at least have a temporary fix?

garymh avatar Apr 20 '21 02:04 garymh

@garymh Your error message doesn't seem obviously related to luarocks. What makes you think the problem lies there rather than with a config or compiled file issue?

wbthomason avatar Apr 20 '21 03:04 wbthomason

@wbthomason I guess it could be something different- I'm just using a very slimmed down packer setup and still getting it. The only thing I could pick out that looked off from my packer compiled file was the luarocks path.

Here is my packer loading code:

local packer = nil

local function init()
    if packer == nil then
        packer = require('packer')
        util = require("packer/util")
        packer.init({
            compile_path = util.join_paths(vim.fn.stdpath("config"),
                                           "vimscript", "packer_compiled.vim"),
            max_jobs = 10
        })
    end

    local use = packer.use
    packer.reset()

    use {"wbthomason/packer.nvim", opt = true}

    use {
        "AndrewRadev/switch.vim",
        cmd = {"Switch", "SwitchReverse"},
        config = function()
            vim.g.switch_custom_definitions =
                {
                    {"assert", "refute"}, {"if", "unless"}, {"[ ]", "[x]"},
                    {"yes", "no"}, {"let g:", "vim.g."}
                }
        end
    }
end

local plugins = setmetatable({}, {
    __index = function(_, key)
        init()
        return packer[key]
    end
})

return plugins

The error message comes up when I use the :Switch command. It seems to work fine when not lazy-loaded... maybe it's a problem with that?

garymh avatar Apr 20 '21 03:04 garymh

Yeah - it seems to be something with lazy loading? 🤷 I removed all the keys and cmd triggers from my packer loading code and everything seems to be working... 🤔

garymh avatar Apr 20 '21 14:04 garymh

I had this issue on linux. For me, the issue was that the python_cmd default is python, whereas my python executable is named python3. Switching it to python3 allows things to install correctly.

There was no error on my end though, even though things weren't working. The hererocks install just went infinitely.

jacksonludwig avatar Jun 13 '21 02:06 jacksonludwig

@jacksonludwig: Thanks for the report. Could you please start a new issue with the contents of ~/.cache/nvim/packer.nvim.log? I suspect that we're missing an early return in the hererocks install function.

wbthomason avatar Jun 13 '21 20:06 wbthomason

I just set my python_cmd back to the default to try to make the error happen again but it did not. Is there some sort of cache or something? I don't know why it would suddenly not hang with the wrong python_cmd

jacksonludwig avatar Jun 14 '21 00:06 jacksonludwig

If you already have Luarocks installed via hererocks, packer won't try to reinstall it. Using hererocks should be the only place that we use python_cmd.

wbthomason avatar Jun 14 '21 05:06 wbthomason

You can add vim.fn.setenv("MACOSX_DEPLOYMENT_TARGET", "10.15") on top of your plugins.lua

folke avatar Jun 30 '21 18:06 folke

Which is proper solution here? Setting up python3 in config.luarocks.python_cmd or MACOSX_DEPLOYMENT_TARGET?

gegoune avatar Jul 14 '21 19:07 gegoune

The environment variable is the easiest fix. Note that it is only needed to be set the very first time you install something for the luarocks installation itself; adding more rocks after it will work fine without it.

clason avatar Jul 14 '21 19:07 clason

Thanks @clason, will add what Folke posted above. I do understand importance of it on initial install only, want to have it in my dots for fresh installations anyway. Thanks guys!

gegoune avatar Jul 14 '21 20:07 gegoune

🤔 still facing the same issue ✗ Failed to install package tried to a number of stuff but no luck, I tired both MACOSX_DEPLOYMENT_TARGET and setting python command.

kkharji avatar Jul 29 '21 08:07 kkharji

You can add vim.fn.setenv("MACOSX_DEPLOYMENT_TARGET", "10.15") on top of your plugins.lua

This works for me. Cheers!

beauwilliams avatar Aug 30 '21 01:08 beauwilliams

NOTE: Use your own Mac version. I had MACOSX_DEPLOYMENT_TARGET=12.3.1!

# Possibly optional.
ln -s /usr/local/bin/python3 /usr/local/bin/python

# Start from scratch.
rm -rf ~/.cache/nvim

nvim
:lua vim.fn.setenv("MACOSX_DEPLOYMENT_TARGET", "10.15")
:PackerSync
:qa!

# If the above fails, install manually:
export MACOSX_DEPLOYMENT_TARGET=10.15
cd ~/.cache/nvim/packer_hererocks
rm -rf 2.1.0-beta3
python3 hererocks.py -j "2.1.0-beta3" "2.1.0-beta3"

# Reattempt:
nvim
:PackerSync
:qa!

EDIT: The :PackerSync indicates that a rock fzy was installed, but importing it still fails... So I had to do some unholy hackery to force lua 5.1 which somehow was then using lua 5.4, and so I sinned and symlinked them:

# Pretend that Lua 5.1 is LuaJIT 2.1.0-beta3:
export MACOSX_DEPLOYMENT_TARGET=10.15
cd ~/.cache/nvim/packer_hererocks
rm -rf 2.1.0-beta3
python3 hererocks.py -l "5.1" "2.1.0-beta3"

# Install rock (e.g. fzy):
nvim
:PackerSync
:qa!

# Pretend 5.4 is 5.1 is 2.1.0-beta3:
ln -s ~/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.4 \
      ~/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1

# Repent:
echo "Father, I repent."

YodaEmbedding avatar Jul 03 '22 00:07 YodaEmbedding