PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 30, 2022

[FIXED] How to add a new folder to the directory you are in in jupyter notebook

 July 30, 2022     image, jupyter-notebook, python     No comments   

Issue

I am working with python and jupyter notebook, and I am writing code to save images to a folder. However, I am getting the error 'FileNotFoundError: [Errno 2] No such file or directory: 'plots/plot0.jpg'. I believe this is because I do not have a folder 'plots' in the current directory, and I was wondering how do add this. I have attached some code to see what is in the directory and how I am saving this image. Thank you!

img.save("plots/plot" + str(j) + ".png")

I ran this code:

import os
os.listdir()

and 'plots' was not in there, does this mean I need to create a new folder, and if so, how do I do that? Thank you!

'


Solution

It appears you are trying to save the image file to a folder named "plot" which doesn't exist. You can use os.makedirs() to create this "plot" folder

For example:

import os
os.makedirs("plots")

This will create a new directory named "plots" in the current directory from which you have called this python script.

You could then check to see if the folder has been created in your directory by using os.listdir()



Answered By - Jacques
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing