I just updated my OS from Snow Leopard to LION 10.7.3, and I usually run this python script using IDLE. However, when I try running it, I get this error..
Traceback (most recent call last):
File "/Users/Brian/Desktop/BitmapBuilder.py", line 1, in
import os, shutil, Image, brianutils, sys
ImportError: No module named Image
Any help would be much appreciated, thanks in advance!
It is saying that Image is not a module. Either it doesn't exist or it isn't in Python's path or the directory in which your script is.
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'm beginner to both bash and python.
I'm working in Ubuntu env.
to be short, I've created a shell script 'format_data.sh' that runs python file 'proc_ko.py' within it.
#!/bin/bash
...
python path/to/python/file/proc_ko.py
...
And the python file 'proc_ko.py' imports a module called khaiii
from khaiii import KhaiiiApi
api = KhaiiiApi()
...
But when I try to execute 'format_data.sh', I get this import error from python file.
Traceback (most recent call last):
File "media/sf_projet/pe/pe/PROGRAMME/SCRIPTS/proc_ko.py", line 5, in
from khaiii import KhaiiiApi
ImportError: No module named khaiii
which doesn't occur when I execute python file independently.
Python file 'proc_ko.py' itself doesn't have any error and 'khaiii' is well installed.
so I don't understand why import error occurs only through the shell script.
If u need more details to figure out, I'll be happy to provide. Thanks in advance for help.
I really really need your help please. The fact is my problem should seem pretty simple to you.
So I have a macbook with Lion, I use python 3.3. In order to use GDAL for GIS? I downloaded the package on this website, which is recommended everywhere:
http://www.kyngchaos.com/software/frameworks
Then I install it. It is ok, but I cannot import it in my project, here is my error.
When I type import osgeo, I have the following :
Traceback (most recent call last):
File "<pyshell#11>", line 1, in <module>
import osgeo
ImportError: No module named 'osgeo'
I know my path is not good, wherecan I change it ?
Any ideas?
I had asked a question previously on relative paths in python in SO question: How can I access relative paths in Python 2.7 when imported by different modules
The provided answer worked great in all of my scripts and functions. However, when trying to debug the files in IDLE (Python 2.7) it generates run time errors.
Can anyone point me to documentation on using the __file__ notation? Also I would like to understand why IDLE generates errors while running the sample code but running the same file from the command line or double clicking it (for the windows users) does not.
Any help would be greatly appreciated!
Note that I am running Python 2.7 on Windows XP with virtualenv (unactivated during these tests).
Sample Code
import os
import sys
curdir = os.path.dirname(__file__)
sys.path.append(curdir + '/..')
Error
Traceback (most recent call last):
File "C:\MyFile.py", line 3, in `<module>`
curdir = os.path.dirname(`__file__`)
NameError: name '`__file__`' is not defined
__file__ won't be set if you're writing this in the interpretor.
So:
>>> import os, sys
>>> curdir = os.path.dirname(__file__)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name '__file__' is not defined
Is expected.
__file__ is the name of the file that was called by the python interpretor - so if you ran this from a script it would work.
$ python curdir.py
$
(The script is exactly the same as what I put into the interpretor, hence no error or output)
From what I've observed using IDLE before, it acts as an interpretor - so it'll run the file in question. However, it wasn't started with that file, so the __file__ is never set.
I've decided to give Python a try on Netbeans. The problem so far is when try to run program I know works, i.e. if I ran it through the terminal. For the project I selected the correct Python version (2.6.5). And received the following error:
Traceback (most recent call last): File
"/Users/XXX/NetBeansProjects/NewPythonProject3/src/newpythonproject3.py",
line 4, in
import sqlite3 ImportError: No module named sqlite3
Search for PYTHONPATH. You probably have different settings in your OS and Netbeans.