ImportError: No module named job - python

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.

Related

why my python program cannot find the modules although my setting is correct?

My colleagues shared some programs and modules with me. I put them in ...../anaconda3/lib/python3.7/site-packages/pdbParser. Below show the content.
I set this directory in $PATH. However, when I run my program at another directory (let's say user directory), I received below error message.
File "run.py", line 20, in <module>
from pdbParser.pdbParser import pdbParser
File "/<my system dir>/anaconda3/lib/python3.7/site-packages/pdbParser/__init__.py", line 14, in <module>
from __pkginfo__ import __version__, __author__
ModuleNotFoundError: No module named '__pkginfo__'
Actually, my program (run.py) can call the module (pdbParser.py) in "//anaconda3/lib/python3.7/site-packages/pdbParser/" but the module (pkginfo.py) called by pdbParser.py cannot be found. I do not understand why it happened. I read related questions (1 and 2) in this community, but I could not get the issue fixed. Is there anything wrong on my end? Any further help and suggestion would be highly appreciated.
Can you fix the error syntax in the __init__.py file like this?
append .
from
from __pkginfo__ import __version__, __author__
to
from .__pkginfo__ import __version__, __author__

"No module named 'osmium._osmium'" error when trying to use PyOsmium

I am trying to use PyOsmium but it will not import. python3 setup.py install appears to complete just fine but when I import osmium I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/dylan/Downloads/osmium/osmium/__init__.py", line 1, in <module>
from ._osmium import *
ImportError: No module named 'osmium._osmium'
I have no idea what's causing this and it's my first time manually installing a C++ wrapper. I have the top-level PyOsmium and libosmium directories in the same directory. Is it trying to import the C++ files?
Any help would be much appreciated.
I had the same problem. The solution, as provided by one of the maintainers, is very easy:
Are you in the pyosmium root directory while trying the import? Change the directory to somewhere else and try again. In the root directory the local osmium source directory takes precedence over your freshly installed version.
Change to a different directory from the one you compiled in and it should work; it did for me.

Dreamhost - ImportError: No module named _weakrefset

Dreamhost upgraded a number of servers this weekend, including the one I was on. It broke my configuration, so as recommended I attempted to delete the virtual environment it was running on and attempted to re-set it up. However, when I try to navigate to the site, I get this:
Traceback (most recent call last):
File "/home/thesp/mysite.com/env/lib/python2.7/site-packages/site.py", line 74, in <module>
__boot()
File "/home/thesp/mysite.com/env/lib/python2.7/site-packages/site.py", line 2, in __boot
import sys, os, os.path
File "/home/thesp/lib/python2.7/os.py", line 400, in <module>
import UserDict
File "/home/thesp/lib/python2.7/UserDict.py", line 83, in <module>
import _abcoll
File "/home/thesp/lib/python2.7/_abcoll.py", line 11, in <module>
from abc import ABCMeta, abstractmethod
File "/home/thesp/lib/python2.7/abc.py", line 8, in <module>
from _weakrefset import WeakSet
ImportError: No module named _weakrefset
I've got Python 2.7.8 installed and running, and from shell access, both in and out of my virtual environment when I run Python, I'm pulling up the correct version (which is different from the native version installed, so it's finding my setup). Other posts which reference this error message seem to think it's a problem with not having an upgraded version of virtualenv, but its version is higher than the troublesome version. (I'm running 1.11.6.)
Weirder still, I can shell into Python, type from _weakrefset import WeakSet, and I don't get import errors. I'm running Django 1.6 and I can python manage.py runserver with no errors, but the web server is throwing up before it ever sees Django.
In the traceback, the first two lines are pulling from my virtual environment, but the remaining ones don't seem to be, and I have no idea why, or even if that's relevant.
Any advice on what I should do next? I've about pulled my hair out on this one! I can post any additional information that would help troubleshoot. Thanks!
Well, I feel silly now. I went to the /home/thesp/lib/python2.7/ directory and downloaded _weakrefset.py, like so:
wget http://svn.python.org/projects/python/trunk/Lib/_weakrefset.py
...and now everything seems to be running fine. There was a _weakrefset.pyo file in the directory, so I'm not sure why _weakrefset.py never made it in, but this seems to have done the trick.
Now, that doesn't solve the mystery of why the stack trace switches directories like it does, but it's running now, so I'll take it for now!

Import error in Python: Polygon

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.

Import tries to import a different file than I specified

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).

Categories