Cannot import pywinauto on Windows 10 - python

I installed pywinauto using pip install pywinauto.
OS: Windows 10
Python: 3.6.2
When I run python and try to import pywinauto, I get the error:
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pywinauto.application import Application
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\__init__.py", line 89, in <module>
from . import findwindows
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\findwindows.py", line 42, in <module>
from . import controls
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\controls\__init__.py", line 36, in <module>
from . import uiawrapper # register "uia" back-end (at the end of uiawrapper module)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\controls\uiawrapper.py", line 47, in <module>
from ..uia_defines import IUIA
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 181, in <module>
pattern_ids = _build_pattern_ids_dic()
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 169, in _build_pattern_ids_dic
if hasattr(IUIA().ui_automation_client, cls_name):
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 50, in __call__
cls._instances[cls] = super(_Singleton, cls).__call__(*args, **kwargs)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\pywinauto\uia_defines.py", line 60, in __init__
self.UIA_dll = comtypes.client.GetModule('UIAutomationCore.dll')
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\client\_generate.py", line 118, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\client\_generate.py", line 183, in _CreateWrapper
generate_module(tlib, ofi, pathname)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\tools\tlbparser.py", line 750, in generate_module
gen.generate_code(list(items.values()), filename=pathname)
File "C:\Users\John\AppData\Roaming\Python\Python36\site-packages\comtypes\tools\codegenerator.py", line 261, in generate_code
tlib_mtime = os.stat(self.filename).st_mtime
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'UIAutomationCore.dll'
Any ideas how to fix this?

I have the same issue today and fixed it by pip install comtypes==1.1.7.
It caused by comtypes library which release a new version 1.1.8 at Dec.26. Downgrade to previous version, it works well now.

It should be fixed in comtypes==1.1.9. Please check.
The problem was introduced in comtypes==1.1.8. My fault.

Try using a different version of python (e.g. 3.7.5 or 3.8):
https://github.com/pywinauto/pywinauto/issues/887
"Had the same issue with Python 3.7.6 and 3.8.1. Issue does not occur in 3.7.5 or 3.8.
I think this will be fixed in 3.8.2 ( but not sure yet)"

Try this, for me works fine
Install pywin32 from https://github.com/mhammond/pywin32/releases
pip install -U comtypes
pip install six
pip install Pillow
cd c:\windows\syswow64\
regsvr32 UIAutomationCore.dll
python
import pywinauto
#and the problem should be solved
I have Win10 and python 3.9..... i don't like Win10
Another thing could be your numpy library, uninstall it and install it again.
pip uninstall numpy
pip install numpy
Credits -> https://www.dll-files.com/download/65996a0afad353ec43ffe1ca69a2be88/uiautomationcore.dll.html?c=TTM2MGJJaHVRaEJkM1JyNDB3TDNwZz09

Related

No module 'gi' and ImportError: The GTK3 backends require PyGObject error

I am trying to run some code on an AWS ec2 (ubuntu). When I comment out the portion that displays graphs from matplotlib, it runs fine. However, I want to view graphs.
When running the code, I get this error:
Traceback (most recent call last):
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 18, in <module>
import gi
ModuleNotFoundError: No module named 'gi'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "run.py", line 8, in <module>
from process_mask import ProcessMasks
File "/home/ubuntu/rPPG/process_mask.py", line 10, in <module>
matplotlib.use('GTK3Agg')
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/cbook/deprecation.py", line 307, in wrapper
return func(*args, **kwargs)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/__init__.py", line 1307, in use
switch_backend(name)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 221, in switch_backend
backend_mod = importlib.import_module(backend_name)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3agg.py", line 4, in <module>
from . import backend_agg, backend_cairo, backend_gtk3
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 20, in <module>
raise ImportError("The GTK3 backends require PyGObject")
ImportError: The GTK3 backends require PyGObject
I've been searching SO and other sources and have tried a lot of things including:
sudo apt-get install python3-gi
pip install vext
pip install vext.gi
sudo apt install python3-gi
pip3 install --user pgi
Also, this works:
$ /usr/bin/python3
Python 3.4.0 (default, Apr 11 2014, 13:05:11)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>>
but my actual code is in a virtual env with a bunch of dependencies, so this doesn't work with my actual code (/usr/bin/python run.py).
I ran into exact same issue, but after much efforts I managed to make TkAgg working (which was giving the import error for _tkagg). Little late, but someone might find it useful.
FWIW I resolved the issue as follows (to use TkAgg):
◉ Installed tk-dev from package manager
◉ Reinstalled python3-tk from package manager
◉ Rebuilt and reinstalled matplotlib from source
◉ (and of course setting TkAgg in matplotrc)
If you think you have tk-dev and python3-tk installed correctly, you need to rebuild and reinstall matplotlib, so that it generates _tkagg.py in your backends directory.
I'm using Python3.3 (numpy 1.7) on LM14. But I think it should work on Ubuntu/Python3.2
Thanks

How to get SublimeText to load DLLs where they load fine using commandline

