'No such file or directory' with absolute Path

前端 未结 2 1257
清歌不尽
清歌不尽 2021-01-26 06:59

I want to import a .png file with

import matplotlib.pyplot as plt
O = plt.imread(\'C:/Users/myusername/Downloads/Mathe/Picture.png\')

I have th

2条回答
  •  囚心锁ツ
    2021-01-26 07:34

    If you're using Windows, that path may cause issues because of the direction of the slashes. Check out this article. You shouldn't hardcode paths because regardless of which direction of slash you use, it can break on other operating systems.

    It should work with something like this:

    import os
    import matplotlib.pyplot as plt
    
    picture_path = os.path.join("C:", "Users", "myusername", "Downloads", "Mathe", "Picture.png")
    im = plt.imread(picture_path)
    

提交回复
热议问题