[Python pip special usage] pip install -v -e . command detailed explanation

Table of contents

foreword

analyze

in conclusion

postscript


foreword

I have been using pip install -v -e . when using codes including large documents (Shangtang Technology, Baidu Feijiang) before, this command, but I have never been very clear about "what" it is.

  • It must be used after modifying some configuration files of the code file, otherwise an error will be reported!
  • He appeared in the user documentation of SenseTime.

Encountered when studying the mmdetection document of Shangtang Technology:

 

 (1) When installing mmcv, it uses something like pip install -e .

(2) When installing mmdet, he used this command again.


analyze

Before the analysis, we need to talk about a knowledge point: what is  a namespace package ?

When we right-click a folder, we can find an option as follows:

Namespaced packages are a way to group related packages or modules, an often overlooked feature that can be very useful for building a packaging ecosystem in larger projects .
Namespaced packages are especially useful if your application components are developed, packaged, and versioned independently, but you still want to access them from the same namespace. It helps to clarify which organization or project each package belongs to.

Why talk about this, because in the code we downloaded, there is a folder that is a namespace package:

Regarding  the interpretation of the namespace package, let's go here first, knowing that it is for the convenience of users and can be freely modified.

I have also analyzed it for a while, and I already have an understanding, so I won’t play tricks with everyone, and I will directly start to say the conclusion:

First of all, everyone should be familiar with the pip install before this command , and the following -v -e . should be divided into   three parts -v , -e , .

  • -v: verbose, or more output. (output more detailed information)
  • -e: installing a project in editable mode. (install the project in editable mode)
  • . : A dot, which represents a relative path, that is, the current path (represents a path)

Note: I translated it myself, don't spray~~~

First, I put the mmdetection project folder under the lalala folder, cd into the folder, and execute pip install -e. Command:

After that, I came to the lalala folder path and executed the pip install -e .\mmdetection-master\  command:

 They actually performed the same operation! ! ! (Well, I just proved that the point is a path~~~)

alright! Next, I will take a screenshot of the entire execution process of pip install -e .:

Note: I have installed all the libraries here, so he just checked it once and passed.

For everyone, see:

  • He installed the dependencies in requirements.txt again.
  • He uninstalled and reinstalled the mmdet library . <this is a namespace package >

For me:

  • He executed setup.py again! (Use the command  python setup.py develop !)

Note: As for how setup.py works, this is another subject of knowledge~~~ I won’t expand on it in detail here [Goutou Baosheng], and I may write another blog to talk about it when I have time. 

For many friends, they think that -e. is to install the namespace package under the current folder   into the third-party library. This is wrong. For example, if I delete setup.py , he will Error:

Heredeleted setup.py :

Then run pip install -e . :

If you are still not convinced, I think this has something to do with   requirements.txt : (I  deleted requirements.txt  again)

 Note: Here I not only deleted  requirements.txt  , but also deleted  the requirements folder .

If you are still not convinced, you can install this namespace package into the package manager (third-party library) by specifying mmdet directly with -e : (I changed the execution command to pip install -e mmdet )

Got it. . I lost my temper.


in conclusion

Alright, we can almost draw conclusions:

  • Namespace software package: here refers to the modifiable embodiment of the mmdet library, that is, if it is a normal third-party library, it is generally only in readable mode , but using the namespace software package method can realize the modification of the third-party library Revise.
  • For  namespace packages , it is only used as a tag, not the direct execution object of pip install -e .
  • The direct execution object of pip install -e. is setup.py under the current file.
  • setup.py contains commands to execute, that is, install dependencies and  reinstall namespace software  into the package manager.

Summary of usage:

  • The configuration you modified under the mmdet package is not directly loaded into the third-party library, that is, after the modification, the environment does not change to the one you modified.
  • The mmdet imported in mmdetection is the mmdet library in your anaconda (that is, in your package manager), not your mmdetection-master/mmdet folder.

Comparison of mmdet and mmdetection-master in the third-party library :

mmdet third-party library:

 

 The mmdet package in mmdetection-master :

Yo, it's quite similar~~~ At least the big difference is not bad


postscript

You may not be very comfortable with this method of dynamically modifying the third-party library, but it is designed to facilitate us to modify the third-party library. Don’t refuse, try to use it, and study the methods patiently. Same harvest!

Guess you like

Origin blog.csdn.net/m0_61139217/article/details/125784977