How to import python file located in same subdirectory in a pycharm project

前端 未结 8 1581
盖世英雄少女心
盖世英雄少女心 2020-12-13 08:48

I have an input error in pycharm when debugging and running.

My project structure is rooted properly, etc./HW3/. so that HW3 is the root di

相关标签:
8条回答
  • 2020-12-13 09:15

    In Pycharm go to "Run - Configuration" and uncheck 'Add Content root to Pythonpath' and 'Add source roots to Pythonpath', then use

    from filename import functionname
    
    0 讨论(0)
  • 2020-12-13 09:19

    Note: May be a bit unrelated.

    I was facing the same issue but I was unable to import a module in the same directory (rather than subdirectory as asked by OP) when running a jupyter notebook (here the directory didn't have __init__.py). Strangely, I had setup python path and interpreter location and everything. None of the other answers helped but changing the directory in python did.

    import os
    os.chdir(/path/to/your/directory/)
    

    I'm using PyCharm 2017.3 on Ubuntu 16.04

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