problems installing sqlite and python on freebsd - python-3.x

This is driving me crazy! Any help you can provide will be most welcome!
I have a python3/sqlite application (running in a virtual environment) that is working fine on debian. I need to install it on freebsd (running in a virtual environment). I have installed python3 and sqlite (I can open a .sqlite file from the command line).
When I try to run the python script, I get the following error:
(venv) [jordan#webServer ~/crons/powerwall]$ python3 main.py
Traceback (most recent call last):
File "/usr/home/jordan/crons/powerwall/main.py", line 78, in <module>
run()
File "/usr/home/jordan/crons/powerwall/main.py", line 33, in run
database.load_db(config_mgr=config)
File "/usr/home/jordan/crons/powerwall/database.py", line 108, in load_db
db = PowerWallDb(cfg_mgr=config_mgr)
File "/usr/home/jordan/crons/powerwall/database.py", line 94, in __init__
super().__init__(cfg_mgr=cfg_mgr, section=section)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/thompcoutils/db_utils.py", line 77, in __init__
self._connect_sqlite(self.sqlite_file, check_same_thread=False)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/thompcoutils/db_utils.py", line 99, in _connect_sqlite
self._connect_uri(uri, **kwargs)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/thompcoutils/db_utils.py", line 95, in _connect_uri
self.connection = sqlobject.sqlhub.processConnection = sqlobject.connectionForURI(uri, **kwargs)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/dbconnection.py", line 1105, in connectionForURI
conn = connCls.connectionFromURI(uri)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/dbconnection.py", line 154, in connectionFromURI
return cls._connectionFromParams(*cls._parseURI(uri))
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/sqlite/sqliteconnection.py", line 122, in _connectionFromParams
return cls(filename=path, **args)
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/sqlite/sqliteconnection.py", line 64, in __init__
raise ImportError(
ImportError: Cannot find an SQLite driver, tried supersqlite,pysqlite2,sqlite3,sqlite
Exception ignored in: <function DBAPI.__del__ at 0x8029c1310>
Traceback (most recent call last):
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/dbconnection.py", line 704, in __del__
self.close()
File "/usr/home/jordan/crons/powerwall/venv/lib/python3.9/site-packages/sqlobject/sqlite/sqliteconnection.py", line 217, in close
if self._memory:
AttributeError: 'SQLiteConnection' object has no attribute '_memory'

You have to install py-sqlite3 which is the "Standard Python binding to the SQLite3 library"
Install From Ports:
cd /usr/ports/databases/py-sqlite3/ && make install clean
Install From pkg:
pkg install databases/py-sqlite3

Basically, it looks like the standard Python bindings for SQLite is a separate package on FreeBSD (perhaps, on all *nix/*BSD). So, in general, there are three components, which you need, Python, SQLite (this one may not be actually necessary for Python) AND the standard Python bindings for SQLite. I have not worked with FreeBSD, but based on Googling, have you tried installing this https://pkgs.org/download/py39-sqlite3 maybe?

Related

Building python3 with ROS using vison_opencv: Raise CvBridgeError, "encoding specified as %s but image has incompatible type %s" % (encoding,cv_type)

I am trying to run python3 with ROS. By default ROS melodic is installed with python2.7.
Hence I have installed the python3 using following instructions:
https://dkqhzm2.tistory.com/entry/ImportError-dynamic-module-does-not-define-module-export-function-PyInitcvbridgeboost-in-Xavier-AGX
where I have cloned the cv_bridge src from the following git: which is called vision_opencv
https://github.com/mikejmills/vision_opencv
I also put in my scripts as
#!/usr/bin/env python3
So that it complies in python3 when I did catkin_make
The following error is the trouble with this package:
rrcam#rrcam20220901-001:~/catkin_ws$ rosrun camera_calibration cameracalibrator.py --size 12x8 --square 0.05 image:=/cam1
Traceback (most recent call last):
File "/home/rrcam/catkin_ws/src/camera_calibration/nodes/cameracalibrator.py", line 39, in <module>
from camera_calibration.camera_calibrator import OpenCVCalibrationNode
File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/camera_calibrator.py", line 44, in <module>
from camera_calibration.calibrator import MonoCalibrator, StereoCalibrator, Patterns
File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/calibrator.py", line 38, in <module>
import cv_bridge
File "/home/rrcam/catkin_ws/devel/lib/python2.7/dist-packages/cv_bridge/__init__.py", line 34, in <module>
exec(__fh.read())
File "<string>", line 1, in <module>
File "/home/rrcam/catkin_ws/src/vision_opencv/cv_bridge/python/cv_bridge/core.py", line 164
raise CvBridgeError, "encoding specified as %s, but image has incompatible type %s" % (encoding, cv_type)
^
SyntaxError: invalid syntax
Not sure what to do.
If I compile only with python2.7 instead of python3 I get error as:
rrcam#rrcam20220901-001:~/catkin_ws$ rosrun camera_calibration cameracalibrator.py --size 12x8 --square 0.05 image:=/cam1
Exception in thread Thread-6:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/camera_calibrator.py", line 118, in run
self.function(m)
File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/camera_calibrator.py", line 242, in handle_monocular
max_chessboard_speed = self._max_chessboard_speed)
File "/home/rrcam/catkin_ws/src/camera_calibration/src/camera_calibration/calibrator.py", line 954, in __init__
super(MonoCalibrator, self).__init__(*args, **kwargs)
TypeError: super() argument 1 must be type, not classobj
Can someone tell me how to tackle this problem?
You’re trying to use Python2.x code with Python3, which doesn’t work. If you want to use Python3 with ROS you shouldn’t be using Melodic, since it targets 2.x. You can get it to sort of work with Python3, but it’s still not a great idea.
If you want Python3 you should be using the Noetic distro.

ModuleNotFoundError: No module named 'winreg' on Mac? (But winreg is a windows thing)

I am receiving the following error when I try to run a django shell. I am on a Mac though and everything that I can find says that this is associated with Windows and that winreg should be installed by default. Suggestions as to what I should be looking at?
Traceback (most recent call last):
File "/Users/j/code/myproject/core/manage.py", line 22, in <module>
main()
File "/Users/j/code/myproject/core/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 440, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 414, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 460, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.9/site-packages/django/core/management/commands/shell.py", line 127, in handle
exec(sys.stdin.read(), globals())
File "<string>", line 5, in <module>
ModuleNotFoundError: No module named 'winreg'
Between when I had a working env and the env producing the error I made a lot of changes to a script that I was working on including installing packages and adding modules.
When I tried to run the script I received the error above.
In the comments, Iain asked for the command I was running and then the contents of the script. Out of all the things I was looking at -- I ignored this, because was certain it was something I installed, not the file I was working on.
At the top of the file, I found this line in the imports:
from winreg import FlushKey
^^ My best guess is that this was accidentally added while I was quickly moving across the keyboard too quickly and I didn't noticed and pressed some sort of key combo that added it.
This is a first. 🫣

Executable made with pyinstaller doesn't work

I've tried to create an executable of my python script with pyinstaller, but it's not working.
If I run the exe file from terminal, I get these errors:
Traceback (most recent call last):
File "main.py", line 127, in <module>
File "main.py", line 9, in main
File "c:\users\danie\onedrive - universitat de valencia\escritorio\professors banda\profs\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 493, in exec_module
exec(bytecode, module.__dict__)
File "docx2pdf\__init__.py", line 13, in <module>
File "importlib\metadata.py", line 531, in version
File "importlib\metadata.py", line 504, in distribution
File "importlib\metadata.py", line 177, in from_name
importlib.metadata.PackageNotFoundError: docx2pdf
[13776] Failed to execute script main
I installed pyinstaller using pip inside the virtual environment of the project.
I would appreciate any help.
Thank you in advance.
Seems you have missing modules, that weren't found by PyInstaller analysis hooks.
Try to rebuild your application with --hidden-import=docx2pdf option.

Q: How to fix the missing dependancies in pyzbar

I am currently using spyder via anaconda with python 3.8.5 on windows 10 and I am trying to use the pyzbar package to make a barcode reader. When I try to run the script I get this error message when trying to run from pyzbar.pyzbar import decode and from pyzbar import pyzbar:
Traceback (most recent call last):
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 58, in load
dependencies, libzbar = load_objects(Path(''))
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 50, in load_objects
deps = [
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 51, in <listcomp>
cdll.LoadLibrary(str(directory.joinpath(dep)))
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 459, in LoadLibrary
return self._dlltype(name)
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 381, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<ipython-input-1-95ae0761f4b5>", line 1, in <module>
from pyzbar.pyzbar import decode
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\pyzbar.py", line 7, in <module>
from .wrapper import (
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 139, in <module>
zbar_version = zbar_function(
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 136, in zbar_function
return prototype((fname, load_libzbar()))
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\wrapper.py", line 115, in load_libzbar
libzbar, dependencies = zbar_library.load()
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 60, in load
dependencies, libzbar = load_objects(Path(__file__).parent)
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 50, in load_objects
deps = [
File "C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\zbar_library.py", line 51, in <listcomp>
cdll.LoadLibrary(str(directory.joinpath(dep)))
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 459, in LoadLibrary
return self._dlltype(name)
File "C:\Users\norinhan\Anaconda3\lib\ctypes\__init__.py", line 381, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\norinhan\Anaconda3\lib\site-packages\pyzbar\libiconv.dll' (or one of its dependencies). Try using the full path with constructor syntax.
When trying to run just import pyzbar it will compile, but it will not be able to access any of the function. When I try I get this message:
Traceback (most recent call last):
File "<ipython-input-3-26272af93b8a>", line 1, in <module>
pyzbar.pyzbar.decode()
AttributeError: module 'pyzbar' has no attribute 'pyzbar'
I have looked up the documentation for pyzbar on github which states "The zbar DLLs are included with the Windows Python wheels", but have not found this anywhere. The closest to "Windows Python wheels" I have found is the wheel package which does not contain any information about pyzbar.
Any advice on how to fix this?
Visit https://pypi.org/project/pyzbar/#files to download pyzbar-0.1.8-py2.py3-none-win_amd64.whl.
You can find all the DLL files inside the wheel package.
I have just encountered this problem.
If your OS & python are x64 version, it's just because of lack of vc 2013 x64 runtime.
You can find Visual C++ Redistributable Packages for Visual Studio 2013 here
download & install.
I was facing similar issue just installed Visual
C++ 64 bit version on my computer and restarted. Choose between vcredist_x86.exe or vcredist_x64.exe based on your machine.
https://www.microsoft.com/en-us/download/confirmation.aspx?id=40784. Hope this solves your issue as well.

Unable to import "eml_parser" module in Python

I am unable to import "eml_parser" module in Python.
I am running Windows 10, Python37 and Anaconda 5.3 (all 64 bit)
The installation docs are at this link: https://pypi.org/project/eml-parser/
I did find the following suggestion from https://github.com/pymedusa/Medusa/issues/1843 but I have not tried it yet. To update the init file as suggested requires administrative rights and I wasn't exactly sure how to open the file as an administrator and save it that way. It seem to make more sense to ask the question before getting too far into editing files. Note line 362 in the quote below would be the equivalent to line 356 on my error message.
Suggestion from https://github.com/pymedusa/Medusa/issues/1843
"If you are using a special version of Python [like Anaconda] and you can't fix it. Navigate to line 362 of lib/ctypes/init.py and change it to:
self._handle = _dlopen(str(self._name), mode)"
From Command Prompt, I get the following error message:
>>> import eml_parser
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Program Files\Python37\lib\site-packages\eml_parser\__init__.py", line 8, in <module>
from . import eml_parser
File "C:\Program Files\Python37\lib\site-packages\eml_parser\eml_parser.py", line 63, in <module>
import magic
File "C:\Program Files\Python37\lib\site-packages\magic.py", line 23, in <module>
_libraries['magic'] = _init()
File "C:\Program Files\Python37\lib\site-packages\magic.py", line 20, in _init
return ctypes.cdll.LoadLibrary(find_library('magic'))
File "C:\Program Files\Python37\lib\ctypes\__init__.py", line 434, in LoadLibrary
return self._dlltype(name)
File "C:\Program Files\Python37\lib\ctypes\__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
TypeError: LoadLibrary() argument 1 must be str, not None
Im not sure how it fixes this but I tried
pip install python-magic
pip install eml_parser
And got this working on Windows 10
https://github.com/GOVCERT-LU/eml_parser/issues/14

Resources