2

I'm trying to work with pipenv and I installed it using pip, however whenever I run any command starting with pipenv, I get the following error:

zsh: command not found: pipenv

I know I should add it to my path somehow but I'm not entirely familiar with how to configure my ~/.zshrc.

Also, I tried locating where pipenv is located using where pipenv, but I get

pipenv not found
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Michael Flor
  • 21
  • 1
  • 2
  • 3
  • How did you install pipenv? – anthony sottile Jan 08 '19 at 02:39
  • @AnthonySottile `sudo -H pip install -U pipenv` I also tried `pip install pipenv`. Side note, pip=pip3 in my case. I have an alias for it in my zshrc file. – Michael Flor Jan 08 '19 at 02:46
  • 2
    `sudo pip install --user`, oh dear -- the `--user` flag is designed to not use root. You probably just want to `pip install --user` and then it'll end up in `~/.local/bin` or something of the sort and you can put that on your `PATH` – anthony sottile Jan 08 '19 at 02:55
  • @AnthonySottile that cleared it up for me. Thank you so much! If you don't mind, what's the difference between using `sudo pip install --user` and just using `pip install --user`? – Michael Flor Jan 08 '19 at 03:02
  • 1
    the first does a user installation for the root user, which is mostly nonsensical (probably wrote to `/root/.local/`) – anthony sottile Jan 08 '19 at 03:36
  • Since `which` *uses* `PATH` to find its argument, it's not useful for finding a program not already found via `PATH`. – chepner Jan 08 '19 at 19:38
  • Anyone know how to fix this problem? – CYC Feb 16 '20 at 08:54

4 Answers4

11

You will need to add support to your ~/.zshrc file. You can access it with code ~/.zshrc.

I needed to add these to the file:

export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
export PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
export PATH="$PATH:$PYTHON_BIN_PATH"

Once you add them you will need to restart your terminal before you can see these changes take effect.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
dacey
  • 145
  • 1
  • 4
4

Using pip

pipenv should be in your PATH if you installed it using pip as a user install, as recommended in the docs:

pip install --user pipenv

If it still isn't available, you'll need to add the user base's binary directory to your PATH:

  • UNIX default: ~/.local
  • MacOS Framework builds: ~/Library/Python/X.Y
  • Windows: %APPDATA%\Python

You can read more about this in the Python docs on site.USER_BASE.

Using Homebrew

If you're using Homebrew, then another option is to install pipenv like so:

brew install pipenv

This installs it globally. Since pipenv can manage even different python versions via pyenv, it's preferable to have it set up like this instead of installing it only for a specific python version using pip.

However, this method is discouraged according to the pipenv documentation:

Homebrew installation is discouraged because each time the Homebrew Python is upgraded, which Pipenv depends on, users have to re-install Pipenv, and perhaps all virtual environments managed by it.

martin-martin
  • 3,274
  • 1
  • 33
  • 60
0

Open ~/.zshrc and append these lines:

# Setting PATH for Python 3.4
PATH="/Library/Frameworks/Python.framework/Versions/3.4/bin:${PATH}"
export PATH

or:

# Setting PATH for Python 3.9
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH

I tested it on macOS.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Chandragupta Borkotoky
  • 1,596
  • 1
  • 11
  • 16
0

Use a package manager such as apt, yum or brew to install pipenv.

Installing pipenv with a package manager rather than pip adds it directly to $PATH of any shell, like bash or zsh.

sudo apt install pipenv
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Atehe
  • 63
  • 4