Python can find a module…and then it can't

前端 未结 2 1142
故里飘歌
故里飘歌 2020-12-12 07:45

I am finally going full steam into Python, but for some reason I have an issue where Python can find a module in the interactive CLI and then it can\'t when I write a script

相关标签:
2条回答
  • 2020-12-12 08:15

    You have a mysql something or other either in your home directory, or in your new directory. It might be a .py file or perhaps the actual package (in the wrong place ;). Fix that and your problem should go away.

    0 讨论(0)
  • 2020-12-12 08:35

    In the traceback, I see that you named your file mysql.py. Therefore, when you try to import something from mysql.py, the interpreter looks for it in your own script, not the "actual" module. Instead of casting a wider net, it immediately gives up. To fix this, rename your script to something that doesn't mask any module names.

    0 讨论(0)
提交回复
热议问题