r/programminghelp • • Nov 15 '18

When installing Python packages, what is "pip" and how do you use it?

Note: I went to r/explainlikeimfive first because I need that kind of answer, but the bot redirected me here since it's about programming. Please do not assume I know anything other than what I say I know. Thank you.

I was self-taught Python and generally have a good feel for how to use the language itself. However, whenever I want to install a package, I have no idea how to do it. The tutorials jump straight into typing commands into the command prompt, which I have absolutely no idea how to use, including switching directories. I've looked up tutorials for the tutorials, but they still go over my head. If I want to install package X, how do I get it, and how do I use pip to install it (pretending I've never heard of command prompt)?

I currently have Python 3.4 on Windows 10.

5 Upvotes

3 comments sorted by

2

u/07734willy Nov 15 '18

To start command prompt, press: [WindowsKey]+ [R], type cmd, and press enter. You'll see a line like-

C:\Users\07734willy>

This is the path to the current directory your command prompt is "looking at". That is, the 07734willy subfolder of the Users folder on your C drive. You can change this directory with the command cd. Such as cd some_folder. You'll then be in:

C:\Users\07734willy\some_folder>

You can use .. as a shorthand for the parent folder (to go up one directory). You can also use dir to list all the files and folders in the current folder.


Now, with that out of the way, pip is package manager for python. That means you can use pip to install or uninstall modules for import in python. You can use pip -h or pip --help to get a list of commands and switches, which are command line options/parameters you can pass to change the action of the command. For example, we passed the -h switch to tell pip to print the help screen (which is a common switch that most major command line programs will likely have).

You can use pip install <some_package_name> to install that package for use in your python environment. You can also use pip uninstall <name> to uninstall it. Often, programmers will create a virtual environment for this, so that they can have multiple configurations of python with different (possibly conflicting) modules installed on each, and can freely switch between them. That's a bit more involved, but this should at least give you a start into using the command line and installing packages with pip.

1

u/PlatypusVenom0 Nov 15 '18

This is great, but I have a couple questions:

  1. Why can't I use pip in the command prompt (unrecognized command)? Should I be in a certain directory or environment? Do I have to install pip itself?

  2. Do I have to install some kind of file before installing the package with pip? If so, are there any intermediate steps?

2

u/07734willy Nov 15 '18 edited Nov 15 '18

Try this command, and then try to run pip again:

python -m ensurepip --default-pip

If that still doesn't work, download this and run it with

python get-pip.py

links and commands taken from this page


Edit- I realize I never actually answered your questions outright.

  1. You can't use pip because for whatever reason, it wasn't installed. You don't need to be in any directory, just run those commands to let python install it for you

  2. If you wish, you can download a file containing the package you want to install, and then use some other commands to install that specific package (maybe to get an unreleased/beta version, or to get a custom build or tweaked variant of a popular package) using pip. But most of the time, you don't need to download anything. Just google the actual name of the package (it might be different than the module's name), and install that as described in the original comment.