Assume I have a virtualenv installation that does not use --no-site-packages. I run bin/pip install somepackage==1.0.0, but it’s already present in my site-packages so it’s not installed. Later, the copy installed site-packages is updated to somepackage==2.0.0.
What will happen in my virtualenv? Will it use the version 2, or download version 1 for itself?
It depends. If none of the packages that are importing
somepackageuse thesetuptoolsAPI, then it works as described above. If any packages in your virtualenv usesetuptools(orDistribute) to specify specific version requirements forsomepackage,setuptoolswill search for a version ofsomepackagethat meets the requirements. If it can’t find a suitable installed version at install time, it will search externally and attempt to install it. If it can’t find one at runtime, the program fails with an exception.For example, if
somepackage 1.0.0was already installed in the system site-packages, everything is fine. If you then update the system site-packages tosomepackage 2.0.0withpip, which uninstalls the old version, the script will fail at runtime with:If you installed both versions of
somepackagewitheasy_installinstead ofpip, things would normally be different. By default,easy_installdoes not uninstall packages and it supports multiple versions of packages (multi-version eggs). So both versions ofsomepackagewould be available in the system site-packages and the script would not fail.setuptools(and theDistributeclone of it) has to jump through many hoops to make the multiple version support work reasonably. Many developers frown on all that extra complexity and argue that it is easier and more transparent to support multiple versions of packages with separatevirutalenv‘s and, for that, the simpler model ofpipis more appropriate. (In fairness tosetuptools,virtualenvcame along later.)