Python win32 on linux

Writing a Python Script which uses pyWin32 in Kali Linux

I’m trying to make a Python script which runs in windows, but because of reasons I have to write it in Kali Linux. Since it doen’t exist on Linux, I can’t add the additional libraries I need. Should I give up and write it under Windows? If I simply put in my imports and commands in my program, will they work when the script will be run in a Windows machine?

I do have to ask why you’re attempting coding on Kali? It’s a specialised distribution for designed penetration testing.

1 Answer 1

You can’t install pywin32 on Kali Linux because it’s only available for Windows. It provides access to the Win32 APIs and to COM objects, and a Python program intended to work on any Linux distribution shouldn’t need those (or it should only attempt to use them conditionally).

You could always try running Python under Wine but I suspect that would involve losing sight of what you were originally trying to do.

You must log in to answer this question.

Hot Network Questions

Subscribe to RSS

To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.17.43537

Linux is a registered trademark of Linus Torvalds. UNIX is a registered trademark of The Open Group.
This site is not affiliated with Linus Torvalds or The Open Group in any way.

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

Источник

pywin32

This is the readme for the Python for Win32 (pywin32) extensions, which provides access to many of the Windows APIs from Python.

See CHANGES.txt for recent notable changes.

Only Python 3 is supported. If you want Python 2 support, you want build 228 .

Docs

The docs are a long and sad story, but there’s now an online version of the helpfile that ships with the installers (thanks @ofek!). Lots of that is very old, but some is auto-generated and current. Would love help untangling the docs!

Support

Feel free to open issues for all bugs (or suspected bugs) in pywin32. pull-requests for all bugs or features are also welcome.

However, please do not open github issues for general support requests, or for problems or questions using the modules in this package — they will be closed. For such issues, please email the python-win32 mailing list — note that you must be subscribed to the list before posting.

Читайте также:  Смарт тв sony linux

Binaries

Installing via PIP

You should install pywin32 via pip — eg,

python -m pip install —upgrade pywin32

If you encounter any problems when upgrading (eg, «module not found» errors or similar), you should execute:

python Scripts/pywin32_postinstall.py -install

This will make some small attempts to cleanup older conflicting installs.

Note that if you want to use pywin32 for «system wide» features, such as registering COM objects or implementing Windows Services, then you must run that command from an elevated (ie, «Run as Administrator) command prompt.

For unreleased changes, you can download builds made by github actions — choose any «workflow» from the main branch and download its «artifacts»)

The specified procedure could not be found / Entry-point not found Errors?

A very common report is that people install pywin32, but many imports fail with errors similar to the above.

In almost all cases, this tends to mean there are other pywin32 DLLs installed in your system, but in a different location than the new ones. This sometimes happens in environments that come with pywin32 pre-shipped (eg, anaconda?).

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»)

Running as a Windows Service

Modern Python installers do not, by default, install Python in a way that is suitable for running as a service, particularly for other users.

  • Ensure Python is installed in a location where the user running the service has access to the installation and is able to load pywintypesXX.dll and pythonXX.dll .
  • Manually copy pythonservice.exe from the site-packages/win32 directory to the same place as these DLLs.

Building from source

Install Visual Studio 2019 (later probably works, but options might be different), select «Desktop Development with C++», then the following options:

  • Windows 10 SDK (latest offered I guess? At time of writing, 10.0.18362)
  • «C++ for MFC for . «
  • ARM build tools if necessary.

(the free compilers probably work too, but haven’t been tested — let me know your experiences!)

setup.py is a standard distutils build script, so you probably want:

Some modules need obscure SDKs to build — setup.py should succeed, gracefully telling you why it failed to build them — if the build actually fails with your configuration, please open an issue.

Release process

