Trouble with Installing 'pipenv' on macOS Terminal

Terminal in macOS is stating that I’ve already installed ‘pip3’ (v 21.3.1).

When I try installing ‘pipenv’, it says ‘Requirement already satisfied: pipenv in ./Library/Python/3.8/lib/python/site-packages’; however, if I type ‘pipenv’ into the terminal, it says ‘command not found: pipenv’.

For the Python3 course, we are currently learning about virtual environments; but I don’t have a lot of terminal experience and starting to feel out of my depth.

Python’s environment handling has always been troublesome, especially if you’re unfamiliar with using the command line in general. It’s better now than it was but it’s still not overly user-friendly. There’s even an xkcd comic about it so don’t worry if it takes some getting used to-

Can you access pipenv when using it as a module? Try python -m pipenv --version (if your system has python2 by default than that command may need to be python3 -m pipenv --version). If so you could use it that way, e.g. python3 -m pipenv install stuff...; that might be more typing than ideal but at least you’d know it works.

Normally when you install pipenv it adds a wee script in a bin directory somewhere on your PATH like /usr/bin/pipenv but it seems like that’s not the case here (this is what allows you to run the program with just the pipenv command rather than anything else).

If using python3 -m pipenv every time is too much typing you could consider writing a short script to do this and sticking it in your path or possibly aliasing it. Apologies if that doesn’t mean much to you, you may have to search for more info about what that means but there’s just a bit much to go into in a single reply, sorry.

It might be worth your time learning a bit more about the command line at some point. It’s used so often when programming that a little knowledge in it can go a long way; worth a look-in so long as it doesn’t interrupt your flow elsewhere :slightly_smiling_face:.

3 Likes

Using the python3 -m pipenv --version ended up working in the terminal. Thank you so much for the insight into how that works. I’ve added the Command Line course to my courses section, too.

1 Like

hello,

I’ve tried to follow the guide. When running the command pipenv --version I get back pipenv, version 2022.1.8 but when I run the python3 -m pipenv I get back C:\Users\user\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe: No module named pipenv
In my system environments I already have added the
C:\Users\Gianmaria Munafo\AppData\Roaming\Python\Python37\Scripts to the Path.

I’m also having another problem when trying to run python3 in my virtual environment. Here attached a screenshot. Python3 command is not loading anything, It’s as if Python3 isn’t installed but when I do python --version I get back Python 3.7.10.

python3_pipenvshell

The original post was about OSX and has already been solved. It’d be a much better idea to ask a new question in that case.

Chances are your PATH is a bit confused (you’ve got two versions and two different sets of libraries). If you can’t sort it out please make a new thread about it.

2 Likes

apologies, I though that using gitbash was similar to running OSX.

Thanks for this solution @tgrtim

I had issues with the native install of pipenv as well.

I decided to create an alias by accessing the text editor vi ~/.bash_profile, and setting
alias pipenv=“python3 -m pipenv --version”

I was curious to know if you considered this to be good practice.

At the end of the day your shell initialisation from profiles and rc etc. in your home folder is your own. So as long as you can remember that it’s set up that way then you’re grand (for a tool like pipenv at least assuming you don’t install multiple pipenvs :slightly_smiling_face:).

I would be a little careful using things like this when it comes to updating python; some modules have issues with newer python versions and python3 might then link to a newer version that pipenv is not set up to work with. Hopefully it doesn’t break with update if it does that might be why. Ideally you’d update python and pipenv at the same time which should avoid issues like this.

If you’re using package managers like homebrew I’d consider installing pipenv from there instead of pip which should help keep them compatible (in theory they’d both update at the same time :slightly_smiling_face:).