Python Forum

Full Version: [split] Bad magic number. What is it ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have the same problem as Sylas has described although I am not interested what a bad magic number is unless the information leads to a solution.
I am following a tutorial topic 'How To Import Modules in Python 3' at https://www.digitalocean.com/community/t...n-python-3 All went well until, following instructions, I moved the module file hello.py from the same directory as the file which imports the module, main_program.py, to one of the directories listed by print(sys.path), namely, /home/<myusername>/.local/lib/python3.5/site-packages/hello.py
hello.py
# Define a function
def world():
    print("Hello, World!") 

main_program.py
# Import hello module
import hello

# Call function
hello.world()
This results in the same error message as reported my Sylas.
Error:
Traceback (most recent call last): File "main_program.py", line 2, in <module> import hello ImportError: bad magic number in 'hello': b'\x03\xf3\r\n'
I am running Python 3.6.5 (default, Sep 6 2018, 17:29:53) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux 3.10.0-862.3.2.el7.x86_64.
Thank you buran. As mentioned in https://stackoverflow.com/a/514395/4046632 there was a .pyc file in the calling program's directory and deleting it fixed the 'ImportError: bad magic number' error.