简体   繁体   English

未找到pythoncom模块(安装了pywin32)-带有Python2.7虚拟环境

[英]pythoncom module not found (pywin32 is installed) - with a Python2.7 virtual environment

I need to set up a Windows 64-bit PC Virtual Environment with Python 2.7 to run a script that I didn't write, and I'm not entirely sure the usage it has, but it imports pythoncom (a .NET communication module as far as I could understand).我需要使用 Python 2.7 设置 Windows 64 位 PC 虚拟环境来运行我没有编写的脚本,我不完全确定它的用途,但它导入了 pythoncom(一个 Z303CB0EF59EDB9082DAZ1 通信模块 far58255据我所知)。

It seems that the module exists in pywin32 and pypiwin32 (installed both), I can see the module is installed in the environment when typing "pydoc modules" and "pydoc pythoncom", but it still fails to import the module when running the script.好像模块存在于pywin32和pypiwin32中(都安装了),我在输入“pydoc modules”和“pydoc pythoncom”时可以看到该模块已安装在环境中,但是在运行脚本时仍然无法导入模块。

I can only use pywin32-244, it has a.dll named pythoncom27.dll inside its wheel file, I can't seem to find a workaround, anyone knows why it might happen?我只能使用pywin32-244,它的wheel文件中有一个名为pythoncom27.dll的.dll,我似乎找不到解决方法,有人知道为什么会发生吗? (all of the versions I gave are not optional (for python, the package) - I cannot change them they has to remain the same) (我提供的所有版本都不是可选的(对于 python,包)-我无法更改它们,它们必须保持不变)

Furthermore - In newer versions of python3.x it's running fine.此外 - 在较新版本的 python3.x 中,它运行良好。 from the python CommandLine I can actually import it?从 python 命令行我实际上可以导入它吗? any reason for me to be able to import it and see it in all of the mentioned ways and still not to be able to import it via a script?我有什么理由能够导入它并以所有提到的方式查看它,但仍然无法通过脚本导入它? maybe something wrong with the script or the way im running it?也许脚本或我运行它的方式有问题?

Also might be important - the script that gives the error is just imported through another script, so I'm actually running T1.py which then imports T2.py which gives the error when trying to import pythoncom...也可能很重要 - 给出错误的脚本只是通过另一个脚本导入的,所以我实际上正在运行 T1.py,然后导入 T2.py,它在尝试导入 pythoncom 时给出错误...

Thanks in Advance!提前致谢! Oren奥伦

The problem was that I wasn't using the virtualenv to run the script, after activating the virtualenv, typing in the cli "script.py" will execture the script from the system's default python env, even though it says (Venv) in the cli, To run it in the Venv's python environment you need to type in 'python script.py'问题是我没有使用 virtualenv 来运行脚本,在激活 virtualenv 后,输入 cli“script.py”将从系统默认的 python env 中执行脚本,即使它在cli,要在 Venv 的 python 环境中运行它,您需要输入“python script.py”

Oren奥伦

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM