'Error22 with plt.savefig() [closed]

I'm trying to save a jpg in one of my files but I revice error 22 all the time. This is my code:

 buy_dir = r'‪C:/Users/Erik/Downloads/buy/'
 plt.savefig(buy_dir + str(uuid.uuid4())+'.jpg', bbox_inches='tight')

And i receive this error:


OSError: [Errno 22] Invalid argument: '\u202aC:/Users/Erikb/Downloads/buy/f8365950-f1e8-4c46-b477-6b4c28d292a3.jpg' 

Could anyone help me?



Solution 1:[1]

You can try convert it with os.path.abspath

from os import path
plt.savefig(path.abspath(buy_dir + str(uuid.uuid4())+'.jpg'), bbox_inches='tight')

Solution 2:[2]

I had a problem with running the first line (unicode error), seems like there is a weird character or something. When retyping the first line it worked fine for me:

buy_dir = r'C:/Users/Erik/Downloads/buy/'
plt.savefig(buy_dir + str(uuid.uuid4())+'.jpg', bbox_inches='tight')

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ymmx
Solution 2 Tobias Molenaar