Repository: pypa/pip

Issue:
pip on windows
Prerequisites:
Windows
python 2.7
setuptools 3.6
easy_install
pip

Problem:
we have a requirements file that contains "pyinstaller" package dependency. I suppose that it somehow depends on cryptography and it in its turn somehow depends on cffi package and that's why it tries to install it as well. For now we specify this depency in a following way:

pyinstaller==2.1.1dev-89e99dd # from requirements file.

Next we try to install our pack of requirements with 

pip -f {our additional private repository} -U -egg -r {requirements file name}

From the build log screenshot attached you can see the following string(build_log attachment):

[12:59:39]:  [Step 7/15] Installed c:\users\administrator\envs\python27-32bit\lib\site-packages\cryptography-0.3-py2.7-win32.egg
[12:59:39]:  [Step 7/15] 
[12:59:39]:  [Step 7/15] error: c:\buildagent\temp\buildtmp\easy_install-snsbak\cryptography-0.3\cffi-0.8.2-py2.7-win32.egg_cffi_backend.pyd: Access is denied

I've done a few of investigation and attached a screenshot of related file activity with a highlighted important items (file_activity_list attachment). It seems that python cannod delete this _cffi_backend.pyd file. A few more investigation revealed that the file creation mode allows to delete this file(file_open_result attachment). From the event properties(event_properties attachment) I see that all related modules appear as if they are loaded using LoadLibray windows api, that's how it supposed to be done with python C extensions if we want to use this code. But it appears to me that someone forgot to unload all these modules before trying to delete them and that's why the file cannot be deleted. Please refer to _cffi_backend_loading attachment - it proves _cffi_backend.pyd is being loaded as a library(WinDbg screen). And the very next screenshot is the state of pip install command when WinDbg broke on module load - _break_python_screen attachment. Yet I pointed out the same problem if I just parse this requirements file with pkg_tools and specify install_requires setup's argument with these requirements - setup develop fails with the same result. As to me this problem more relates to easy_install/setuptools core. And yet to mention - without '--egg' argument the problem doesn't reproduce.

![file_activity_list](https://cloud.githubusercontent.com/assets/7242142/3082926/4def0fa4-e4db-11e3-8e14-37f52ea5b2ee.png)
![event_properties](https://cloud.githubusercontent.com/assets/7242142/3082956/ba432474-e4db-11e3-8d6f-5d0996c35a44.png)
![file_open_result](https://cloud.githubusercontent.com/assets/7242142/3082983/1417a8e4-e4dc-11e3-9289-0bf61c7cf2c9.png)

![build_log](https://cloud.githubusercontent.com/assets/7242142/3082887/b8bc80e2-e4da-11e3-945a-a0c1137bb6bb.png)
![_cffi_backend_loading](https://cloud.githubusercontent.com/assets/7242142/3160093/dddbe462-eb1a-11e3-8e08-48cfade1b261.png)
![_break_python_screen](https://cloud.githubusercontent.com/assets/7242142/3160112/29cc9c0e-eb1b-11e3-88a6-2601f7a8dbe5.png)



Discussion:
Has anybody ever had a look over this issue?


Resolving patch:
diff --git a/pip/_vendor/requests/__init__.py b/pip/_vendor/requests/__init__.py
--- a/pip/_vendor/requests/__init__.py
+++ b/pip/_vendor/requests/__init__.py
@@ -49,11 +49,13 @@
 __copyright__ = 'Copyright 2016 Kenneth Reitz'
 
 # Attempt to enable urllib3's SNI support, if possible
-try:
-    from .packages.urllib3.contrib import pyopenssl
-    pyopenssl.inject_into_urllib3()
-except ImportError:
-    pass
+# Note: Patched by pip to prevent using the PyOpenSSL module. On Windows this
+#       prevents upgrading cryptography.
+# try:
+#     from .packages.urllib3.contrib import pyopenssl
+#     pyopenssl.inject_into_urllib3()
+# except ImportError:
+#     pass
 
 import warnings
 
diff --git a/pip/_vendor/requests/compat.py b/pip/_vendor/requests/compat.py
--- a/pip/_vendor/requests/compat.py
+++ b/pip/_vendor/requests/compat.py
@@ -21,12 +21,14 @@
 #: Python 3.x?
 is_py3 = (_ver[0] == 3)
 
-try:
-    import simplejson as json
-except (ImportError, SyntaxError):
-    # simplejson does not support Python 3.2, it throws a SyntaxError
-    # because of u'...' Unicode literals.
-    import json
+# Note: We've patched out simplejson support in pip because it prevents
+#       upgrading simplejson on Windows.
+# try:
+#     import simplejson as json
+# except (ImportError, SyntaxError):
+#     # simplejson does not support Python 3.2, it throws a SyntaxError
+#     # because of u'...' Unicode literals.
+import json
 
 # ---------
 # Specifics


Test patch: