Cost Check Now
Programming·Python

How to install packages in Python using pip (2026)

Verified from sources

Quick Answer

To install a Python package with pip, first make sure Python and pip are available in the same environment you plan to use, then run a command such as `python -m pip install package-name`. It is usually best to install into a virtual environment rather than system Python, especially for project work. You know it worked when pip reports a successful install and you can import the package in Python without an error.

Overview

Installing packages with pip is the standard way to add third-party libraries to Python. The important part is not just running `pip install`, but doing it in the right environment. Many installation problems happen because people have more than one Python version installed, or because pip is installing into a different interpreter than the one that runs their code. Using `python -m pip` helps avoid that by tying pip to a specific Python interpreter. For most projects, create and activate a virtual environment first. This keeps project dependencies separate from your system Python and from other projects, reducing version conflicts and permission problems. Once the environment is active, install the package, then verify both the installation and the import. If pip is missing or outdated, update it using Python’s own module runner rather than relying on a separate `pip` command. This guide covers the practical order: confirm Python, confirm pip, optionally create a virtual environment, install the package, and check that it works. It also covers common issues such as “pip not found”, permission errors, and installs going to the wrong place.

Who this is for

Python beginners, developers setting up a new project, and anyone who needs to install packages reliably on Windows, macOS, or Linux.

What you’ll need

  • A working Python installation
  • Command Prompt, PowerShell, Terminal, or another shell
  • Internet access for packages from Python Package Index or another package source
  • The exact package name you want to install
  • Permission to install software in your user account or environment

Before you start

Check which Python interpreter you want to use. If you have more than one Python version installed, decide which one should run your project. For project work, plan to use a virtual environment so package versions stay isolated. If you are on a managed work machine, your administrator may restrict installs or require an internal package index.

Step-by-step

  1. 1

    Confirm Python is installed

    Open your shell and run `python --version`. If that does not work, try `py --version` on Windows or `python3 --version` on macOS or Linux. If none of these work, install Python first from the official Python source for your operating system.

    Why: pip installs packages for a specific Python interpreter. You need to know which interpreter you are targeting before you install anything.

  2. 2

    Check that pip is available for that Python

    Run `python -m pip --version`. If you are using `py` or `python3`, use `py -m pip --version` or `python3 -m pip --version` instead. If pip is missing, try `python -m ensurepip --upgrade` where supported, or reinstall Python with pip included.

    Why: Using `python -m pip` makes sure you are calling the pip linked to that exact Python installation, which avoids many path and version mix-ups.

  3. 3

    Create a virtual environment for project work

    In your project folder, run `python -m venv .venv` or the equivalent command for your interpreter. Then activate it: on Windows use the activation script in `.venv\Scripts`, and on macOS or Linux use the activation script in `.venv/bin`. After activation, run `python --version` and `python -m pip --version` again.

    Why: A virtual environment keeps packages for this project separate from the rest of the system, which prevents conflicts and avoids needing system-wide install permissions.

  4. 4

    Upgrade pip in the target environment

    Run `python -m pip install --upgrade pip`. Let the command finish before installing other packages.

    Why: A current pip version improves compatibility with modern package formats and reduces installation errors.

  5. 5

    Install the package

    Run `python -m pip install package-name`, replacing `package-name` with the exact package name. If you need a specific version, use standard pip version syntax such as `package-name==version`. If your project has a requirements file, use `python -m pip install -r requirements.txt` instead.

    Why: This is the actual installation step. Installing by exact package name or from a requirements file makes your environment more predictable and repeatable.

  6. 6

    Verify that installation completed correctly

    Read the pip output and confirm it reports a successful install rather than an error or warning. Then test the package with a short command such as `python -c "import package_name; print('ok')"`, using the correct import name for the library. You can also inspect installed packages with `python -m pip show package-name` or `python -m pip list`.

    Why: A package may appear to install but still be unavailable to the Python interpreter you actually use. Import testing confirms the environment is correct.

Why this works

pip downloads and installs Python distributions into the site-packages area used by a specific Python interpreter or virtual environment. When you run that same interpreter, it can then import and use the installed package.

Common mistakes to avoid

  • Using `pip install` without checking which Python interpreter that pip belongs to
  • Installing packages globally instead of in a virtual environment for a project
  • Confusing the package name on the package index with the module name used in `import`
  • Running installation commands in one environment and running code in another
  • Ignoring permission errors and trying repeated installs instead of switching to a virtual environment or user install

Troubleshooting

`pip` or `python -m pip` is not found

Check that Python is installed and that you are using the correct command for your platform, such as `py`, `python`, or `python3`. If pip is missing, use `ensurepip` where available or reinstall Python with pip included.

The package installs, but `import` fails

You are probably using a different interpreter from the one pip installed into. Run `python -m pip --version` and compare it with the Python you use to run your code. Activate the correct virtual environment and reinstall there if needed.

Permission denied or access refused during install

Do not force a system-wide install unless you manage that machine. Use a virtual environment or, where appropriate, a user-level install. On managed systems, follow your organisation’s package policy.

A build or compilation error appears during install

Some packages need platform-specific build tools or system libraries. Check the package’s official installation instructions. If a prebuilt wheel is unavailable for your platform or Python version, you may need development tools or a different Python version.

The wrong package version gets installed

Specify the version explicitly in the install command or in a requirements file, then verify with `python -m pip show package-name`.

Compare your options

Install in a virtual environment

Best for: Most project-based development

Pros: Keeps dependencies isolated, avoids most permission issues, makes projects easier to reproduce

Cons: Needs activation per shell session and separate setup per project

Install to system Python

Best for: Very limited cases where you intentionally manage one shared environment

Pros: Available without activating an environment

Cons: Higher risk of conflicts, can affect system tools, often needs elevated permissions

Install from `requirements.txt`

Best for: Teams and existing projects

Pros: Repeatable environment setup, easier version control

Cons: Depends on the requirements file being maintained correctly

Install a single package manually

Best for: Quick experiments or adding one library

Pros: Simple and direct

Cons: Easy to forget exact versions or miss related dependencies across machines

Alternatives

  • Use a distribution or environment manager such as conda if your workflow depends on non-Python binary dependencies and the project specifically supports it
  • Use project tools that manage environments and dependencies on top of pip, such as venv-based workflows driven by a project configuration

Pro tips

  • Prefer `python -m pip` over plain `pip` to avoid path confusion
  • Keep one virtual environment per project
  • Store your project dependencies in a requirements file for repeatable setup
  • If a package import name differs from its install name, check the package documentation before testing the import
  • After activating a virtual environment, confirm it by checking that `python -m pip --version` points inside that environment

Safety notes

  • Only install packages from sources you trust, because Python packages can execute code during installation or when run
  • Be careful with copy-pasted commands from unverified websites, especially commands that use elevated privileges
  • On shared or production systems, test package changes in an isolated environment before applying them more widely

What this guide does not cover: This guide covers standard pip-based installation only. It does not provide package-specific build instructions, operating-system-specific shell walkthroughs in full detail, or advanced dependency management for every tooling ecosystem.

Cost considerations

pip itself is free to use. Most packages on the Python Package Index are free, but some development workflows may involve paid tooling, private package repositories, or organisational infrastructure.

Frequently asked questions

Should I use `pip` or `pip3`?+

Use the command tied to the interpreter you actually want, but the most reliable form is usually `python -m pip` or `python3 -m pip`. That avoids guessing which standalone pip command is on your path.

Do I need administrator rights to install Python packages?+

Not usually if you use a virtual environment, which is the recommended approach for project work. System-wide installs may require elevated permissions.

How do I install a specific version of a package?+

Use pip’s version specifiers in the install command, or put the package and version in a requirements file. Then verify the installed version with `python -m pip show package-name`.

Why does pip say a package is installed, but my editor or script cannot find it?+

Your editor or script is probably using a different Python interpreter from the one pip installed into. Check the interpreter setting in your editor and compare it with `python -m pip --version` in the shell.

Can I install several packages at once?+

Yes. You can list multiple package names in one command or use a requirements file. A requirements file is usually better for anything you need to repeat later.

Sources & references

Guidance on this page is traced to documented sources. Last checked 25 September 2026.

  • Python Packaging User Guide · official

    Supports use of pip for package installation, virtual environments, and general Python packaging best practice.

  • pip Documentation · official

    Supports correct pip command usage, installation behaviour, requirements files, package inspection, and troubleshooting concepts.

  • Python Standard Library: venv · official

    Supports creation and use of virtual environments with the standard library.

The overall process stays stable, but command details and packaging best practice can change as Python and pip evolve.

Related guides

Legal Disclaimer: The information provided on Cost Check Now is for general informational and educational purposes only. It does not constitute financial, legal, professional, or any other form of advice. Cost Check Now makes no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability, or availability of any information, products, services, or related graphics contained on this website. Any reliance you place on such information is strictly at your own risk. In no event will Cost Check Now, its owners, operators, contributors, or affiliates be liable for any loss or damage including without limitation, indirect or consequential loss or damage, or any loss or damage whatsoever arising from loss of data or profits arising out of, or in connection with, the use of this website. Always seek independent professional advice before making financial or purchasing decisions.