Как установить pip на windows
Перейти к содержимому

Как установить pip на windows

  • автор:

Installing Python Modules¶

As a popular open source development project, Python has an active supporting community of contributors and users that also make their software available for other Python developers to use under open source license terms.

This allows Python users to share and collaborate effectively, benefiting from the solutions others have already created to common (and sometimes even rare!) problems, as well as potentially contributing their own solutions to the common pool.

This guide covers the installation part of the process. For a guide to creating and sharing your own Python projects, refer to the distribution guide .

For corporate and other institutional users, be aware that many organisations have their own policies around using and contributing to open source software. Please take such policies into account when making use of the distribution and installation tools provided with Python.

Key terms¶

pip is the preferred installer program. Starting with Python 3.4, it is included by default with the Python binary installers.

A virtual environment is a semi-isolated Python environment that allows packages to be installed for use by a particular application, rather than being installed system wide.

venv is the standard tool for creating virtual environments, and has been part of Python since Python 3.3. Starting with Python 3.4, it defaults to installing pip into all created virtual environments.

virtualenv is a third party alternative (and predecessor) to venv . It allows virtual environments to be used on versions of Python prior to 3.4, which either don’t provide venv at all, or aren’t able to automatically install pip into created environments.

The Python Package Index is a public repository of open source licensed packages made available for use by other Python users.

the Python Packaging Authority is the group of developers and documentation authors responsible for the maintenance and evolution of the standard packaging tools and the associated metadata and file format standards. They maintain a variety of tools, documentation, and issue trackers on both GitHub and Bitbucket.

distutils is the original build and distribution system first added to the Python standard library in 1998. While direct use of distutils is being phased out, it still laid the foundation for the current packaging and distribution infrastructure, and it not only remains part of the standard library, but its name lives on in other ways (such as the name of the mailing list used to coordinate Python packaging standards development).

Changed in version 3.5: The use of venv is now recommended for creating virtual environments.

Basic usage¶

The standard packaging tools are all designed to be used from the command line.

The following command will install the latest version of a module and its dependencies from the Python Package Index:

For POSIX users (including macOS and Linux users), the examples in this guide assume the use of a virtual environment .

For Windows users, the examples in this guide assume that the option to adjust the system PATH environment variable was selected when installing Python.

It’s also possible to specify an exact or minimum version directly on the command line. When using comparator operators such as > , < or some other special character which get interpreted by shell, the package name and the version should be enclosed within double quotes:

Normally, if a suitable module is already installed, attempting to install it again will have no effect. Upgrading existing modules must be requested explicitly:

More information and resources regarding pip and its capabilities can be found in the Python Packaging User Guide.

Creation of virtual environments is done through the venv module. Installing packages into an active virtual environment uses the commands shown above.

How do I …?¶

These are quick answers or links for some common tasks.

… install pip in versions of Python prior to Python 3.4?¶

Python only started bundling pip with Python 3.4. For earlier versions, pip needs to be “bootstrapped” as described in the Python Packaging User Guide.

… install packages just for the current user?¶

Passing the —user option to python -m pip install will install a package just for the current user, rather than for all users of the system.

… install scientific Python packages?¶

A number of scientific Python packages have complex binary dependencies, and aren’t currently easy to install using pip directly. At this point in time, it will often be easier for users to install these packages by other means rather than attempting to install them with pip .

… work with multiple versions of Python installed in parallel?¶

On Linux, macOS, and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip :

Appropriately versioned pip commands may also be available.

On Windows, use the py Python launcher in combination with the -m switch:

Common installation issues¶

Installing into the system Python on Linux¶

On Linux systems, a Python installation will typically be included as part of the distribution. Installing into this Python installation requires root access to the system, and may interfere with the operation of the system package manager and other components of the system if a component is unexpectedly upgraded using pip .

On such systems, it is often better to use a virtual environment or a per-user installation when installing packages with pip .

Pip not installed¶

It is possible that pip does not get installed by default. One potential fix is:

There are also additional resources for installing pip.

Installing binary extensions¶

Python has typically relied heavily on source based distribution, with end users being expected to compile extension modules from source as part of the installation process.

With the introduction of support for the binary wheel format, and the ability to publish wheels for at least Windows and macOS through the Python Package Index, this problem is expected to diminish over time, as users are more regularly able to install pre-built extensions rather than needing to build them themselves.

Some of the solutions for installing scientific software that are not yet available as pre-built wheel files may also help with obtaining other binary extensions without needing to build them locally.

Installing PIP on Windows

Ankit Garg

This is a comprehensive guide to install pip on windows OS.

Step 1: Install Python (if you already don’t have).
Python can be easily installed. Just go to https://www.python.org/downloads/ and download the version you need and install the setup.

Verify python installation by typing python —version in the command prompt and will display you the python version if you installing is successful. If somehow it shows any error there might be a problem with your environment variables.

