17

I have installed both virtualenv and pywin32 on my Windows 7 64-bit laptop, and each of them seems to work, but not with each other.

More specifically, if a virtualenv is active, then running import win32com.client in a python interactive shell fails with No module named win32com.client. The same expression succeeds, however, if no virtualenv is active.

When I try to install pywin32 with pip (which is how I normally install modules when a virtualenv is active), I get the error:

  Could not find any downloads that satisfy the requirement pywin32
No distributions at all found for pywin32

...even though pywin32 is one of the modules listed in the output of

pip search pywin32

Therefore, to install pywin32 at all I had to install it using an *.exe installer downloaded from SourceForge.

Is there any way to install pywin32 within a virtualenv?

Clay Records
  • 329
  • 3
  • 16
kjo
  • 27,601
  • 42
  • 124
  • 225
  • 4
    `pip install pypiwin32` might work. – Marius Gedminas Dec 10 '15 at 09:24
  • Possible duplicate of [How can I use pywin32 with a virtualenv without having to include the host environment's site-packages folder?](http://stackoverflow.com/questions/1830304/how-can-i-use-pywin32-with-a-virtualenv-without-having-to-include-the-host-envir) – ivan_pozdeev Apr 19 '17 at 01:27

3 Answers3

34

UPDATE 2016

There is now a version of pywin32 on PyPI that can be installed with pip. It is called pypiwin32, and it installs the package using the binary wheel format.

https://pypi.python.org/pypi/pypiwin32

pip install pypiwin32

That will work in a virtualenv, or with tox, etc.


Below this line is my previous old answer. That is now outdated information.

OLD ANSWER - OUTDATED. Modern versions of virtualenv default to --no-site-packages. That means that not having access to global site-packages is now the default behavior. Sadly, (as of July 2014) you can not pip install pywin32 in to your virtualenv. (here's the bug report) If you want to get pywin32 running inside a virtualenv, activate the virtualenv and use easy_install and the pywin32 installer exe file. For example easy_install "C:\Path\To\Downloads\pywin32-219.win32-py3.4.exe"

Related question

Community
  • 1
  • 1
Christian Long
  • 6,799
  • 2
  • 52
  • 51
6

Try this:

  1. Download directly
  2. Enable your virtualenv
  3. pip install --no-index --find-links:/local/dir/ SomePackage

Check out #8 on pip-installer.org (sorry no permalink)/

chirinosky
  • 4,206
  • 1
  • 19
  • 35
2

Create a virtualenv and activate it: cd c:\Users\ernesto.luzon virtualenv --no-site-packages py351env py351env\Scripts\activate

From here, you have two options:

  1. Download pywin32 from sourceforge project: http://sourceforge.net/projects/pywin32/files/pywin32/

  2. Download pywin32 from unofficial (but very helpful) binary site: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pywin32

Make sure you download the correct version for the Python Interpreter installed in your environment, otherwise you will encounter ImportError: DLL load failed: %1 is not a valid Win32 application later.

If you downloaded from sourceforge, install it using easy_install: (py351env) C:\Users\ernesto.luzon\Downloads>easy_install pywin32-220.win-amd64-py3.5.exe

If you downloaded from gohlke, install it using pip: (py351env) C:\Users\ernesto.luzon\Downloads>pip install pywin32-220-cp35-none-win_amd64.whl

In case you encounter ImportError: DLL load failed: The specified module could not be found error later on, you need these additional steps:

Run the post install script: (py351env) C:\Users\ernesto.luzon>python py351env\Scripts\pywin32_postinstall.py -install Copied pythoncom35.dll to C:\Users\ernesto.luzon\py351env\pythoncom35.dll Copied pywintypes35.dll to C:\Users\ernesto.luzon\py351env\pywintypes35.dll ....

Notice where it copied the 'pythoncom35.dll' and 'pywintypes35.dll' files. You need to move these files to the folder: C:\Users\ernesto.luzon\py351env\Lib\site-packages\win32

Community
  • 1
  • 1
ldiary
  • 404
  • 2
  • 7