I am trying to get a screenshot utility to work after porting it from:
PyQt4 -> PyQt5
Python 2.7 -> Python 3.7
Ubuntu -> Windows 7
original code
new ported code
I changed all the Qt4 references over to Qt5 and got it mostly working except for the Select Area function that lets you select an area on the screen by drawing a rectangle. This part fails with the error:
resArea: Traceback (most recent call last):
File "screenshot.py", line 318, in <module>
d = display.Display()
File "C:\Users\frak\AppData\Local\Programs\Python\Python37\lib\site-packages\python_xlib-0.24-py3.7.egg\Xlib\display.py", line 89, in __init__
File "C:\Users\frak\AppData\Local\Programs\Python\Python37\lib\site-packages\python_xlib-0.24-py3.7.egg\Xlib\display.py", line 71, in __init__
File "C:\Users\frak\AppData\Local\Programs\Python\Python37\lib\site-packages\python_xlib-0.24-py3.7.egg\Xlib\protocol\display.py", line 85, in __init__
File "C:\Users\frak\AppData\Local\Programs\Python\Python37\lib\site-packages\python_xlib-0.24-py3.7.egg\Xlib\support\connect.py", line 72, in get_display
File "C:\Users\frak\AppData\Local\Programs\Python\Python37\lib\site-packages\python_xlib-0.24-py3.7.egg\Xlib\support\connect.py", line 55, in _relative_import
File "C:\Users\frak\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 668, in _load_unlocked
File "<frozen importlib._bootstrap>", line 638, in _load_backward_compatible
File "C:\Users\frak\AppData\Local\Programs\Python\Python37\lib\site-packages\python_xlib-0.24-py3.7.egg\Xlib\support\unix_connect.py", line 31, in <module>
ModuleNotFoundError: No module named 'fcntl'
I know that fcntl isn't supported on Windows but I think there could be a workaround since I think what the code is trying to do is get some screen dimensions before proceeding.
All the research I've done so far points me to other things like pyscreenshot or alternative implementations that only do a full-screen grab but don't have a rectangular selector to select a screen region.
I like this implementation because it shows you a quick preview and options to select an area, adjust delay, hide window and save to file.
Any help would be greatly appreciated
Related
I've got an error when I try to update the python runtime of a function Azure, from 3.6 to 3.7 or 3.8, because version 3.6 is no longer used in Azure.
This is the full error:
Result: Failure Exception: AttributeError: module 'os' has no attribute 'add_dll_directory' Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 355, in _handle__function_load_request func = loader.load_function( File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 40, in call return func(*args, **kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/loader.py", line 127, in load_function mod = importlib.import_module(fullmodname) File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1014, in _gcd_import File "<frozen importlib._bootstrap>", line 991, in _find_and_load File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 671, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 843, in exec_module File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "/home/site/wwwroot/CopyTransactionHttpTrigger/__init__.py", line 8, in <module> from confluent_kafka import avro File "/home/site/wwwroot/.python_packages/lib/site-packages/confluent_kafka/__init__.py", line 18, in <module> _delvewheel_init_patch_16682001180() File "/home/site/wwwroot/.python_packages/lib/site-packages/confluent_kafka/__init__.py", line 9, in _delvewheel_init_patch_16682001180 os.add_dll_directory(libs_dir)
Python 3.7 and 3.8
modules in requirements.txt file:
azure-functions==1.12.0 confluent-kafka==1.7.0 confluent-kafka[avro]==1.7.0 requests azure.storage.blob
I tried to update the function Azure with python 3.7 and 3.8 installing all dependencies above (modules) with such runtimes.
I think this module is necessary => module 'os' has no attribute 'add_dll_directory', and I don't know how to solve it.
What I see on the documentation of os module, it's used for windows. Do I need this module (os) in Azure?, can I avoid it by code?, if so, how?
I just install the function in linux on my local machine and deploy it from there adn it works. The issue was that I was deplying form a windows environtment.
I'm setting up my Django Rest API on Linux instance-template-1 5.10.0-14-cloud-amd64 #1 SMP Debian 5.10.113-1 (2022-04-29) x86_64
Python 3.9 is installed and Django 4x
I've installed One signal required by my API using
sudo pip3 install onesignal
sudo pip3 install onesignal_sdk
The module not found error throws up when I run
sudo python3.9 manage.py migrate
The detailed error trace is as follows :
File "/home/lineofsight/myprojects/my API/manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/dist-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/dist-packages/django/core/management/__init__.py", line 420, in execute
django.setup()
File "/usr/local/lib/python3.9/dist-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python3.9/dist-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/usr/local/lib/python3.9/dist-packages/django/apps/config.py", line 304, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "/home/lineofsight/myprojects/My API/myapp_auth/models.py", line 25, in <module>
from myapp_notifications.helpers import get_notification_language_code_for_target_user
File "/home/lineofsight/myprojects/My API/myapp_notifications/helpers.py", line 4, in <module>
import onesignal as onesignal_sdk
File "/usr/local/lib/python3.9/dist-packages/onesignal/__init__.py", line 3, in <module>
from onesignal_client import OneSignal
ModuleNotFoundError: No module named 'onesignal_client'
I think you didn't install the correct python location.
Please try to install using the following commands.
python3.9 -m pip install onesignal
python3.9 -m pip install onesignal_sdk
So I was working with python, coding and installing packages, everything was going ok, but then everything with pip stoped working, and every times the cmd prompt me :
Traceback (most recent call last):
File "c:\python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Python39\Scripts\pip.exe\__main__.py", line 7, in <module>
File "c:\python39\lib\site-packages\pip\_internal\cli\main.py", line 69, in main
command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
File "c:\python39\lib\site-packages\pip\_internal\commands\__init__.py", line 91, in create_command
module = importlib.import_module(module_path)
File "c:\python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 855, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "c:\python39\lib\site-packages\pip\_internal\commands\list.py", line 9, in <module>
from pip._internal.cli.req_command import IndexGroupCommand
File "c:\python39\lib\site-packages\pip\_internal\cli\req_command.py", line 20, in <module>
from pip._internal.index.collector import LinkCollector
File "c:\python39\lib\site-packages\pip\_internal\index\collector.py", line 5, in <module>
import cgi
File "c:\python39\lib\cgi.py", line 41, in <module>
import html
ModuleNotFoundError: No module named 'html'
I never run into those kind of errors.
BTW pip -V is working, and when I try to run a programme using python with the already installed package and it still works fine.
I tried to reinstall python partially after restarting my pc, and nothing with pip has changed
I fixed it, here is what I have done, and more context that may help you understand where the problem was coming from :
So I was doing an gui app using pyqt5 and I was having trouble with PySide2, the first error of this kind was when I tried to install it with pip (pip install PySide2). I don't know where the error came from, but if you encounter this after in a similar situation, there way be a problem with that.
what I have done to fix it was not re-installing python or pip but using the repair "tool" when installing the version of python already installed.
Hi I am pretty new to django and I ended up with a very big error when I tried running the command python3 manage.py syncdb. I am trying to create a form builder application and encountered the error when I was trying to sync the database with the project. I am using the django-forms-builder from pypi.org.
For the error:
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'foo'
Any kind of help will be appreciated.
You must have forgotten to install a dependency that is listed in your INSTALLED_APPS. Try pip install foo. Or you can remove foo from the installed apps.
I get this error from the exe generated by PyInstaller when using Pyttsx3. The code works fine in python. I've tried using other versions of PyInstaller and Pyttsx but it doesn't make a difference. I've also tried Py2exe which is also not working with Pyttsx3, does anyone know what's causing this?
The code
import pyttsx3
engine = pyttsx3.init()
engine.say('Test')
engine.runAndWait()
The error after running the exe generated
Traceback (most recent call last):
File "site-packages\pyttsx3\__init__.py", line 44, in init
File "c:\python34\lib\weakref.py", line 125, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Test.py", line 85, in <module>
File "site-packages\pyttsx3\__init__.py", line 46, in init
File "site-packages\pyttsx3\engine.py", line 52, in __init__
File "site-packages\pyttsx3\driver.py", line 75, in __init__
File "importlib\__init__.py", line 109, in import_module
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'pyttsx3.drivers'
Try this:
import pyttsx3
from pyttsx3.drivers import sapi5
engine = pyttsx3.init()
engine.say('Test')
engine.runAndWait()
Explanation:
You actually need to import an extra module from pyttsx3.
Goto location:
C:\Users\username\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\PyInstaller\hooks
Create a newfile "hook-pyttsx3.py"
inside file, copy the code below..
#-----------------------------------------------------------------------------
# Copyright (c) 2013-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------
""" pyttsx3 imports drivers module based on specific platform. Fount at https://github.com/nateshmbhat/pyttsx3/issues/6 """
hiddenimports = [
'pyttsx3.drivers',
'pyttsx3.drivers.dummy',
'pyttsx3.drivers.espeak',
'pyttsx3.drivers.nsss',
'pyttsx3.drivers.sapi5', ]
Now your program will run without getting error.
Click here Github issue created
Try this:
pyinstaller --hidden-import=pyttsx3.drivers --hidden-import=pyttsx3.drivers.dummy --hidden-import=pyttsx3.drivers.espeak --hidden-import=pyttsx3.drivers.nsss --hidden-import=pyttsx3.drivers.sapi5
Hidden import argument for pyinstaller import 3 rd party packages into build. By adding above lines to pyinstaller will create a spec file with hidden-import =[‘pyttsx3.drivers’,’pyttsx3.drivers.dummy’,....] which will rectify the error “no module named pyttsx.driver’ but eventually u will end up other error also which i am unable to solve.
I've just fixed pyttsx3 compatibility in #101. In a couple of weeks you will be able to:
pip install "pyinstaller-hooks-contrib>=2021.2"
but until then you can use the Github version:
pip install -U https://github.com/pyinstaller/pyinstaller-hooks-contrib/archive/refs/heads/master.zip
Add the --clean option the first time you run PyInstaller after using pip (unless you're using auto-py-to-exe which blocks PyInstaller's caching). It should then work on all platforms without using any --hiddenimport-ing.