Step 2: Download pip installation script.
Download get-pip.py , and make sure you save it as .py and not .txt
If you are facing any difficulties, just open the link as save page as get-pip.py

Step 3: Installing PIP
Run the get-pip.py script using command prompt.
Example:
C:\Users\ankit>python get-pip.py

Make sure that you are in the same directory in command prompt as where you have saved your get-pip.py file.
After this PIP will get successfully installed.

Step 4: Verifying Installation
You can verify if pip is correctly installed or not by running the following command in the command prompt.
pip —version
It should output something like this:
pip 9.0.1 from c:\users\ankit\appdata\local\programs\python\python36-32\lib\site-packages (python3.6)

Now you are ready to use pip. Make sure that you are using pip outside the python environment, some users start using pip commands inside python environment and get the following error:

So avoid this error by not using pip inside python but anywhere outside python environment. If anyhow your code requires pip, use can use it by importing pip first.

Python Crash Course

Resources for Python Crash Course (1st edition), from No Starch Press.

Resources for the second edition are here. I’d love to know what you think about Python Crash Course; please consider taking a brief survey. If you’d like to know when additional resources are available, you can sign up for email notifications here.

Pip: Installing Python Packages

Pip is a special program used to install Python packages to your system. Pip is sometimes included automatically when Python is installed to your system, and sometimes you have to install it yourself. These instructions will help you check if pip is on your system, and help you upgrade or install it if necessary.

Pip on Linux

Checking for pip on Linux

First, check whether pip is installed on your system:

The output of pip —version tells you which version of pip is currently installed, and which version of Python it’s set up to install packages for. This is especially helpful if you have more than one version of Python installed on your system.

If you have only one version of Python installed on your system, you can use pip to install packages. You might want to try upgrading pip first though.

If you have more than one version of Python installed on your system, you should also try the command pip3:

Here pip3 is set up to install to the same version of Python, but often times pip will install to Python 2. pip3, if you have it set up, should always install packages to the version of Python 3 you have installed.

Installing pip on Linux

To install pip, go to https://bootstrap.pypa.io/get-pip.py. Save the file if you’re prompted to do so; if the code for get-pip.py appears in your browser, copy and paste the entire program into your text editor and save the file as get-pip.py.

Open a terminal and navigate to the folder containing get-pip.py, and run it with administrative privileges:

After the program runs, use the command pip —version (or pip3 —version ) to make sure pip was installed correctly.

Upgrading pip on Linux

Once you have pip installed, it’s good to upgrade it from time to time. Usually pip will prompt you with instructions for how to upgrade it when necessary, but you can try to upgrade manually any time. For example, here’s sample output for upgrading an out-of-date version of pip:

Installing Python packages with pip on Linux

Once you have pip installed, most Python packages can be installed in one line. For example, here’s how you can install Requests, which is used to make API calls from Python programs:

Here pip has downloaded the files needed to install Requests, and then managed the installation for us. The —user flag means pip has made Requests available to us, but not to other users. This keeps each user’s Python packages from conflicting with each other on systems with more than one user. It’s a good idea to use this flag unless you have a specific reason not to.

Now you can start a Python terminal session, and import requests:

Here we’ve used requests to retrieve Google’s home page, and the status code of 200 tells us that the request was successful.

Uninstalling packages with pip on Linux

If you ever want to uninstall a package, you can use requests to do so as well:

Pip lists all the files that will be removed, prompts you about whether to proceed, and then uninstalls the package.

Pip on OS X

Checking for pip on OS X

First, check whether pip is installed on your system:

The output of pip —version tells you which version of pip is currently installed, and which version of Python it’s set up to install packages for. This is especially helpful if you have more than one version of Python installed on your system.

If you have only one version of Python installed on your system, you can use pip to install packages. You might want to try upgrading pip first though.

If you have more than one version of Python installed on your system, you should also try the command pip3:

Here pip3 is set up to install to the same version of Python, but often times pip will install to Python 2. pip3, if you have it set up, should always install packages to the version of Python 3 you have installed.

Installing pip on OS X

To install pip, go to https://bootstrap.pypa.io/get-pip.py. Save the file if you’re prompted to do so; if the code for get-pip.py appears in your browser, copy and paste the entire program into your text editor and save the file as get-pip.py.

Open a terminal and navigate to the folder containing get-pip.py, and run it with administrative privileges:

After the program runs, use the command pip —version (or pip3 —version ) to make sure pip was installed correctly.

Upgrading pip on OS X

Once you have pip installed, it’s good to upgrade it from time to time. Usually pip will prompt you with instructions for how to upgrade it when necessary, but you can try to upgrade manually any time. For example, here’s sample output for upgrading an out-of-date version of pip:

Installing Python packages with pip on OS X

Once you have pip installed, most Python packages can be installed in one line. For example, here’s how you can install Requests, which is used to make API calls from Python programs:

