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

后端 未结 4 1493
余生分开走
余生分开走 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.

    0 讨论(0)
  • 2021-02-20 05:30

    With the latest virtualenv-1.7.1.2, try creating the virtualenv with the --distribute flag. I managed to solve the exact same problem you had by adding the flag.

    On a related note, on another machine (same OS, Windows Server 2008 R2), I had to create the virtualenv without the --distribute flag, otherwise whenever I run easy_install a new command prompt will pop open.

    Virtualenv on Windows is like a dark art.

    0 讨论(0)
  • 2021-02-20 05:36

    This is an old question, but come across this problem recently and I want to share what I did to make this work. I was looking for python kerberos implementation on windows, and I found kerbeors_sspi that uses pywin32. all of this is installed using pip, but pywin32 can't be installed using pip inside the virtualenv.

    So i patched the kerberos_sspi library to use pypiwin32, which is a wheel packaged by Glyph and el (twisted creator BTW). And now all of this works wonderfully, still if you want access the COM stuff you have to manually install pywin32 because it needs to be registered with the system.

    Here is the link to the pypiwin32 index

    Cheers,

    0 讨论(0)
  • 2021-02-20 05:45

    Unfortunately, support for 64bit Python on Windows is relatively poor than the 32bit version. It's not the fault of the Python community but the relative difficulty of getting free compilers for 64bit Windows.

    If you installed the 64bit version of Python, you also need to use packages built for 64bit. Some simple Python packages (those written in pure Python and not requiring external/C libraries) will install as normal using setuptools/easy_install/virtualenv. A lot of 64bit packages however might break when installed in virtualenv and will require an installer.

    Fortunately, you can find 64bit pre-compiled installers for popular packages here. Try the package there first. The installer will target the global/main installation of Python and thus is not isolated by virtualenv. Note however that these are unofficial builds: provided for free for your convenience so please don't sue the provider if things fail (or expect for help).

    0 讨论(0)
提交回复
热议问题