Install win32com on MacOs and Linux - python

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.

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:
Platform(s) (OS, CPU architecture)
Python version(s)
...
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 page
Homepage
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:
Win:
ComTypes
Error:
[cfati#cfati-5510-0:/mnt/e/Work/Dev/StackOverflow/q064975918]> python -c "import comtypes"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/cfati/.local/lib/python3.8/site-packages/comtypes/__init__.py", line 28, in <module>
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)
Fix (improvement): [GitHub]: enthought/comtypes - Improve error message on non Win
WConio2
Error:
[cfati#cfati-5510-0:/mnt/e/Work/Dev/StackOverflow/q064975918]> python -c "import WConio2"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/cfati/.local/lib/python3.8/site-packages/WConio2.py", line 125, in <module>
from ctypes import windll
ImportError: cannot import name 'windll' from 'ctypes' (/usr/lib/python3.8/ctypes/__init__.py)
Fix (improvement): [GitHub]: Solomoriah/WConio2 - Improve error message on non Win

Related

Linux terminal and Python are mushed together

When I run some commands, which work, for example neofetch, it gives me a Python error.
username#host:~$ as
Traceback (most recent call last):
File "/usr/lib/command-not-found", line 28, in <module>
from CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
from CommandNotFound.db.db import SqliteDatabase
File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'
It does that whenever I type an invalid command. This started happening after I installed Python 3.9. I am running Kubuntu with Python 3.10 installed by default.
Modern Linux distributions tend to use a lot of python scripts for internal use; for this reason python gets installed with a plethora of libraries.
The error you are getting is because you replaced that fairly complete system python with a version of your own choosing without providing all the libraries the original came with.
The error you see is emitted by /usr/lib/command-not-found, a script using python3 as found in the system path.
I strongly recommend that you re-install the original python packages and use e.g. anaconda for your specific python needs.
The main takeaway from this is:
DON'T MESS WITH THE SYSTEM PYTHON.
try to find which python are you using using which python and uninstall the first python interpreter it finds.

Cannot use tkinter in Python 3 on macOS

Short version: Python 3 is unable to use tkinter on my iMac.
Details and useful info: I'm on macOS Mojave, Version 10.14.3 (18D109). (I can't upgrade for a while yet because of software that won't run on the newer versions.)
In my scripts I'm using #!/usr/bin/env python3 and when I get to the line import tk as tkinter I get this error:
Traceback (most recent call last):
File "/Users/hal/Documents/Dev/HalPy/TestScript.py", line 5, in <module>
import tkinter
File "/Users/hal/.pyenv/versions/3.7.3/lib/python3.7/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
When I tested it, from the command line, I typed python and got the Python shell and the version info (Python 3.7.3 (default, Apr 11 2020, 02:53:05)). Then I tried import tkinter as tk and I get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/hal/.pyenv/versions/3.7.3/lib/python3.7/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter'
I see the module when I drop into the Help mode and type modules and tkinter shows up in the list of modules. Just in case, I tried installing it with pip, but it wouldn't install (which is what I expected).
So what do I need to do to get Python 3 to recognize tkinter? (Just in case it matters, Python 2 with Tkinter does work.)
Also, I have looked at this question and this one and this is NOT a duplicate. (First note that neither has an accepted answer.) The first one involves reinstalling, and the focus seems to be on Windows, and this is on macOS, which includes it pre-installed. I'm a bit concerned what reinstalling it would do. The 2nd question is having problems because it's being run within the XCode framework and one element of the issue is the wrong shebang and I'm already using the one the answer suggests.
you can find your answer here:
https://blog.lanzani.nl/2020/install-tkinter-macos/
If you are using a Python from any current python.org Python installer for macOS (3.9.0+, 3.8.0+, or 3.7.2+), no further action is needed to use IDLE or tkinter. A built-in version of Tcl/Tk 8.6 will be used.
If you are using macOS 10.6 or later, the Apple-supplied Tcl/Tk 8.5 has serious bugs that can cause application crashes. If you wish to use IDLE or Tkinter, do not use the Apple-supplied Pythons. Instead, install and use a newer version of Python from python.org or a third-party distributor that supplies or links with a newer version of Tcl/Tk.

Wine refuses to find "ssl" python module

First and foremost, I'm not a very experienced wine user.
Onto the problem. I want to run a Windows executable which in some way or another launches some sort of a python script (presumably, for authorization purposes). In this script, as evident from the error message, an import of "ssl" is present and it fails:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named ssl
I have found that ssl is by default bundled with python 2.6+. I have also found that installing/uninstalling any versions of python inside wine does not fix the issue. Furthermore, I can import ssl inside of wineconsole successfully and also on my linux installation with both python2 and python3.
I don't know how to solve this, but I have a guess that wine pulls python modules from somewhere else, although I haven't been able to find where from exactly and why.

install of mapnik on windows python

for my master thesis, I have to render some maps from OpenStreetMap information. Unfortunately, I'm not able to install mapnik.
In the manual (https://github.com/mapnik/mapnik/wiki/WindowsInstallation) it said I should Add ";C:\mapnik-v2.2.0\lib" to the PATH variable. In my case it is "C:\Users\User\Mapnik\lib". I cloned the git repo and updated it to v3.0.23. Like it said here: https://mapnik.org/pages/downloads.html
But in this location, I don't have lib. Also, I don't have bin. So I'm a little bit confused about how to install mapnik.
I would really appreciate your help.
Some more Information: OS is windows 10, For Python, I'm using Anaconda with a 2.7 Instance just for mapnik... even if I read, that I could go with python 3. For the rest of my code, I go with Python 3.8. For sure I would prefer to stay at 3.8 but if it only works with 2.7 I would also use that.
Error message: "(Mapnik) C:\Users\User\Mapnik\demo\python>python rundemo.py
Traceback (most recent call last):
File "rundemo.py", line 25, in
import mapnik
ImportError: No module named mapnik"

Modules in Python on Windows

I have a simple sode snippet that uses cairomodule. I would like to launch the scipt but it somehow cannot run giving this error :
Traceback (most recent call last):
File "C:\Users\xxx\Desktop\test.py", line 1, in <module>
import cairo
ImportError: No module named cairo
how should I "install" a module in Python on Windows ? I have tried installing http://gladewin32.sourceforge.net/ as stated on cairo page that I can get cairo as a "side effect" of intalling GTK+ but somehow this didn't work.
If I should add some paths to PATH please indicate which one as I am raelly confused about this.
Now I realise how simpler that would be on linux with powerful terminal :)
Try installing PyGtk from here: http://www.pygtk.org/downloads.html. The all-in-one-installer worked for me. Just choose the packages you want installed.

Categories

Resources