Here pip has downloaded the files needed to install Requests, and then managed the installation for us. The —user flag means pip has made Requests available to us, but not to other users. This keeps each user’s Python packages from conflicting with each other on systems with more than one user. It’s a good idea to use this flag unless you have a specific reason not to.

Now you can start a Python terminal session, and import requests:

Here we’ve used requests to retrieve Google’s home page, and the status code of 200 tells us that the request was successful.

Uninstalling packages with pip on OS X

If you ever want to uninstall a package, you can use requests to do so as well:

Pip lists all the files that will be removed, prompts you about whether to proceed, and then uninstalls the package.

Pip on Windows

Checking for pip on Windows

First, check whether pip is installed on your system. Open a terminal window and issue the following command:

The output of pip —version tells you which version of pip is currently installed, and which version of Python it’s set up to install packages for. This is especially helpful if you have more than one version of Python installed on your system.

If you have only one version of Python installed on your system, you can use pip to install packages. You might want to try upgrading pip first though.

If you have more than one version of Python installed on your system, you should also try the command pip3:

Here pip3 is set up to install to the same version of Python, but often times pip will install to Python 2. pip3, if you have it set up, should always install packages to the version of Python 3 you have installed.

Installing pip on Windows

To install pip, go to https://bootstrap.pypa.io/get-pip.py. Save the file if you’re prompted to do so; if the code for get-pip.py appears in your browser, copy and paste the entire program into your text editor and save the file as get-pip.py.

Open a terminal and navigate to the folder containing get-pip.py, and run it with administrative privileges:

After the program runs, use the command pip —version (or pip3 —version ) to make sure pip was installed correctly.

Upgrading pip on Windows

Once you have pip installed, it’s good to upgrade it from time to time. Usually pip will prompt you with instructions for how to upgrade it when necessary, but you can try to upgrade manually any time. For example, here’s sample output for upgrading an out-of-date version of pip:

Installing Python packages with pip on Windows

Once you have pip installed, most Python packages can be installed in one line. For example, here’s how you can install Requests, which is used to make API calls from Python programs:

Here pip has downloaded the files needed to install Requests, and then managed the installation for us. The —user flag means pip has made Requests available to us, but not to other users. This keeps each user’s Python packages from conflicting with each other on systems with more than one user. It’s a good idea to use this flag unless you have a specific reason not to.

Now you can start a Python terminal session, and import requests:

Here we’ve used requests to retrieve Google’s home page, and the status code of 200 tells us that the request was successful.

Uninstalling packages with pip on Windows

If you ever want to uninstall a package, you can use requests to do so as well:

Pip lists all the files that will be removed, prompts you about whether to proceed, and then uninstalls the package.

Python Crash Course is maintained by ehmatthes. This page was generated by GitHub Pages using the Cayman theme by Jason Long.

Installation#

If your Python environment does not have pip installed, there are 2 mechanisms to install pip supported directly by pip’s maintainers:

ensurepip #

Python comes with an ensurepip module [ 1 ] , which can install pip in a Python environment.

More details about how ensurepip works and how it can be used, is available in the standard library documentation.

get-pip.py #

This is a Python script that uses some bootstrapping logic to install pip.

Open a terminal/command prompt, cd to the folder containing the get-pip.py file and run:

More details about this script can be found in pypa/get-pip’s README.

Standalone zip application#

The zip application is currently experimental. We test that pip runs correctly in this form, but it is possible that there could be issues in some situations. We will accept bug reports in such cases, but for now the zip application should not be used in production environments.

In addition to installing pip in your environment, pip is available as a standalone zip application. This can be downloaded from https://bootstrap.pypa.io/pip/pip.pyz. There are also zip applications for specific pip versions, named pip-X.Y.Z.pyz .

The zip application can be run using any supported version of Python:

If run directly:

then the currently active Python interpreter will be used.

Alternative Methods#

Depending on how you installed Python, there might be other mechanisms available to you for installing pip such as using Linux package managers .

These mechanisms are provided by redistributors of pip, who may have modified pip to change its behaviour. This has been a frequent source of user confusion, since it causes a mismatch between documented behaviour in this documentation and how pip works after those modifications.

If you face issues when using Python and pip installed using these mechanisms, it is recommended to request for support from the relevant provider (eg: Linux distro community, cloud provider support channels, etc).

Upgrading pip #

Upgrade your pip by running:

Compatibility#

The current version of pip works on:

Windows, Linux and MacOS.

CPython 3.7, 3.8, 3.9, 3.10 and latest PyPy3.

pip is tested to work on the latest patch version of the Python interpreter, for each of the minor versions listed above. Previous patch versions are supported on a best effort approach.

Other operating systems and Python versions are not supported by pip’s maintainers.

Users who are on unsupported platforms should be aware that if they hit issues, they may have to resolve them for themselves. If they received pip from a source which provides support for their platform, they should request pip support from that source.

The ensurepip module was added to the Python standard library in Python 3.4.

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *