Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

import problem on a fresh AWS EC2 #1803

Open
jrobbins-LiveData opened this issue Nov 22, 2021 · 3 comments
Open

import problem on a fresh AWS EC2 #1803

jrobbins-LiveData opened this issue Nov 22, 2021 · 3 comments

Comments

@jrobbins-LiveData
Copy link

(Note: I've read the entry point caveat, but am still in need of some guidance.)

  • Steps to reproduce the problem.
    On a freshly created AWS EC2 (running a Windows_Server-2019-English-Full-Base-2021.11.10 AMI), there's a folder in the System Path that has an older version of Python DLLs, including pythoncom39.dll. But I didn't know that, at first.

I installed Python 3.9.9 using pyenv-win. I then ran the following commands:

md pywin32-test2
cd pywin32-test2
python -m venv .venv
.venv\scripts\activate
python -m pip install -U pip
pip install pywin32
python -c "import win32com.client"
  • Expected behavior and actual behavior.
    I expected no problem from the import win32com.client. But instead, this popped up

image

I started to investigate, and saw this

image

And in the C:/Program Files/Amazon/cfn-bootstrap folder

image

Here are the "details" of pythoncom39.dll in the cfn-bootstrap folder

image

The question I have is centered on the Python virtual environment. Since the virtual environment puts its Scripts folder at the head of the Path

Path=C:\Users\Administrator\Documents\projects\pywin32-test2\.venv\Scripts

I was expecting to be protected from stray Python files outside my project. The pywin32 README.md says

The possible solutions are:

  • Run the "post_install" script documented above.

  • Otherwise, find and remove all other copies of pywintypesXX.dll and pythoncomXX.dll (where XX is the Python version - eg, "39")

But I don't see the "post_install" script documented above. Does that script know about virtual environments? Would it copy the two DLLs (pythoncom39.dll and pywintypes39.dll) from site-packages\pywin32_system32into my.venv\Scripts` folder? I ask, because I don't want to put things in the global system32 folder.

Also, the "Entry Point Not Found" popup happens here. If the load algorithm could be made virtual environment aware, perhaps it could explicitly check in site-packages\pywin32_system32` before letting the Windows Path burst the bubble of the virtual environment?

I noticed that after letting Windows look elsewhere, there this subsequent check. What is the rationale for this code coming later? If there's a virtual environment that it is "active", tested by checking the path, it seems like it would be better to find the DLLs in its site-packages\pywin32_system32` , than on the System Path.

Anyway, I was hoping for a bit of discussion about this, or pointers to reading material if it has all be discussed before.

I'll also open an issue with AWS, because I don't understand why they left this folder (in the Path, no less), causing problems with a fresh virtual environment install of pywin32.

  • Version of Python and pywin32
    Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] on win32
    pywin32==302
@mhammond
Copy link
Owner

mhammond commented Dec 3, 2021

Sorry for the delay here:

But I don't see the "post_install" script documented above. Does that script know about virtual environments? Would it copy the two DLLs (pythoncom39.dll and pywintypes39.dll) from site-packages\pywin32_system32into my.venv\Scripts` folder? I ask, because I don't want to put things in the global system32 folder.

That script is pywin32_postinstall.py - I'll try and remember to update the docs to make that clearer. It will try and copy to system32, but unless this is done from an elevated command prompt it will not be able to, in which case it will copy it next to pythonXX.dll.

That almost certainly could be improved for virtual envs and I'd welcome PRs - see also #1794 which might make life a bit better and some user's report it does help when running in a virtualenv, and may even help this exact case. If you can test the artifacts from that PR I'd welcome any feedback you have.

@jrobbins-LiveData
Copy link
Author

jrobbins-LiveData commented Dec 5, 2021

I tried this on the AWS EC2 (using a .whl from the artifacts from that PR):

python --version
Python 3.9.9

md artifact
cd artifact
python -m venv .venv
.venv\Scripts\activate
pip install pywin32-302.1-cp39-cp39-win_amd64.whl
python -c "import win32com.client"

and, no error popup!

Is there some way in the Python REPL that I can show I'm running the correct pywin32?

@eabase
Copy link

eabase commented Jan 29, 2022

@jrobbins-LiveData
try: print('Location: {}\nVersion: {}\n'.format(win32com.__file__, win32com.__version__))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants