Python Forum
Has anyone figured out how to get pywin32 into a virtual environment yet?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Has anyone figured out how to get pywin32 into a virtual environment yet?
#1
People have been trying for years to get pywin32 to work inside a virtual environment, and it seems nobody has succeeded yet. At least, all the unanswered questions about how to do it are swamping the few questions that have received answers. I need to have my Python script use COM to communicate with an ActiveX program, and so I need win32com.client.Dispatch(), and so I need pywin32.

I've read that pypiwin32 is the currently favored module, but it depends on pywin32. I can load pywin32 into my registered copy of Python with no trouble, but I want to be able to use a virtual environment.

So how do I do it? My venv is based on the 32-bit version of Python 3.8. If I need to switch to 64 bits, I can.
Reply
#2
pywin32 is supported through Python 3.7
I couldn't load it on 3.8.1
Obviously if pypiwin32 is dependent on pywin32 this is a game stopper.
You can go to github: https://github.com/mhammond/pywin32
and contact the author from there. Perhaps he is not aware of this limitation.
Reply
#3
(Jun-01-2020, 08:45 PM)Larz60+ Wrote: People have been trying for years to get pywin32 to work inside a virtual environment, and it seems nobody has succeeded yet.
Then i most have been lucky as done this a lot of times Wink
Here a run.
# Make
C:\Python38
λ python -m venv py32_env

# cd in
C:\Python38
λ cd py32_env\

# Activate
C:\Python38\py32_env
λ C:\Python38\py32_env\Scripts\activate

# Test pip
C:\Python38\py32_env
(py32_env) λ pip -V
pip 19.2.3 from c:\python38\py32_env\lib\site-packages\pip (python 3.8)

# Install
C:\Python38\py32_env
(py32_env) λ pip install pywin32
Collecting pywin32
  Downloading .....
Successfully installed pywin32-227

# Test that it work
C:\Python38\py32_env
(py32_env) λ python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import win32com.client as win32
>>>
>>> win32.pythoncom
<module 'pythoncom' (C:\Python38\py32_env\lib\site-packages\pywin32_system32\pythoncom38.dll)>
>>>
>>> exit()
Reply
#4
I also didn't have problem running it on virtual environment.
Also note that you should use pywin32. pypiwin32 was just a repackaging of earlier version of pywin32 [Python for Windows Extension] when it was not installed via wheels and not available on pypi. At that time (before version 2.2.2.) the homepage was on sourceforge.net and downloads were available there as exe installers. Probably these are the [hard] times you refer to - before 2018. Now homepage is on GitHub and it's also available on PyPi as wheel files.
Current version of pywin32 is 2.2.7 updated in Nov 2019, while pypiwin32 is 2.2.3 and not updated since Feb 2018 and will never be updated, because there is no need of it now.
Current version supports incl. 3.9 and both 32-bit and 64-bit
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Quote:People have been trying for years to get pywin32 to work inside a virtual environment, and it seems nobody has succeeded yet.
I didn't write that
Reply
#6
(Jun-02-2020, 10:28 AM)Larz60+ Wrote: I didn't write that
It happens by mistake - when one select a text in a post and then click quote selected text button below another post. I guess @snippsat will fix it, or you can correct the quote in his post
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
My thanks to Snipsat for the screenshot of how he was able to do it, and to all in this thread for helpful replies. I replicated Snipsat's commands from my Python folder, and they worked. I do not know why I was having trouble.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with creating folder and "virtual environment" AudunNilsen 1 171 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  Installing python packages in a virtual environment Led_Zeppelin 1 712 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Problem with virtual environment standenman 2 944 Feb-23-2023, 07:09 PM
Last Post: standenman
Question Virtual Environment (using VS Code) Ashcora 4 12,489 Feb-15-2023, 07:17 PM
Last Post: snippsat
  How to find PyWin32 for Python 2.1.3 Paul_Newton 9 1,621 Nov-20-2022, 09:15 PM
Last Post: Paul_Newton
  pywin32: Outlook connection ends with 'operation aborted' on one machine tstone 0 2,323 May-03-2022, 04:29 AM
Last Post: tstone
  pywin32 problems catlessness 0 1,184 Apr-01-2022, 01:04 PM
Last Post: catlessness
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,331 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  Project structure with a virtual environment gdbengo 1 1,389 Jan-26-2022, 03:22 PM
Last Post: snippsat
  pywin32 Illustrator Throwing Exception Error matthewsjc1 7 5,401 Aug-27-2021, 02:43 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020