When python installs fitz pip to install modules, it prompts: No module named pip

fitz is a sub-library in the PyMuPDF library for processing PDF documents. After installing PyMuPDF with pip, you can use import to import fitz.

Only one command is needed:

pip install PyMuPDF -i https://pypi.tuna.tsinghua.edu.cn/simple

The installation is complete.

You can ignore the following analysis of possible problems and doubts

Problem: When using pip to install the PyMuPD module, it prompts: No module named pip

repair pip install

The specified version environment exists in a system with multiple versions of Python2 and Python3. The following uses only Python3 in the system as an example

  • 1. In Python 3.4+
Microsoft Windows [版本 10.0.19045.2728]
(c) Microsoft Corporation。保留所有权利。
 
C:\WINDOWS\system32>python -m ensurepip
Installing collected packages: pip
Successfully installed pip-22.3

The ensurepip package supports bootstrapping a pip installer into an existing Python installation or virtual environment.

  • 2. In Python 3 ≤ 3.3

Download the script from https://bootstrap.pypa.io/get-pip.py .

Open a terminal/command prompt, go to the folder containing the file and run:

 py get-pip.py

View pip version pip -V

Microsoft Windows [版本 10.0.19045.2728]
(c) Microsoft Corporation。保留所有权利。

C:\WINDOWS\system32>pip -V
pip 23.0.1 from C:\Python312\Lib\site-packages\pip (python 3.12)

It is mentioned in a blog post that you can also use easy_install to install pip

easy_install pip

The difference between easy_install and pip in linux and Windows

easy_install and pip are commonly used package management tools in Python. Although their functions are similar, there are still some differences between Linux and Windows.

In Linux:

How to use: easy_install and pip are used in the same way on the command line, but the command of pip is more concise and easy to use.

  • Different installation methods

easy_install is the package management tool installed by default in Python, which can be installed by the following command:

$ sudo apt-get install python-setuptools

pip can be installed with the following command:

$ sudo apt-get install python-pip

  • Different ways to install packages

The easy_install installation package is as follows:

$ sudo easy_install package_name

The way to install the package with pip is as follows:

$ sudo pip install package_name

  • The configuration files are different

The configuration file for easy_install is located at ~/.pydistutils.cfg, and the configuration file for pip is located at ~/.pip/pip.conf.

In Windows:

Installation method: easy_install has been built in Python, no additional installation is required, and pip needs to be installed separately.

Refer to Repair

The way to install the package with pip is as follows:

run at the command line

pip install package_name

Usage: The pip command line usage is simpler and clearer, and can quickly complete package installation, upgrade, uninstallation and other operations; the usage of easy_install is relatively more cumbersome, and parameters need to be specified manually.

The same points between easy_install and pip in linux and Windows

Package management : pip can automatically resolve dependencies, support installation and uninstallation of packages from PyPI, support installation of local and remote packages, etc.; and easy_install's dependency solution is relatively simple, and it also supports installation of local and remote packages. When resolving dependencies, Can't handle some complex dependencies, easy_install only considers direct dependencies, not indirect dependencies, if there are multiple versions of the same dependency, easy_install can't handle it either.

Version compatibility : pip only supports Python 2.7 and Python 3.4 and above, while easy_install supports Python 2.x and Python 3.x.

To sum up, pip is more powerful and convenient than easy_install in both Linux and Windows. It is recommended to use pip to manage Python packages. Its dependency solution is more complete and can automatically resolve complex dependencies.

update pip

The python environment is very slow when using the default installation when installing source files, but the domestic Tsinghua source is faster

C:\WINDOWS\system32>python -m pip install --upgrade pip -i https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pip in c:\python311\lib\site-packages (22.3)
Collecting pip
  Using cached pip-23.0.1-py3-none-any.whl (2.1 MB)
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.3
    Uninstalling pip-22.3:
      Successfully uninstalled pip-22.3
Successfully installed pip-23.0.1

Install PyMuPDF

C:\WINDOWS\system32>pip install PyMuPDF -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting PyMuPDF
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/aa/c0/2a7bfe118a5c965aa358da95fe77872d8d4fabadd14ed5f46a55b6ce7cc6/PyMuPDF-1.21.1-cp311-cp311-win_amd64.whl (11.7 MB)
     ---------------------------------------- 11.7/11.7 MB 203.3 kB/s eta 0:00:00
Installing collected packages: PyMuPDF
Successfully installed PyMuPDF-1.21.1
 

View the status of the PyMuPDF package, normal

C:\WINDOWS\system32>pip list
Package            Version
------------------ ----------
PyMuPDF            1.21.1

  • Install the latest version
    pip install PyMuPDF

  • Install the specified version
    pip install PyMuPDF==

View the fitz status of the PyMuPDF package component, normal

C:\WINDOWS\system32>python
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")

Please wait a moment while I gather a list of all available modules...

_testcapi           fitz                queue               zipimport

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".

>>>

test import, normal

C:\WINDOWS\system32>python
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fitz
>>>

PyMuPDF uses the documentation PyMuPDF Documentation
https://buildmedia.readthedocs.org/media/pdf/pymupdf/latest/pymupdf.pdf

install fitz using pip

C:\WINDOWS\system32>pip install fitz -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting fitz
  Downloading 
     --------------------------------------
Installing collected packages: fitz

Successfully installed fitz-0.0.1.dev2

View the fitz library installed by pip

C:\WINDOWS\system32>pip list
Package            Version
------------------ ----------
fitz               0.0.1.dev2

The difference between installing fitz with PyMuPDF and installing fitz with pip

  • Whether you install fitz with pip or install fitz with PyMuPDF, you can use the functions of the fitz library.

  • Installing fitz with pip only installs the fitz library itself, not the other features of the PyMuPDF library. This means that if you need to use other functions of the PyMuPDF library, you need to install the PyMuPDF library. Installing the PyMuPDF library will automatically install the fitz sub-library, and you can use the PyMuPDF library to include all the functions of the fitz sub-library.

  • If you use pip uninstall to uninstall the fitz installed by pip, it will delete the fitz in the PyMuPDF package components. In fact, the two installation methods are in the same location.

The fitz library update can be done by reinstalling PyMuPDF


C:\WINDOWS\system32>pip install --force-reinstall PyMuPDF -i https://pypi.tuna.tsinghua.edu.cn/simple
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting PyMuPDF
  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/aa/c0/2a7bfe118a5c965aa358da95fe77872d8d4fabadd14ed5f46a55b6ce7cc6/PyMuPDF-1.21.1-cp311-cp311-win_amd64.whl (11.7 MB)
Installing collected packages: PyMuPDF
  Attempting uninstall: PyMuPDF
    Found existing installation: PyMuPDF 1.21.1
    Uninstalling PyMuPDF-1.21.1:
      Successfully uninstalled PyMuPDF-1.21.1
Successfully installed PyMuPDF-1.21.1

Check the fitz status of the PyMuPDF package component again, it is normal

C:\WINDOWS\system32>python
Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> help("modules")

Please wait a moment while I gather a list of all available modules...

_symtable           fitz                pty                 winreg

Enter any module name to get more help.  Or, type "modules spam" to search
for modules whose name or summary contain the string "spam".

>>>

This article belongs to the original author, please indicate the source for reprinting.

Guess you like

Origin blog.csdn.net/u013669912/article/details/129622828