[python] Pipenv: Command Not Found

I'm new to Python development and attempting to use pipenv. I ran the command pip install pipenv, which ran successfully:

...
Successfully built pipenv pathlib shutilwhich pythonz-bd virtualenv-clone
Installing collected packages: virtualenv, pathlib, shutilwhich, backports.shutil-get-terminal-size, pythonz-bd, virtualenv-clone, pew, first, six, click, pip-tools, certifi, chardet, idna, urllib3, requests, pipenv
...

However, when I run the command pipenv install in a fresh root project directory I receive the following message: -bash: pipenv: command not found. I suspect that I might need to modify my .bashrc, but I'm unclear about what to add to the file or if modification is even necessary.

This question is related to python python-3.x pip pipenv

The answer is


OSX GUYS, OVER HERE!!!

As @charlax answered (for me the best one), you can use a more dynamic command to set PATH, buuut for mac users this could not work, sometimes your USER_BASE path got from site is wrong, so you need to find out where your python installation is.

$ which python3
/usr/local/bin/python3.6

you'll get a symlink, then you need to find the source's symlink.

$ ls -la /usr/local/bin/python3.6
  lrwxr-xr-x  1 root  wheel  71 Mar 14 17:56 /usr/local/bin/python3.6 -> ../../../Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

(this ../../../ means root)

So you found the python path (/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6), then you just need to put in you ~/.bashrc as follows:

export PATH="$PATH:/Library/Frameworks/Python.framework/Versions/3.6/bin"


If you've done a user installation, you'll need to add the right folder to your PATH variable.

PYTHON_BIN_PATH="$(python3 -m site --user-base)/bin"
PATH="$PATH:$PYTHON_BIN_PATH"

See pipenv's installation instructions


You might consider installing pipenv via pipsi.

curl https://raw.githubusercontent.com/mitsuhiko/pipsi/master/get -pipsi.py | python3
pipsi install pew
pipsi install pipenv

Unfortunately there are some issues with macOS + python3 at the time of writing, see 1, 2. In my case I had to change the bashprompt to #!/Users/einselbst/.local/venvs/pipsi/bin/python


I'm using zsh on my Mac, what worked for me is at first install pipenv

pip3 install --user pipenv

Then I changed the PATH in the ~/.zshrc

vi ~/.zshrc

In the editor press i to insert your text:

export PATH="/Users/yourUser/Library/Python/3.9/bin:$PATH"

Press esc and then write :wq! Close the terminal and re-open it. And finally write pipenv

This way worked for me using macOS BigSur 11.1


For window users this may be due to conflicting installation with virtualenv. For me it worked when I uninstalled virtualenv and pipenv first, and then install only pipenv.

pip uninstall virtualenv
pip uninstall pipenv
pip install pipenv

Now pipenv install xxx worked for me


This is fixed for me to:

sudo -H pip install -U pipenv

For me, what worked on Windows was running Command Prompt as administrator and then installing pipenv globally: python -m pip install pipenv.


HOW TO MAKE PIPENV A BASIC COMMAND

Pipenv with Python3 needs to be run as "$ python -m pipenv [command]" or "$ python3 -m pipenv [command]"; the "python" command at the beginning varies based on how you activate Python in your shell. To fix and set to "$ pipenv [command]": [example in Git Bash]

$ cd ~
$ code .bash_profile

The first line is necessary as it allows you to access the .bash_profile file. The second line opens .bash_profile in VSCode, so insert your default code editor's command. At this point you'll want to (in .bash_profile) edit the file, adding this line of code:

alias pipenv='python -m pipenv'

Then save the file and into Git Bash, enter:

$ source .bash_profile

You can then use pipenv as a command anywhere, for example: $ pipenv shell Will work.

This method of usage will work for creating commands in Git Bash. For example:

alias python='winpty python.exe'

entered into the .bash_profile and: $ source .bash_profile will allow Python to be run as "python".

You're welcome.


In some cases of old pip version:

sudo easy_install pip
sudo pip install pipenv

After installing pipenv (sudo pip install pipenv), I kept getting the "Command Not Found" error when attempting to run the pipenv shell command.

I finally fixed it with the following code:

pip3 install pipenv
pipenv shell

Where Python store packages

Before jumping into the command that will install pipenv, it is worth understanding where pip installs Python packages.

Global site-packages is where Python installs packages that will be available to all users and all Python applications on the system. You can check the global site package with the command

python -m site

For example, on Linux with Python 3.7 the path is usually

/usr/lib/python3.7/dist-packages/setuptools

User site-packages is where Python installs packages available only for you. But the packages will still be visible to all Python projects that you create. You can get the path with

python -m site --user-base

On Linux with Python 3.7 the path is usually

~/.local/lib/python3.7/site-packages

Using Python 3.x

On most Linux and other Unices, usually Python 2 and Python 3 is installed side-by-side. The default Python 3 executable is almost always python3. pip may be available as either of the following, depending on your Linux distribution

pip3
python3-pip
python36-pip
python3.6-pip

Linux

Avoid using pip with sudo! Yes, it's the most convenient way to install Python packages and the executable is available at /usr/local/bin/pipenv, but it also mean that specific package is always visible for all users, and all Python projects that you create. Instead, use per-user site packages instead with --user

pip3 install --user pipenv

pipenv is available at

~/.local/bin/pipenv

macOS

On macOS, Homebrew is the recommended way to install Python. You can easily upgrade Python, install multiple versions of Python and switch between versions using Homebrew.

If you are using Homebrew'ed Python, pip install --user is disabled. The global site-package is located at

