Windows reports error when trying to install package using pipenv

51,420

Solution 1

I have a similar setup and faced a similar problem, but the solution I found was fairly simple. All of my PATH variables were already correct (from Python 3 the Windows Installer automatically does all of this).

The problem

The problem actually arises because of conflicting installations of virtualenv.

Fix

To address this problem you need to simply run the following commands:

  1. First, remove your current version of virtualenv: pip uninstall virtualenv

  2. Then, remove your current version of pipenv: pip uninstall pipenv

  3. When you are asked Proceed (y/n)? just enter y. This will give you a clean slate.

  4. Finally, you can once again install pipenv and its dependencies: pip install pipenv

This will also install the latest version of virtualenv.

Testing if it worked

Just enter pipenv --version in the command prompt and you should see the desired output.

Notes

I know this sounds the mundane, but it is actually the solution for Windows systems. You do not need to modify any of your system environment variables (please do not add site-packages to your environment variables).

Hope this helps!

Solution 2

python -m pipenv may work for you, (or python3 -m pipenv or py 3 -m pipenv) this is telling python to run the module pipenv instead of the terminal shortcut which sometimes doesn't install properly.

Just to show they are equivalent when I installed pipenv and run which pipenv it points to a file like /Library/Frameworks/Python.framework/Versions/3.6/bin/pipenv which looks like this:

#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6

# -*- coding: utf-8 -*-
import re
import sys

from pipenv import cli

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
    sys.exit(cli())

so it removes .pyw or .exe from the executable name then call pipenv.cli.cli(). It is likely there is a file like this on your machine it just didn't add python's /bin folder to your system PATH so it isn't accessible, there is usually a warning when installing python if this happens but no one checks those. :P

the module pipenv.__main__ which is run when using python -m pipenv looks like this:

from .cli import cli

if __name__ == '__main__':
    cli()

Which calls pipenv.cli.cli(). So this main module absolutely does the same effective thing.

Solution 3

to solve this problem i need to start my CMD as administrator.

  1. pip uninstall pipenv

  2. pip install pipenv

To test this new configuration, you can write pipenv --version

Solution 4

Try adding the following to Path environmental variable:

C:\Users\Robert\AppData\Roaming\Python\Python36\Scripts

instead of the \site-package, as that is where pipenv.exe is installed (at least for me).

Solution 5

use this cmd solve my problem :

python -m pipenv install django==2.1
Share:
51,420
Robert
Author by

Robert

Updated on August 23, 2021

Comments

  • Robert
    Robert almost 3 years

    I installed pipenv by following the instructions here. From the Windows command prompt I ran

    pip install --user pipenv
    

    which returned the message

    Successfully installed pipenv-5.3.3
    

    Now I want to install the requests package using pipenv, so I ran

    pipenv install requests
    

    but this returned

    'pipenv' is not recognized as an internal or external command,
    operable program or batch file.
    

    I have added the path

    C:\Users\Robert\AppData\Roaming\Python\Python35\site-packages
    

    to my Windows path environment variable, but I still receive the same error. How can I install the requests package using pipenv?


    EDIT: As I have remnants of Python 3.5 and Python 3.6 on my system, I'm going to uninstall everything and start anew. (I've just started learning Python and I want to keep this as simple as possible.)

  • Tadhg McDonald-Jensen
    Tadhg McDonald-Jensen over 6 years
    the question states that they get an error saying 'pipenv' is not recognized as a command so I don't see how this would help
  • Robert
    Robert over 6 years
    Using python -m pipenv requests returned Traceback followed by a dozen file/line number specifications and PermissionError: [Errno 13] Permission denied: 'Pipfile'. When I run a program with the lineimport requests Python returns the error ModuleNotFoundError: No module named 'requests'. BTW, I appreciate your detailed answer, but it's beyond my level of understanding and I don't know how to implement it in Windows. So maybe a better question would be What's the easiest way to install a package? (I tried python -m pip install requests with no improvements.)
  • Tadhg McDonald-Jensen
    Tadhg McDonald-Jensen over 6 years
    This seems more suited for a comment then an answer
  • Tadhg McDonald-Jensen
    Tadhg McDonald-Jensen over 6 years
    @Robert using python -m pip install is my suggestion for installing packages, if that is resulting in error I'd be interested in what that error is. also when you run python programs how do you do that?
  • Robert
    Robert over 6 years
    I decided to cleanly reinstall Python as I had remnants of two different versions on my system. I'm still not able to install packages, and my follow-up question is here
  • Robert
    Robert over 6 years
    Thanks, but I just reinstalled Python into a folder where I had write access. See stackoverflow.com/a/46042921/4945268
  • Taylor Liss
    Taylor Liss over 5 years
    Worked like a charm! Thank you!
  • Jozcar
    Jozcar about 5 years
    This work for me, my mistake was that i install virtualenv first, was not aware that this was included in pipenv, thank you!
  • Dwhitz
    Dwhitz about 5 years
    Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.
  • Aubergine
    Aubergine almost 5 years
    Worked as well, there is something fundamentally broken with Python dependency managers and virtual environments. I had problems on Linux , Windows and not even proficient QA engineers using Python on daily basis could help me. Corrupted environments, broken pip, reinstalling python etc. etc. as reigning language in 2019 Python community should sort out their mess. Javascript did with npm, Java long time with maven and gradle. Python is doing some weird tango.
  • Muhammad Umar Amanat
    Muhammad Umar Amanat over 4 years
    Solved my problem. Thanks mate!
  • Nqabeni Simela
    Nqabeni Simela about 4 years
    helped me in 2020
  • Ray K. Ragan
    Ray K. Ragan over 3 years
    Worked perfectly. Thank you.
  • Admin
    Admin over 3 years
    The first paragraph of your answer solved my problem.
  • 1020rpz
    1020rpz over 3 years
    Needs to be accepted as best answer. Thanks mate
  • Gaurav Khurana
    Gaurav Khurana about 3 years
    Thanks thats aweswome.. not sure how it happened but it worked
  • Alter
    Alter about 3 years
    Did not work for me. Edit: oops, pip gave me a clear log message saying The script virtualenv is installed in '/home/pi/.local/bin' which is not on PATH. - I guess this is something else that can come up
  • Nedim
    Nedim about 3 years
    @Alter thanks, I didn't read log :) you saved me some time :)
  • m-dz
    m-dz almost 3 years
    To the contrary, it did not help me, had to manually add the correct dir to path... Just search for "pipenv" on C: