Can't import cv2 in Python 2.7 linux - linux

I'm trying to get OpenDroneMap to run on my linux mint machine. I've been working my way through a number of problems in the current release's dependency chain.
At the moment, I'm stumped on getting the OpenCV module, cv2 to import.
OpenCV is required by an OpenDroneMap dependency, OpenSfM and it's one of the OpenSfM py files that tries to import the module cv2.
Anyway, running OpenDroneMap generates the error:
Traceback (most recent call last):
File "~/OpenDroneMap/src/OpenSfM/bin/opensfm", line 10, in <module>
from opensfm import commands
File "~/OpenDroneMap/src/OpenSfM/opensfm/commands/__init__.py", line 3, in <module>
import extract_metadata
File "~/OpenDroneMap/src/OpenSfM/opensfm/commands/extract_metadata.py", line 5, in <module>
from opensfm import dataset
File "~/OpenDroneMap/src/OpenSfM/opensfm/dataset.py", line 12, in <module>
import cv2
ImportError: dynamic module does not define init function (PyInit_cv2)
b
quitting cause:
PYTHONPATH=~/OpenDroneMap/lib/python2.7/dist-packages "~/OpenDroneMap/src/OpenSfM/bin/run_all" opensfm
returned with code 256.
From what I can tell, the import error cause typically suggests that the cv2 module was not found. I've ensured that cv2.so does exist in the path specified, as well as the usr/lib/python27/dist-packages path, where it seems to me it should really be looking...
In any case, I was hoping someone might be able to give me some direction on what to try next.

Related

ImportError: cannot import name 'cpyHook' from partially initialized module 'pyWinhook'

This has been plaguing me for a while now, and I'm not sure what to do about it. I've tried modifying the init.py pyWinhook script's imports, but to no avail. Here's the whole error:
Traceback (most recent call last):
File "d:\myuser\Documents\Python\evil_programs\keylogger.py", line 6, in <module>
import pyWinhook as pyHook
File "C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\__init__.py", line 1, in <module>
from .HookManager import *
File "C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\HookManager.py", line 1, in <module>
from . import cpyHook
ImportError: cannot import name 'cpyHook' from partially initialized module 'pyWinhook' (most likely due to a circular import) (C:\Users\myuser\AppData\Roaming\Python\Python310\site-packages\pyWinhook\__init__.py)
Thanks in advance
The way I fixed this is by installing Python 3.8.
Python 3.10 and 3.11 produced this issue.
I got this idea from the executable name on GitHub "pyWinhook-1.6.2.win-amd64-py3.8.exe"
Why it does not work with newer python, I have no clue.

Numpy related Error while running a docker container

I composed a docker image file that gets built successfully.
However, when I run a container with that image, it produces the following numpy error and exits.
Any idea how this could be corrected?
ERROR:
Traceback (most recent call last):
File "/opt/venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 22, in <module>
from . import multiarray
File "/opt/venv/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in <module>
from . import overrides
File "/opt/venv/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /opt/venv/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-gnu.so)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/src/app/./MetReTrim", line 14, in <module>
import matplotlib.pyplot as plt
File "/opt/venv/lib/python3.9/site-packages/matplotlib/__init__.py", line 107, in <module>
from . import _api, cbook, docstring, rcsetup
File "/opt/venv/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 28, in <module>
import numpy as np
File "/opt/venv/lib/python3.9/site-packages/numpy/__init__.py", line 150, in <module>
from . import core
File "/opt/venv/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/opt/venv/bin/python"
* The NumPy version is: "1.21.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /opt/venv/lib/python3.9/site-packages/numpy/core/_multiarray_umath.cpython-39-x86_64-linux-gnu.so)
Did you install numpy outside of docker, and copied the venv?
If so, C extensions were compiled for your host (which, according to the error, is not Linux)
You'll need to install numpy into the container itself

Running vispr throws EmptyDataError when importing pandas.io.common

I'm trying to run the tool vispr in able to visualize the results of the mageck-vispr run.
I have installed everything as explained on the website within a conda environment.
Unfortunately, when running the command
vispr server results/GSC.vispr.yaml
it throws an error
Traceback (most recent call last):
File "/fs/home/yeroslaviz/miniconda3/bin/vispr", line 6, in <module>
from vispr.cli import main
File "/fs/home/yeroslaviz/miniconda3/lib/python3.7/site-packages/vispr/__init__.py", line 12, in <module>
from vispr.results import Screens, Screen
File "/fs/home/yeroslaviz/miniconda3/lib/python3.7/site-packages/vispr/results/__init__.py", line 15, in <module>
from vispr.results import rna
File "/fs/home/yeroslaviz/miniconda3/lib/python3.7/site-packages/vispr/results/rna.py", line 14, in <module>
from pandas.io.common import EmptyDataError
ImportError: cannot import name 'EmptyDataError' from 'pandas.io.common' (/fs/home/yeroslaviz/miniconda3/lib/python3.7/site-packages/pandas/io/common.py)
From what I could find online, this exception might happens, when trying to read an empty file, but all the entries listed in the called GSC.vispr.yaml file exists and are not empty.
I would appreciate it, if someone can help me narrow down the problem or offer a solution.
thanks
I am not sure if the solution I have found is the right one, but all I did is to comment out line 14 in rna.py
import pandas as pd
# from pandas.io.common import EmptyDataError
import numpy as np
Now vispr is working.

Can't get opencv working with a gtk backend on my mac

I am trying to do some human pose estimation with a cool library that can be found here:
https://github.com/DeNA/Chainer_Realtime_Multi-Person_Pose_Estimation
I have it working on still images using the tkagg backend, set via the following lines:
import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
Unfortunately, to do the live webcam tracking it seems tkagg will not work. When I run the code to do live web cam tracking i get the following error:
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp, line 583
This seems to be telling me to use the GTK backend, which makes sense as that is what the original repo said to use. The issue is when i change the matplotlib.use line to GTK like so:
import matplotlib
matplotlib.use('GTK')
import matplotlib.pyplot as plt
This gives an error with the following trace:
Traceback (most recent call last):
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 14, in
import gobject
ImportError: No module named 'gobject'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "camera_pose_demo.py", line 4, in <module>
from pose_detector import PoseDetector, draw_person_pose
File "/Users/mark/Downloads/Chainer_Realtime_Multi-Person_Pose_Estimation-master/pose_detector.py", line 8, in <module>
import matplotlib.pyplot as plt
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/pyplot.py", line 116, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
[backend_name], 0)
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 18, in <module>
raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.
This is obviously saying my program can't find the GTK backend. I have installed it via brew, but I have read of other people having this problem too - just withouth a clear answer. It seems as though I need to find GTK on my machine and explicitly tell my python program/virtualenv where that is, although i am not sure how to do this.
You need to install PyGTK (python wrapper for GTK) which in turn require pygobject (python wrapper for GObject).
PyGTK seems to be rather old (2011 year), I am not sure it works with Python 3.

requests module not working in pycharm (only)

I was trying to create a web scraping program , which uses bs4 and requests library. What i noticed that whenever pycharm encounters import requests it just gets stuck and throws an error when i press return .The error is :
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\HP\64bit\lib\site-packages\requests\__init__.py", line 43, in <module>
import urllib3
File "C:\Users\HP\64bit\lib\site-packages\urllib3\__init__.py", line 8, in <module>
from .connectionpool import (
File "C:\Users\HP\64bit\lib\site-packages\urllib3\connectionpool.py", line 3, in <module>
import logging
File "C:\Users\HP\AppData\Local\Programs\Python\Python36\Lib\logging\__init__.py", line 28, in <module>
from string import Template
File "C:\Users\HP\PycharmProjects\Automate\string.py", line 28, in <module>
t = int(input())
ValueError: invalid literal for int() with base 10: ''
>>>
Trying to do the same in IDLE shell or cmd window works just fine
I'm using windows 10 64-bit , python 64-bit 3.6.2rc1 & Pycharm 2017.1.4 community edition.
Your PYTHONPATH is screwed up, which is probably due to PyCharm's option to add the project root to PYTHONPATH (the option is in the "run" settings).
Due to the messed-up PYTHONPATH, the string import inside requests imports your string.py instead of the same module from the stdlib (the traceback clearly shows this by the way).
Easiest solution? Don't have top-level .py files, put them inside a package. That way only your package will be importable as a top-level package in PYTHONPATH but you don't end up having tons of new top-level modules.

Resources