Pip creates build/ directories

2019-01-23 06:36发布

问题:

I use virtualenv to create isolated environments for my Python projects. Then i install dependencies with pip - Python package manager. Sometimes i forget to do source venv/bin/activate, and then pip creates build/ directories inside my projects. Why does pip create them? May i delete them, and if not, may i put them in my .hgignore file?

As far as i understand, pip stores source of downloaded packages there along a file called pip-delete-this-directory.txt. But when i delete it, everything still works, as the real code is being put into venv/lib/python2.7/site-packages/. Then what is build/ really for?

回答1:

The build directory is where a packages gets unpacked into and build from. When the package is installed successfully, pip removes the unpacked dir from build, unless you've removed pip-delete-this-directory.txt. As described in pip-delete-this-directory.txt:

This file is placed here by pip to indicate the source was put
here by pip.

Once this package is successfully installed this source code will be
deleted (unless you remove this file).

Thus its less important for runtime environment. You could ignore it safely.

Also, you could use pip install -b customized_build_directory to specify another directory as build base directory, for example /tmp

Furthermore, you could pip install --no-download package_name to rebuild the package w/o downloading it, if the previous installation of the package failed.



回答2:

the -b option does not seem to work for me in cases when build fails for some reason that only Visual Studio can fix right now I need _sodium.c and sadly pip deletes it when I do not want it too as I need a copy of that file.