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.
Solutions:
__init__.py
file near the myfile.py
?sys.path
? (if not add it like this sys.path.append('path/to/python/code'))Also you can try run this code
import sys
print(sys.path)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With