Python cant find module in the same folder

Python cant find module in the same folder

Change your import in to:

from .hello import hello1

Your code is fine, I suspect your problem is how you are launching it.

You need to launch python from your 2014_07_13_test directory.

Open up a command prompt and cd into your 2014_07_13_test directory.

For instance:

$ cd /path/to/2014_07_13_test
$ python

If you cannot cd into the directory like this you can add it to sys.path


import sys, os

Or set/edit the PYTHONPATH

And all should be well…

…well there is a slight mistake with your shebang lines (the first line in both your files), there shouldnt be a space between the # and the !

There is a better shebang you should use.

Also you dont need the shebang line on every file… only the ones you intend to run from your shell as executable files.

Python cant find module in the same folder

I had a similar problem, I solved it by explicitly adding the files directory to the path list:

import os
import sys

file_dir = os.path.dirname(__file__)

After that, I had no problem importing from the same directory.

Leave a Reply

Your email address will not be published. Required fields are marked *