Search code examples
pythonvisual-studiorelative-path

How to set RELATIVE PATH with python in Visual Studio?


My Directory Setting
I'm studying OpenCV with Visual Studio. But I have a issue that only apply to Visual Studio.
First of all, this is sample code I made.

img = cv2.imread('../data/Lena.png')

Of course, the variable img doesn't return None in command line. Output in Command Line
But, as you can see it doesn't work in Visual Studio.(I used assert statement to check whether img is None or not) Output in Visual Studio

I assume that the start point of debugging is different from the command python [file.py]. How can I resolve this problem? There were no problems when it comes to setting the absolute path.


Solution

  • Under the settings for the microsoft python extension there is a Testing: CWD item. this allows you to set the CWD for tests. (python.testing.cwd)