How to install pywin32 in virtualenv with python 2.7 64 bit?

后端 未结 4 1863
余生分开走
余生分开走 2021-02-20 04:52

I wonder right way to install on virtualenv with 64 bit python 2.7 pywin32 module (Operating system is Windows 7 64 bit).
I\'ve found exe installer on Sourceforge.

4条回答
  •  轮回少年
    2021-02-20 05:18

    I figured this out, but the process isn't pleasant.

    There are 3 problems with the PyWin32 installer:

    1. It reads your python install location out of the registry.
    2. Is assumes that your lib directory is a child of the directory containing python.exe
    3. It dumps 3 dlls to %WINDIR%\system32

    So if you're running 64 bit python 2.7 on 64 bit windows or 32 on 32 and your virtual environment is in c:\scratch\env1\ the process looks like this:

    1. Copy python.exe and pythonw.exe from c:\scratch\env1\scripts to c:\scratch\env1
    2. Update the value "(default)" in the registry key HKLM\SOFTWARE\Python\PythonCore\2.7\InstallPath\ to "c:\scratch\env1\" (make sure you record the old value.)
    3. From the command line, where you've activated the virtual environment, install PyWin32 by running the installer.exe directly. Do not use easy_install.
    4. Set the InstallPath registry key back to the original value
    5. Delete python.exe and pythonw.exe from c:\scratch\env1\
    6. move pythoncom27.dll, pywintypes27.dll and pythoncomloader27.dll from %WINDIR%\system32\ to c:\scratch\env1\ (do not move python27.dll or you'll regret it)

    This works well enough to run django-mssql in the virtual environment without having pywin32 installed outside of the virtual environment.

提交回复
热议问题