I installed opencv in RaspberryPi (using this link)and import in termial and python3 (idle). It shows no error in these two as shown in below images.
But, when I tried to run import cv2 in Geany, it shows error given below:
Traceback (most recent call last):
File "import.py", line 1, in <module>
import cv2
ImportError: No module named cv2
How I can solve this problem?
I solved this problem by changing python to python3 in Geany.
For this, Go to Build->Set Build Commands in Geany menu. In Set Build Commandswindow, under Python commands label in compile line python m py_compile will be there. Similarly, under Executive commands label in executive line python "%f" will be there. I changed python m py_compile into python3 m py_compile and python "%f" into python3 "%f" (as shown in images 1 and 2) and above-mentioned problem get solved.
Image 1.
Image2.
Thanks.
Related
perhaps my question is very simple, but I was not able to find a solution for my problem.
Presumably I have to level up my skills in searching. ;-)
I want to use a notificationservice (webservice: zmeventnotification) for my IP-cameras. This service needs opencv for objectdetection with yolo. Therefore I compiled opencv from source on a Ubuntu 20.04 LTS machine. The installation path for opencv was /usr/local/lib/.
After the installation a folder named "cv2" was created in /usr/local/lib/python3.8/site-packages/.
But unfortunately I have problems using this module and very poor python skills.
When I start python3 on the commandline as default user:
import cv2 -> works fine
print(cv2.__version__) -> following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'cv2' has no attribute '__version__'
When I start python3 as root, everything works fine:
import cv2 -> works fine
print(cv2.__version__) -> works fine
4.6.0-dev
As user www-data (sudo -u www-data python3) I'm even not able to import the module:
import cv2 -> following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
When I use the following lines everything works well (even for www-data).
import sys
sys.path.append('/usr/local/lib/python3.8/site-packages')
import cv2
print(cv2.__version__)
4.6.0-dev
So I tried to attach the line
export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python3.8/site-packages to /etc/profile.
This works for the default user but not for www-data.
So what can I do to give www-data access to the module without editing the source code of the notification service.
Any help would be greatly appreciated.
Thanks in advance
Fritz
I am working on a script which calls easygui. This has been added to the virtual environment.
The lines involving easygui are
#import module
from easygui import *
#set message and title
msg="Hello World!"
title="Sample Program"
# a simple window showing a message, a title and a ‘Ok’ button
msgbox(msg,title)
The script throws the error below. However, it runs perfectly when I call it from the command line. Why is pycharm throwing an error, but not the command line? Thanks.
Traceback (most recent call last):
File "/Users/nickriches/PycharmProjects/pythonProject3/main.py", line 12, in <module>
from easygui import *
File "/Users/nickriches/PycharmProjects/pythonProject3/venv/lib/python3.7/site-packages/easygui/__init__.py", line 34, in <module>
from .boxes.button_box import buttonbox
File "/Users/nickriches/PycharmProjects/pythonProject3/venv/lib/python3.7/site-packages/easygui/boxes/button_box.py", line 18, in <module>
import global_state
ModuleNotFoundError: No module named 'global_state'
I had this error this afternoon (MacOS M1, running python 3.9), and this is how I fixed it.
Basically the error is caused by the absence of a properly functioning tkinter installation, even though the error is complaining about "global_state". You can work this out by tracing through the code, which I will not do here.
You can prove to yourself that there is a defect in your tkinter installation by opening python in REPL mode and typing:
"import tkinter".
If you get an error, then you are on the right track to continue below.
The solution therefore is to properly get tkinter working.
I installed tkinter on my Mac by going to https://www.activestate.com/products/tcl/downloads/ and installing it.
Then I installed the "python-tk" module by running:
"brew install python-tk".
After that, when I opened python in REPL and ran "import tkinter", things worked.
I am getting below ImportError while running a python file.
ImportError: No module named osgeo.gdal_array
!/usr/bin/env python
from osgeo.gdal_array import BandReadAsArray
However, if i try to import same from command line, it runs fine.
$ which python
/home/hduser/anaconda2/bin/python
$ python
>>> from osgeo.gdal_array import BandReadAsArray
>>>
Also, please see the below where i am getting the same ImportError.
$ /usr/local/bin/python2.7
>>> from osgeo.gdal_array import BandReadAsArray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named osgeo.gdal_array
I figured out that there is something going on between different versions of python. But, i do not want to change the original source code.
How do i make my program run without changing anything within the code of calling python installed in anaconda explicitly?
I am new to Python and am having trouble loading numpy in Wing IDE. I can load the module and use it fine in the command line but not in Wing IDE. Below is what I am seeing:
code:
import numpy as np
a=np.arange(15)
result:
[evaluate numpy.py]
Traceback (most recent call last):
File "C:\Users[my name]\Documents\Python\practice\numpy.py", line 2, in 0
builtins.NameError: name 'arange' is not defined
I have also tried to use the help() command:
code:
help(np)
result:
Help on module numpy:
NAME
numpy
FILE
c:\users[my name]\documents\python\practice\numpy.py
It is probably due to your code being in a file named numpy.py If you do this then 'import numpy' may import your module and not numpy. This depends on what's on the Python Path and possibly current directory, which probably explains why it works outside of Wing.
I use mac ports to install python and many other modules like pygame, numpy, networkx. Codes work well on spyder and IDLE.
But when using sublimeREPL to run codes in python. It says "no module named pygame", like the follows(Sorry I cant post image for short of reputations)
Traceback (most recent call last):
File "12.py", line 2, in <module>
import pygame
ImportError: No module named pygame