PyCharm error: 'No Module' when trying to import own module (python script)

前端 未结 14 1833
醉话见心
醉话见心 2020-12-07 07:57

I have written a module (a file my_mod.py file residing in the folder my_module). Currently, I am working in the file cool_script.py t

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-07 08:14

    This can be caused when Python interpreter can't find your code. You have to mention explicitly to Python to find your code in this location.

    To do so:

    • Go to your python console
    • Add sys.path.extend(['your module location']) to Python console.

    In your case:

    • Go to your python console,
    • On the start, write the following code:

      import sys
      sys.path.extend([my module URI location])
      
    • Once you have written this statement you can run following command:

      from mymodule import functions
      

提交回复
热议问题