Hey Guys I know this has been asked before, and even various times, but I can't really figure out the exact problem with regards to my issue, even after looking at the other import errors.
It's a really basic question, so sorry for that...
I'm writing a program, we'll call it "X.py". I need to import from another file, named graphics.py so my first line of code says:
from graphics.py import *
I'm pretty sure the rest of my code is right, but when I run the program it gives me the error saying
Traceback (most recent call last):
File "/Users/me/Desktop/X.py", line 1, in <module>
from graphics import *
ImportError: No module named 'graphics'
Now I clearly have this file downloaded and I put them in a folder called Project X, together.
Any idea how I can get this program to see the other file I guess?
Thanks in advance!
Drop the .py
Instead, use:
from graphics import *
You have to download this file and put it in the same folder with your script.
From the docstring:
INSTALLATION: Put this file somewhere where Python can see it.
Related
I'm getting an error on importing a function from another file in python.
This is my file structure
In checkSpellings.py there's a function defined as spellchecker(tokenized_text) . And I'm trying to use it by importing it on main.py by following code
from checkSpellings import spellChecker
But it gives me an warning (red underline on top of both of checkSpellings(file name) and spellChecker(function name) in import code). This previously happened and I though this is purely an issue with intellisense . Because last time same thing happened (gave me the warning), but the code worked fine.
But now when I run the main.py it gives me an error saying
Traceback (most recent call last):
File "/home/pankaja/Documents/PycharmProjects/BookDigitizer/OCR_Correction/main.py", line 1, in <module>
from checkSpellings import spellChecker
ImportError: cannot import name 'spellChecker
How can I fix this ? What have I done wrong ?
IMPORTANT : Here I'm using python3.6 interpreter on an anaconda virtual environment. Might it be an issue ?
The function is spellchecker but you tried to import spellChecker.
The form builder wxFormBuilder imports wx and wx.xrc. However the second of these causes an error as follows:
Traceback (most recent call last):
File "/home/peter/python/wxpython/wxFormBuilder/Demo/demo.py", line 4, in
import demogui
File "/home/peter/python/wxpython/wxFormBuilder/Demo/demogui.py", line 11, in
import wx.xrc
File "/usr/local/lib/python3.6/dist-packages/wx/xrc.py", line 10, in
from ._xrc import *
ImportError: libwx_gtk3u_html-3.0.so.0: cannot open shared object file: No such file or directory
The obvious answer would be that the file was missing, but it isn't:
peter#peter-HP-Pavilion-15-Notebook-PC:~$ locate libwx_gtk3u_html-3.0.so.0
/usr/local/lib/python3.6/dist-packages/wx/libwx_gtk3u_html-3.0.so.0
So, to my inexperienced eyes it seems to be present and in the right place. Can anyone make any suggestions on this?
I'm using wxPython for Python 3, by the way.
Many thanks
This issue was fixed in wxPython release 4.0.1, see the discussion at https://groups.google.com/forum/#!topic/wxpython-users/UBjdeTgOmD4.
The build scripts were setting LD_RUN_PATH only for the wxPython libraries, not for the embedded wxWidgets build. I can confirm that the fixes mentioned in https://github.com/wxWidgets/Phoenix/issues/723 solve the issue.
I'm trying to import mrjob so I can run a script. It was working fine about an hour ago, and then I changed some code around to try to make my job faster.
when I run this import:
from mrjob.job import MRJob
I get this:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "mrjob.py", line 5, in <module>
from mrjob.job import MRJob
ImportError: No module named job
but if I try to import in this directory (/usr/local/bin) it works. This is really starting to get to me. Anyone know how to fix this? I've tried uninstalling and installing again. Tried updating pip, tried exporting my path (even though I don't really know what I'm doing with system paths and whatnot). Anyone have any tips?
Thanks
EDIT:
It seems I can import mrjob from any directory, but the directory that my project is in. I've tried moving the project directory around but nothing seems to work. Tried updating my PATH and PYTHONPATH profile variables, nothing seems to work :/
May be you have another module in your PYTHONPATH called mrjob?
Try this
import mrjob
print(mrjob.__file__)
to check mrjob module location.
I installed this library called Polygon, in Python 2.7.3. But, each time I import it I get the next error message :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "Polygon/__init__.py", line 5, in <module>
from Polygon.cPolygon import *
ImportError: No module named cPolygon
I have no idea about what could be going wrong. And also, I have already tried to contact the original author of this on his personal webpage.
but he hasn't replied though :( I wonder if someone can help me with this issue please.
It sounds like you didn't in fact install it, but instead just copied it to your working directory. As always, run setup.py with the appropriate arguments to install.
This error can happen if you try to run python from inside the directory you used to install Polygon. Move to a different directory and try again.
I had a file called baseFunctions.py which I changed to elementFunctions.py. Importing elementFunctions with parsePeaksMzML.py gave me weird print statements, especially because I did not have any print statements in elementFunctions.py. Stepping through the code with Eclipses debugger showed instead of doing
import elementFunctions
as it said in the parsePeaksMzML.py, it actually did
import baseFunctions
I thought there was some weird mix-up with the renaming, so I copied all the code from elementFunctions.py, deleted the file, made a new file and pasted in all the code in the new file. Still I got the same weird errors. Looking in the folder I still had the baseFunctions.pyc, so I deleted that. Rerunning the code gave me:
Traceback (most recent call last):
File "/homes/ndeklein/workspace/MS/Trunk/PyMS_dev/pyMS/test/test_parsePeaksMzML.py", line 25, in <module>
import parsePeaksMzML
File "/homes/ndeklein/workspace/MS/Trunk/PyMS_dev/pyMS/test/parsePeaksMzML.py", line 12, in <module>
import elementFunctions
ImportError: No module named baseFunctions
Somehow import elementFunctions points to import baseFunctions (I have no clue why) and deleting and remaking elementFunctions.py has no effect. I can't find anything like this searching on google or stack overflow, so I'm kind of stumped here.
I suspect it to be a problem with eclipse, but I'm not sure.
edit:
What makes it even stranger, I get the error when I import parsePeaksMzML.py from
test_parsePeaksMzML.py, but not when I run parsePeaksMzML.py directly.
edit2:
Running from the commandline gives the same error:
-bash-3.2$ python test_parsePeaksMzML.py
Traceback (most recent call last):
File "test_parsePeaksMzML.py", line 26, in <module>
import parsePeaksMzML
File "/homes/ndeklein/workspace/MS/Trunk/PyMS_dev/pyMS/test/parsePeaksMzML.py", line 12, in <module>
ImportError: No module named baseFunctions
-bash-3.2$
If you changed the name of a file, probably you have some old .pyc lingering in your workspace. I'm assuming you're using the PyDev plug-in in Eclipse; I haven't used it in a while, but you should be able to do a Project -> Clean. If that doesn't help, try manually clearing all of the .pyc files in your workspace.
The symptoms you describe are very strange, so I'm not 100% sure what the problem is. Regardless, trying cleaning your workspace and let us know how things progress from there.
Do try a blanket delete of all .pyc files and see if that clears it up. If not, here are a few possibilities:
Your $PYTHONPATH points to different source than you expect. (Though this would likely not be the entire explanation.)
Code within elementFunctions/__init__.py is trying to import baseFunctions.
Code somewhere is using an exec statement to do imports, or using the built-in __import__ function to dynamically import baseFunctions (which might make the source of the directive difficult to hunt down).