When using python through the commandline, I am able to import modules fine. However, when I build a python script in SublimeText3, some modules don't import. I generally receive the following error:
ImportError: DLL load failed: The specified module could not be found.
The problem looks to involve modules with dependencies on modules with a "_" prefix (_sqlite3, _ssl). For example:
File "C:\ProgramData\anaconda3\Lib\sqlite3\__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "C:\ProgramData\anaconda3\Lib\sqlite3\dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: DLL load failed: The specified module could not be found.
System:
Windows 10
SublimeText3 (freshly reinstalled during troubleshooting)
Python 3.7.3 [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
(freshly reinstalled during troubleshooting)
Both commandline and ST3 or pointing to same instance of Python.
This is the only python install on the machine.
Have used default Python build in ST3 and created a new build, both have same issue.
Results when using the commandline:
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import plotly
>>>
Results in ST3:
import plotly
Traceback (most recent call last):
File "C:\Users\usr\Desktop\scrap.py", line 1, in <module>
import plotly
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\__init__.py", line 32, in <module>
from plotly import (
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\graph_objs\__init__.py", line 3, in <module>
from plotly.basedatatypes import BaseLayoutType as _BaseLayoutType
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\basedatatypes.py", line 25, in <module>
from .callbacks import (Points, InputDeviceState)
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\callbacks.py", line 2, in <module>
from plotly.utils import _list_repr_elided
File "C:\ProgramData\anaconda3\Lib\site-packages\plotly\utils.py", line 262, in <module>
from chart_studio.utils import *
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\__init__.py", line 2, in <module>
from chart_studio import (plotly, dashboard_objs, grid_objs, session)
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\__init__.py", line 10, in <module>
from . plotly import (
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\plotly.py", line 38, in <module>
from chart_studio.plotly import chunked_requests
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\chunked_requests\__init__.py", line 1, in <module>
from . chunked_request import Stream
File "C:\ProgramData\anaconda3\Lib\site-packages\chart_studio\plotly\chunked_requests\chunked_request.py", line 4, in <module>
import ssl
File "C:\ProgramData\anaconda3\Lib\ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: DLL load failed: The specified module could not be found.
[Finished in 2.9s]
Any help much appreciated, been stuck on this for days.
For those with a similar issue in the future, I've fixed this by uninstalling the Anaconda distribution of Python and replacing it with a base Python installation from Python.org, then installing packages using pip manually. While not the ideal solution, this has solved the issue so that when I build a Python script in ST3, all modules are imported fine.

cannot import name 'multiarray' in numpy with python3

I usually work with python 2.7 but this time i have to test a script in python3.
It is already installed on my computer, however when i start "python3", then go "import numpy", it show me "cannot import name 'multiarray'.
I even installed anaconda3 to test, but nothing happens
myName:~/anaconda3/bin$ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
I saw that it is looking in the lib/python2.7, but i cannot find what to do to get him search in the python3 library.
I already tried python -m pip install numpy, and tried to create a virtualenv in python3 but i still get the same error.
I cannot figure what to do. Can someone help me ?
I would like to add, i cannot start command with 'sudo' as i'm working on a client machine.
edit:
i tried #gehbiszumeis answer and got this:
myName:~ $ cd anaconda3/bin/
myName:~/anaconda3/bin $ source activate /home/myName/anaconda3
(base) myName:~/anaconda3/bin $ conda list numpy
# packages in environment at /home/myName/anaconda3:
#
# Name Version Build Channel
numpy 1.14.3 py36hcd700cb_1
numpy-base 1.14.3 py36h9be14a7_1
numpydoc 0.8.0 py36_0
(base) myName:~/anaconda3/bin $ python3
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/numpy/__init__.py", line 180, in <module>
from . import add_newdocs
File "/usr/lib/python2.7/dist-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/usr/lib/python2.7/dist-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/usr/lib/python2.7/dist-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/usr/lib/python2.7/dist-packages/numpy/core/__init__.py", line 14, in <module>
from . import multiarray
ImportError: cannot import name 'multiarray'
I see there is numpy 36 installed when i type conda list numpy, but it seems not to work.. Did i miss something ?
edit2:
After #Pal Szabo method, i tested command python3 -m pip install --upgrade pip and got this error :
(env) (base) myName:~/anaconda3/bin $ python3 -m pip install --upgrade pip
Traceback (most recent call last):
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 183, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 142, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/home/myName/anaconda3/lib/python3.6/runpy.py", line 109, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 4, in <module>
import locale
File "/home/myName/anaconda3/bin/env/lib/python3.6/locale.py", line 16, in <module>
import re
File "/home/myName/anaconda3/bin/env/lib/python3.6/re.py", line 142, in <module>
class RegexFlag(enum.IntFlag):
AttributeError: module 'enum' has no attribute 'IntFlag'`
It is a crazy mix between python3, python2.7 then again python3. I'm lost \o/
edit3:
I finally found my error.
It was a probleme with my PYTHONPATH, which was pointing somewhere where a .pth file was defined, with some hard link to python 2.7 libraries.
with a simple "unset PYTHONPATH" it works fine.
Thanks you all
I had the same problem, took me several hours to figure it out.
In my case, the PYTHONPATH was set to /usr/lib/python2.6/dist-packages/
changing it to /Users/xxx/miniconda3/lib/python3.7/site-packages/ resolved the issue.
Good luck.
Based what I can see from your code listing, it seems that the anaconda environment is not activated (this is usually indicated by the environments name in surrounding brackets () before the prompt). Because of that python3 tries to look for numpy and only finds the one you used for python 2.7 previously, which causes the error (see the python2.7 error messages)
Try
source activate <your-anaconda-environment>
Then your prompt should look like this
(<your-anaconda-environment>) myName:~/anaconda3/bin$
Numpy should be contained in the standard anaconda environment. Try then to check if numpy is installed within your environment with
conda list numpy
If there is no numpy listed, try to install it with pip as you wrote before.
If want to use python3, use pip3 instead of pip:
pip3 install numpy
You can try these too in terminal:
rm -Rf env
virtualenv -p python3 env
source env/bin/activate
python3 -m pip install --upgrade pip
pip3 install numpy
Also make sure that the first line of your script is
#!/usr/bin/python3
Don't write anything, even comments, before this.
I solved this problem changing the Python's version on VS Code. I was working with Python 3.7.4, now with the 3.7.8 one.
When I installed Numpy, it was stored in the folder of Python3.6. So I think that u could try to change the path or just change the Python's version

Unable to import matplotlib.pyplot

I have installed python 2.7.10 in CentOS 6.5. Then I installed matplotlib using pip. However, I am getting the following error when trying to import matplotlib.pyplot.
import matplotlib.pyplot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 6, in <module>
from six.moves import tkinter as Tk
File "/usr/local/lib/python2.7/site-packages/six.py", line 203, in load_module
mod = mod._resolve()
File "/usr/local/lib/python2.7/site-packages/six.py", line 115, in _resolve
return _import_module(self.mod)
File "/usr/local/lib/python2.7/site-packages/six.py", line 82, in _import_module
__import__(name)
File "/usr/local/lib/python2.7/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
tkinter seems to be installed.
"Package tkinter-2.6.6-66.el6_8.x86_64 already installed and latest version"
I have _tkinter.so module in python2.6/lib-dynload, but nothing related to tkinter under python2.7/lib-dynload.
/usr/lib64/python2.6/lib-dynload/_tkinter.so
/usr/local/lib/python2.7/lib-tk/test/test_tkinter
Also, I verified sys.path in python to get the following:
Python 2.7.10 (default, Jun 1 2017, 18:51:46)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print '\n'.join(sys.path)
/usr/local/lib/python27.zip
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
/usr/local/lib/python2.7/lib-old
/usr/local/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
This may be a problem with your python library path. Check to see where tkinter is installed, and make sure that you have that available to your Python interpreter. Can you import anything else from tkinter?
Try to install tkinter as they said ”no module named _tkinter“.
You can do so with that command:
sudo apt-get install python-tk

Python import command not finding module that exists

I presently have Python 2.7 installed, and have been attempting to get my pygeoprocessing module to work correctly (which appears to have been installed correctly). This is the version of Idle Python I am running:
"Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32"
When I type in "import pygeoprocessing" from the Idle command line, this is the error message . . .
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
import pygeoprocessing
File "C:\Python27\ArcGISx6410.4\lib\site-packages\pygeoprocessing\__init__.py", line 10, in <module>
from geoprocessing import *
File "C:\Python27\ArcGISx6410.4\lib\site-packages\pygeoprocessing\geoprocessing.py", line 25, in <module>
import scipy.interpolate
File "C:\Python27\ArcGISx6410.4\lib\site-packages\scipy\interpolate\__init__.py", line 160, in <module>
from .interpolate import *
File "C:\Python27\ArcGISx6410.4\lib\site-packages\scipy\interpolate\interpolate.py", line 15, in <module>
import scipy.linalg
File "C:\Python27\ArcGISx6410.4\lib\site-packages\scipy\linalg\__init__.py", line 161, in <module>
from .misc import *
File "C:\Python27\ArcGISx6410.4\lib\site-packages\scipy\linalg\misc.py", line 5, in <module>
from . import blas
***File "C:\Python27\ArcGISx6410.4\lib\site-packages\scipy\linalg\blas.py", line 155, in <module>
from scipy.linalg import _fblas
ImportError: DLL load failed: The specified module could not be found.
When I navigated to the folder mentioned ( . . . scipy\linalg\blas.py) I found that both blas.py and _fblas were present. Therefore I don't know why I got that last import error.
Is there something I can check?
Thanks!
Since you are on a windows box you may want to verify whether you have the 64-bit or the 32-bit version of python installed. That has caused problems for me in the past.
If the above listed methods do not work, try installing the module with pip.
And then try importing it.
C.f. How do I install pip on Windows?

Categories

Resources