/usr/local/lib/python3.y/site-packages

and you can safely install Python packages here. Python 3.y also searches for modules in:

 /Library/Python/3.y/site-packages
 ~/Library/Python/3.y/lib/python/site-packages

Windows

For legacy reasons, Python is installed in C:\Python37. The Python executable is usually named py.exe, and you can run pip with py -m pip.

Global site packages is installed in

C:\Python37\lib\site-packages

Since you don't usually share your Windows devices, it is also OK to install a package globally

py -m pip install pipenv

pipenv is now available at

C:\Python37\Scripts\pipenv.exe

I don't recommend install Python packages in Windows with --user, because the default user site-package directory is in your Windows roaming profile

C:\Users\user\AppData\Roaming\Python\Python37\site-packages 

The roaming profile is used in Terminal Services (Remote Desktop, Citrix, etc) and when you log on / off in a corporate environment. Slow login, logoff and reboot in Windows can be caused by a large roaming profile.


I tried this:

python -m pipenv # for python2

python3 -m pipenv # for python3

Hope this can help you.


Installing pipenv globally can have an adverse effect by overwriting the global/system-managed pip installation, thus resulting in import errors when trying to run pip.

You can install pipenv at the user level:

pip install --user pipenv

This should install pipenv at a user-level in /home/username/.local so that it does not conflict with the global version of pip. In my case, that still did not work after running the '--user' switch, so I ran the longer 'fix what I screwed up' command once to restore the system managed environment:

sudo python3 -m pip uninstall pip && sudo apt install python3-pip --reinstall

^ found here: Error after upgrading pip: cannot import name 'main'

and then did the following:

mkdir /home/username/.local ... if it doesn't already exist

export PYTHONUSERBASE=/home/username/.local

Make sure the export took effect (bit me once during this process):

echo $PYTHONUSERBASE

Then, I ran the pip install --user pipenv and all was well. I could then run pipenv from the CLI and it did not overwrite the global/system-managed pip module. Of course, this is specific to the user so you want to make sure you install pipenv this way while working as the user you wish to use pipenv.

References:

https://pipenv.readthedocs.io/en/latest/diagnose/#no-module-named-module-name https://pipenv.readthedocs.io/en/latest/install/#pragmatic-installation-of-pipenv https://pip.pypa.io/en/stable/user_guide/#user-installs


This fixed it for me:

sudo -H pip install -U pipenv

I have same problem with pipenv on Mac OS X 10.13 High Seirra, another Mac works just fine. I use Heroku to deploy my Django servers, some in 2.7 and some in 3.6. So, I need both 2.7 and 3.6. When HomeBrew install Python, it keeps python points to original 2.7, and python3 points to 3.6.

The problem might due to $ pip install pipenv. I checked /usr/local/bin and pipenv isn't there. So, I tried a full uninstall:

$ pip uninstall pipenv

Cannot uninstall requirement pipenv, not installed
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

$ pip3 uninstall pipenv
Skipping pipenv as it is not installed.

Then reinstall and works now:

$ pip3 install pipenv
Collecting pipenv

I don't know what happened, but the following did the work (under mac os catalina)

$ brew install pipenv

$ brew update pipenv

after doing this i am able to use

$ pipenv install [package_name]

OS : Linux
Pip version : pip3
sudo -H pip3 install -U pipenv

OS : Windows
Pip version : any one
sudo -H pip install -U pipenv


On Mac OS X Catalina it appears to follow the Linux path. Using any of:

pip install pipenv
pip3 install pipenv
sudo pip install pipenv
sudo pip3 install pipenv

Essentially installs pipenv here:

/Users/mike/Library/Python/3.7/lib/python/site-packages/pipenv

But its not the executable and so is never found. The only thing that worked for me was

pip install --user pipenv

This seems to result in an __init__.py file in the above directory that has contents to correctly expose the pipenv command.

and everything started working, when all other posted and commented suggestions on this question failed.

The pipenv package certainly seems quite picky.


Examples related to python

programming a servo thru a barometer Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? python variable NameError Why my regexp for hyphenated words doesn't work? Comparing a variable with a string python not working when redirecting from bash script is it possible to add colors to python output? Get Public URL for File - Google Cloud Storage - App Engine (Python) Real time face detection OpenCV, Python xlrd.biffh.XLRDError: Excel xlsx file; not supported Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation

Examples related to python-3.x

Could not load dynamic library 'cudart64_101.dll' on tensorflow CPU-only installation Replace specific text with a redacted version using Python Upgrade to python 3.8 using conda "Permission Denied" trying to run Python on Windows 10 Python: 'ModuleNotFoundError' when trying to import module from imported package What is the meaning of "Failed building wheel for X" in pip install? How to downgrade python from 3.7 to 3.6 I can't install pyaudio on Windows? How to solve "error: Microsoft Visual C++ 14.0 is required."? Iterating over arrays in Python 3 How to upgrade Python version to 3.7?

Examples related to pip

How to fix error "ERROR: Command errored out with exit status 1: python." when trying to install django-heroku using pip "E: Unable to locate package python-pip" on Ubuntu 18.04 How to Install pip for python 3.7 on Ubuntu 18? What is the meaning of "Failed building wheel for X" in pip install? Could not install packages due to an EnvironmentError: [Errno 13] How do I install Python packages in Google's Colab? Conda version pip install -r requirements.txt --target ./lib pip: no module named _internal AttributeError: Module Pip has no attribute 'main' Error after upgrading pip: cannot import name 'main'

Examples related to pipenv

How to remove a virtualenv created by "pipenv run" Pipenv: Command Not Found