Python works in PyCharm but not from terminal

后端 未结 7 824
你的背包
你的背包 2020-12-31 03:06

I recently figured out how to import modules for unittesting in python. As a solution to this, I use:

sys.path.append(os.path.abspath(os.path.join(os.path.di         


        
7条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 03:53

    What @codewarrior has said about the PyCharm setting its own PYTHONPATH is correct. But sys.path didn't have my current working directory. So to get around this problem, I updated my PYTHONPATH (or you can edit sys.path).

    Setting PYTHONPATH

    export PYTHONPATH=$PYTHONPATH:`pwd`  (OR your project root directory)
    

    Updating sys.path

    import sys
    sys.path.insert(0,'') OR
    sys.path.append('')
    

    You can use insert/append based on the order in which you want your project to be searched.

    HTH.

提交回复
热议问题