I am working on my first open source project.
While getting everything setup for the project, I followed the README.md step by step.
Now, I run into a problem. When I try to run a test and src scripts, I get the following error,
ImportError: No module named modules
Now, below is the file structure.
../
/modules
__init__.py
/src
lyrics.py
/tests
test_lyrics.py
lyrics.py import statements
import modules
def test_lyrics():
assert('lyrics' == modules.process_query('paradise lyrics')[0])
This is where the error "Import Error: modules not found".
Yes, all the requirements on the README were met.
If you want to take a look at the project, check it out on github .
It could be that your module's directory is not being read by your PYTHONPATH. To check this go to your home directory and look for a .bashrc
or some kind of .profile
file. You may have to use ls -a
to see these hidden files. If you don't see your module's address listed, add this to the file:
export PYTHONPATH="${PYTHONPATH}:/my/module/path"
Make sure the address points to the directory with your highest-level __init__.py
file as python uses it to read the directory as a python package.
Use python -m site
to conveniently view the effect of the $PYTHONPATH env var on sys.path
.
Code authors will often assume that current directory is in your path:
$ export PYTHONPATH=.
If you intend to use .
current directory, then pay careful attention to which one's in use at the time the script starts running. You may want to view this value: os.getcwd()
I am maybe a bit late to the party but I can answer and maybe it helps.
1)Check once more your paths. 2)Check that you run with >./myProj arguments more arguments, and not
myProj arguments more arguments. Hope it helps even a bit
You could try using a relative import
from ..modules import process_query
def test_lyrics():
assert('lyrics' == process_query('paradise lyrics')[0])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.