I just finished installing SimpleCV and all its dependencies, but am having trouble running it. If I just use this:
import SimpleCV
I don't get any errors, but when I try:
from SimpleCV import Camera
I get the error:
ImportError: cannot import name Camera
Any ideas?
If you are attempting to use SimpleCV from eclipse and you're getting these errors, perhaps you could try the instructions I posted in this question's answer: SimpleCV Code Completion with Eclipse I'll paste the same info for you here:
My attempt at fixing their imports was to remove all those import *'s from their init.py file which helps with the code completion lag that it presents in eclipse. Then importing the SimpleCV egg directory (C:\Python27\Lib\site-packages\simplecv-1.3-py2.7.egg) into eclipse as an external library. After that, I was able to run this:
from SimpleCV.ImageClass import Image
Same goes for importing Color:
from SimpleCV.Color import Color
There are cyclical imports, so beware of those as they might bite you. I myself had one earlier while trying to import SimpleCV.Color before importing SimpleCV.ImageClass. Note, with the above instructions, I seem to be able to get code-completion from Eclipse.
Related
I have been trying to use the noise module in Python for a game I was making. I am on the Mac OS, and I used pip3 install noise to download the module. I uninstalled and reinstalled it multiple times, without the wheel library, and with, as it recommended. The noise module itself downloads fine, but every time I try to import pnoise from it, I get an ImportError.
Just straight up importing noise (import noise) gives me no error, it just prints a string of numbers to my console. Also, downloading and running the module in a virtual environment works, so it must be something on my computer or OS.
Code: from noise import pnoise1
Error: ImportError: cannot import name 'pnoise1' from 'noise'
I have looked for a while for a solution, but nothing has seemed to help, it just doesn't work. The only information I have found is that this may be a file problem, but I haven't found out how to fix it.
Any help would be greatly appreciated.
Edit:
I ended up figuring it out. I was importing a file by the same name instead of the library. Thanks for the help, everyone!
To me it works ok. Have you installed it correctly via pip/pip3?
Ended up figuring it out, I was importing a file of mine instead of the library. Thanks for the help!
I am using python version 3.6.2 and working on image processing. My problem is when I run python through cmd it imports io module of skimage without error but when I import it through python Idle it shows module error that no module name io. Can anyone please enlighten me why is this happening? For more understanding i'm putting screenshots of both the cases.
Through cmd:
Through Python Idle:
This problem got solved by reinstalling each and every supporting package.
I am trying to freeze a Python script that contains an import from osgeo but the executable fails with an ImportError: No module named '_gdal'.
I've stripped down my script to just one line:
import osgeo
When running in Python (version 3.3.3) all is well. I've tried freezing with cx_Freeze and py2exe. Both report that there is a missing module: ? _gdal imported from osgeo (among others) but successfully freeze the script. Then the exe fails with the above ImportError.
I've tried importing _gdal in python and it works. I tried manually including the osgeo module in the freezing options but still get the same error.
There is a similar question here:
Importing GDAL with cx_Freeze, Python3.4
but maybe this isn't a cx_freeze issue because it also happens with py2exe (it has experimental support for python 3 now).
Does anybody know how to fix this?
I found a fix. I edited the osgeo\__init__.py file and modified line 13 like this: import osgeo._gdal. This works but only if the module osgeo._gdal is manually included when freezing. #Thomas K Your solution does the same thing I guess.
Note that the same modification must be applied both at osgeo.ogr (line 18) and osgeo.osr (line 18) modules if they are needed (import osgeo._ogr and import osgeo._osr respectively). This means that these must be manually included when freezing as well. My freezing command now looks like this: python cxfreeze.py module1.py --include-modules=osgeo._gdal,osgeo._ogr,osgeo._osr.
Thanks #Thomas K for your help.
I want to import PIL in Sikuli for doing that I have added the code below
import sys
sys.path.append("C:\\Python27\Lib\site-packages")
sys.path.append("C:\\Python27\Lib\site-packages\PIL")
import PIL
import Image
So it imported the above modules but when I am trying to import ImageFont, it's giving me the error below:
def getmask2(self, text, mode="", fill=Image.core.fill):
File "C:\Python27\Lib\site-packages\PIL\Image.py", line 39, in __getattr__
raise ImportError("The _imaging C module is not installed")
ImportError: The _imaging C module is not installed
I am able to import PIL and Image and ImageFont successfully in Python scripts and code is running fine.
Any idea how to fix this?
The Sikuli IDE uses Jython so packages installed to your local Python version won't be able to be imported within the Sikuli IDE and Jython doesn't support c extensions as far I'm aware which PIL requires ( see http://bugs.jython.org/issue1388 ).
I think you would need to use a Java library, maybe something like ImageJ ( see http://fiji.sc/wiki/index.php/Jython_Scripting )
Since the following (as I think valuable information) was rejected as an edit to the original question (my intention: people should see this in the first place), I put it as an answer now:
I want to add:
Python modules can be imported in Jython/Sikuli scripts as long as they contain only Python code. There are many modules written for Python, that hold this condition (e.g. xlrd, xlwt). But as correctly mentioned: PIL contains C-based stuff and this can normally (exception JNI libs) not be loaded (hence the above error message, which is true, but might lead in the wrong direction).
I am trying to work with PIL in my project but the pydev can't seem to find it in my project. First of all I can see it when I enter the python shell, I can import it and I see it in the python sys.path. Second, I Added it to the PYTHONPATH in eclipse.
I restarted eclipse, but still, when I try to do "from PIL import Image" I am getting: "unresolved import".
Can any one please help me here, all other packages I used until now worked great the same way.... and i really need to use PIL
Try to go to Window -> Preferences -> Pydev-> Interpreter -> Python Interpreter -> Forced Builtins tab.
Then add a PIL entry and apply.
I've had the same unresolved import error when tried to import from this particular package (other packages worked fine), and found this information which finally helped me.
Had the same problem here.
Got it resolved by adding /usr/share/pyshared to the Libraries tab in window->preferences->pydev->Interpreter - Python.
There were a lot of /usr/lib/python* paths with the compiled libraries (the C stuff with python bindings) where included already, but not /usr/share... parts with the source.