The following steps are performed when making a new release — this is mainly to form a checklist so mhammond doesn’t forget what to do 🙂

  • Ensure CHANGES.txt has everything worth noting, commit it.
  • Update setup.py with the new build number.
  • Execute build.bat, wait forever, test the artifacts.
  • Upload .whl artifacts to pypi — we do this before pushing the tag because they might be rejected for an invalid README.md . Done via py -3.? -m twine upload dist/*XXX*.whl .
  • Commit setup.py (so the new build number is in the repo), create a new git tag
  • Upload the .exe installers to github.
  • Update setup.py with the new build number + «.1» (eg, 123.1), to ensure future test builds aren’t mistaken for the real release.
  • Make sure everything is pushed to github, including the tag (ie, git push —tags )
  • Send mail to python-win32
Читайте также:  Hacking wireless networks linux

Источник

Install win32com on MacOs and Linux

enter image description here

My question is simple: can I install win32com python API ( pywin32 notably) on an OS that is not Windows? I have been trying, on Mac, multiple versions of pip install pywin32 , all have failed. An example below: If you managed to install it on Linux I am also interested as I wrote it. I am using python 3.7.8. Thanks.

Ok, thanks for the semantic correction. What about the fact to install the python library on mac and Linux?

1 Answer 1

Win32COM is part of [GitHub]: mhammond/pywin32 — pywin32.
According to the (above) URL, the package is only designed to work on Win:

Python for Win32 (pywin32) extensions

So, this is Win specific (it was never intended for other OSes).

As for your question, technically you could install it on Linux, or OSX (it is possible with some manual steps), but that would make absolutely no difference, because (even if installed) it would NOT run on those platforms, as it contains (consists of) binaries (.dlls) that don’t run (can’t be loaded by processes) on non Win OSes.

Just looked at the comments: [MS.Docs]: Office.MessageCompose interface is available on OSX, but (most likely, if there isn’t already a Python wrapper available) you’d have to write the bindings yourself (their examples are in JS).

Additional (generic) information

Some packages are only meant to work in specific conditions, based on restricting criteria like:

even if not enforced by the installation mechanism (meaning they can somehow end up «installed» on platforms that they don’t work on).
Anyway, such restrictions are (should be) mentioned (example for PyWin32 — see the red boxes) in package’s:

  • PyPI pageImg0
  • HomepageImg1
  • Other resources (e.g.: package’s doc page, if it has one)

Bottom line is that such a package will not work outside the conditions it was meant to run in (even if it can be installed), and more: when attempting to run it, will yield some error message that might not be very clear.

There are packages with such restrictions, but can be installed outside them:

[cfati@cfati-5510-0:/mnt/e/Work/Dev/StackOverflow/q064975918]> python -c "import comtypes" Traceback (most recent call last): File "", line 1, in File "/home/cfati/.local/lib/python3.8/site-packages/comtypes/__init__.py", line 28, in from _ctypes import COMError ImportError: cannot import name 'COMError' from '_ctypes' (/usr/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so) 
[cfati@cfati-5510-0:/mnt/e/Work/Dev/StackOverflow/q064975918]> python -c "import WConio2" Traceback (most recent call last): File "", line 1, in File "/home/cfati/.local/lib/python3.8/site-packages/WConio2.py", line 125, in from ctypes import windll ImportError: cannot import name 'windll' from 'ctypes' (/usr/lib/python3.8/ctypes/__init__.py) 

Источник

Is win32com library available on Linux?

Is win32com library available on Linux?

Certainly not.

win32com looks like a Windows specific library, tied to the WinAPI.

Читайте также:  Host based firewall linux

Linux has a different operating system API (because Linux is not Windows and both are different OSes), mostly following the POSIX standards. For example, both Linux and Windows have files, directories, processes, executables, dynamic loading, users, etc. but the details about them vary greatly and significantly (and you need to understand them, since «the evil is in the details»);

To learn the Linux operating system API, read a good Linux programming book. The ALP book is freely downloadable, even if it is a bit old (but most of its content still apply); and you could get (e.g. buy) newer books.

For more, read the man pages (which are the canonical documentation on Unix). In particular syscalls(2) and the many other pages refereed from it. You’ll also need to look into the section 3 of man pages, since it is listing many functions usable in Linux.

You might find (but this is programming language specific) some framework libraries trying to provide some common abstractions above several OSes. Look (for C++) into Qt, POCO, Boost, etc.

At last, don’t forget that Linux is made of free software. Sometimes, it is useful to download them and study their source code. In some occasions, that is a good approach to leaky abstractions.

PS. Budget several weeks of your time to read documentation and books, and perhaps study the source code of some free software similar to your goals.

Источник

Python module win32com on Linux

I am writing some Python code that runs under multiple platforms. Unfortunately under Win32, I have to support some COM functionalities. However these lines will fail under an Linux environment:

from pythoncom import PumpWaitingMessages from pythoncom import Empty from pythoncom import Missing from pythoncom import com_error import win32api 

And all the other functions which are using the Win32 COM API will fail as well. What is the standard method to make sure that some code is not loaded/imported depending on the platform and give an error message/exception in the case they are called by the client of the interface ?

1 Answer 1

try: from pythoncom import PumpWaitingMessages from pythoncom import Empty from pythoncom import Missing from pythoncom import com_error import win32api except ImportError: # handle exception 

What to do when there is an exception is up to you. You could add Linux-specific code that provides an analogous interface, or you could use the warnings module to tell the user that certain functions/features are unavailable.

Alternatively, you could use an if-statement based on the value of sys.platform :

import sys if sys.platform == "win32": . elif sys.platform == 'cygwin': . elif sys.platform[:5] == 'linux': . elif sys.platform == 'darwin': . else: . 

Other values which may be important for cross-platform code may be os.name (which could equal ‘posix’ , ‘nt’ , ‘os2’ , ‘ce’ , ‘java’ , ‘riscos’ ), or platform.architecture (which could equal things like (’32bit’, ‘ELF’) .)

Источник

Оцените статью
Adblock
detector