Python3. ImportError: No Module Named 'myfile'

- 1 answer

iMac-Mark:~ Mark$ python3
Python 3.3.2 (v3.3.2:d047928ae3f6, May 13 2013, 13:52:24) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import myfile
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'myfile'

I am new to Python and programming in general. I read a bit about sys.path, __PATH__ but I didn't understand anything.




  1. Have you file near the
  2. Do you have you directory in sys.path? (if not add it like this sys.path.append('path/to/python/code'))
  3. If you try import it from python enviroment you need run python shell near this file

Also you can try run this code

import sys

In your output you can see list of all directories which python see. If your file in any another directory you must change directory or python sys.path

You can do like this

$ python3
>>> import sys
>>> sys.path.append('/all/path/to/Desktop/Python')
>>> import myfile

Or like this

$ cd ~/Desktop/Python
$ python3
>>> import myfile