Setting up Pipenv in VSC

Hey all,

Following along with the Pipenv section of modules and I’ve hit a bit of a snag with my VSC terminal.

I followed the directions for installing pipenv within the command line and creating the new path, however when I call pipenv --three in VSC to create a virtual environment I receive:

 pipenv : The term 'pipenv' is not recognized as the name of a cmdlet, function, script file, or 
operable program. Check the spelling of the name, or if a path was included, verify that the path is     
correct and try again.
At line:1 char:1
+ pipenv --three
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (pipenv:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I’ve tried going back into cmd and editing the path. For some reason Git Bash is also just full on denying me permission to call pip in any capacity (–version or otherwise) even when ran as admin.

Any insight would be greatly appreciated!

1 Like

If you haven’t already, close any previously open sessions of Visual Studio Code. PATH is an environment variable, and may not update in any previously open terminals.

If you still can’t call pipenv after restarting the shell, you may need to adjust your PATH. The pipenv documentation may also be of assistance.

2 Likes

Thank you most kindly!

After I set the PATH I restarted all my external command lines, but didn’t think to restart VSC.

Also, is the command line you install Pipenv on mutually exclusive with your choice of command line within something like VSC’s terminal?

1 Like

No, Visual Studio Code will use instances of the same shell(s) available outside it; so, on a Windows machine, you’d have cmd and maybe PowerShell for example.

2 Likes

So it shouldn’t make a difference if I use Git Bash as the default for the Terminal? Or is that not recommended for functionality?

Nope, anything that you can do in Git Bash you should be able to do with an instance of Git Bash in VSC.

2 Likes

I primarily use Git Bash on Windows. I use it in VS Code just fine.

That being said, Git Bash and Pipenv don’t play well with each other. Specifically, even once you get it set up properly, Git Bash won’t indicate at the prompt that you have activated a pipenv environment. For that exact reason, I usually use Python’s built-in venv or conda to manage my virtual environments.

Honestly, my favorite of the three is conda due to its ease of use and excellent management of dependencies, but developers outside the Data Science world don’t really use it much.

2 Likes

I use the WSL to run Ubuntu on Windows, so I get proper bash and don’t have to cobble it into Windows or deal with a bundler like conda. :slight_smile:

So many ways to dev, it’s amazing. :smiley:

2 Likes

I love Linux and WSL for sure. Though, even on Linux I use conda quite a bit since it’s better than pip in many ways (fighting words, I know :grimacing:)

1 Like

So in most cases when I try and call pip in Git Bash I get a permission denied message in the console, even when running it as admin.

Does pip work in CMD? It sounds like you might not have pip in your Git Bash path, which is separate from your CMD path. Try typing which python in Git Bash and see what it says.

1 Like

It does. That’s interesting. I’ll give it a shot. I’m not sure I path’d my Git Bash correctly. I have to navigate to my user profile and desktop manually when I open it.

which python returns:

/c/Users/TEST/AppData/Local/Microsoft/WindowsApps/python

Hm, yeah I’m pretty sure that’s your system Python. You shouldn’t be coding using that one. Have you downloaded Python yourself? If so, did you do it from Python.org or through Anaconda/Miniconda?

1 Like

Yeah I have Anaconda installed. I launch VSC from there. Could it be an issue with the git path?

Okay, so you’re trying to use Python downloaded with Anaconda then.

The easiest way to do this is to just use Anaconda Prompt. It is basically CMD with conda built into it and ready to use. In Anaconda Prompt, you can download using either conda install or pip install. If it doesn’t have pip you can download it with conda install pip. You can also install pipenv using the pip install pipenv or conda install -c conda-forge pipenv

The only downside of using Anaconda Prompt is that it uses CMD-style commands instead of Bash-style commands. Other than that, it can do pretty much anything you want it to.

Git Bash, on the other hand, struggles with a good number of things, such as running certain Windows executables like the Python interactive shell, postgreSQL CLI, and the pipenv shell. This is because Git Bash needs to use winpty to run them. With some things, this works fine, but with others it does not. But, Git Bash does let you use Bash commands on Windows and has excellent integration with Git (obviously).

If you still want to use Git Bash, you can either set up conda to work from there, or you can download Python here and use the installer. If you do the latter, I believe there is an “Add to path” option that you should select and it will automatically get it working with Git Bash. If you want conda working on Git Bash, I can walk you through that, but it will take a few extra steps.

However, as I mentioned in my earlier comment, pipenv doesn’t play nicely with Git Bash so if you’re dead-set on using pipenv for your virtual envirionments, you should probably just do it via CMD or Anaconda Prompt.

2 Likes

Just to confirm:

When I launch my navigator, I have CMD Promp and Powershell Prompt. Are either of these where I would access Anaconda Prompt??

Thank you for your patience again, I’m still quite green as I’m sure you can tell.

EDIT: I immediately googled Anaconda Prompt and found it in my start menu. :sweat_smile:

2 Likes