IOError: [Errno 2] No such file or directory: 'nik7.jpg' - python-imaging-library

Error
IOError: [Errno 2] No such file or directory: 'nik7.jpg'
I am trying to read an image but get the above error.
Code:
from PIL import Image
pil_im=Image.open('C"\Users\nikhil\Desktop\nik7.jpg' )

Two things:
You're missing a colon
\ escapes the next character, so either use two (double escape): \\, or use the Unix-style / which works on Windows too:
pil_im = Image.open('C:/Users/nikhi/Desktop/nik7.jpg')

Related

How do I solve this issue?

I tried to install a package in command prompt (actin) from python.but always there is an error. I tried to solve this issue but I could not.
The package is (Actin) to calculate the indices in science.
this is an error:
This is what I do:
C:\Users\MAISSA>**\pip install actin
Collecting actin
Using cached actin-1.3.6.tar.gz (52.0 MB)
ERROR: Could not install packages due to an OSError: [Errno 22]
Invalid argument: 'C:\Users\MAISSA\AppData\Local\Temp\pip-install-ysinw5a9\actin_8d5ed7c1aad943cbba7a60ea2545108f\actin/test_files/2010-09-18T23:42:36.178_spec.rdb
The Python OSError: [Errno 22] Invalid argument problem occurs,1.The file path is faulty(The file path does not exist, or the string is inconsistent with the file path) 2.When there are strange characters in front of the path,You should have thought it was because of coding(Whether it's ANSI coding or UTF-8 coding or some other coding reason)

Changing directory with os in python

I'm trying to change the directory to the folder that contains the folder I'm in.
That is, I'm in /Users/ethanfuerst/Documents/Coding/mpgdata and I'm trying to go back to /Users/ethanfuerst/Documents/Coding and access a text file in the Coding folder.
When I run this code:
import os
print(os.getcwd())
os.chdir('⁨Users/ethanfuerst/Documents/Coding')
I get this output and error
/Users/ethanfuerst/Documents/Coding/mpgdata
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-19-6c6ee01785f6> in <module>
1 import os
2 print(os.getcwd())
----> 3 os.chdir('⁨Users/ethanfuerst/Documents/Coding')
FileNotFoundError: [Errno 2] No such file or directory: '\u2068Users/ethanfuerst/Documents/Coding'
Does anyone know why this could be the case?
Edit: forgot to mention I am on a Mac
Try using C:\ in front of Users. If that does not work, try using .. in the directory specification to go back one directory.
Use double quotes os.chdir("⁨Users/ethanfuerst/Documents/Coding") instead of os.chdir('⁨Users/ethanfuerst/Documents/Coding')

PyPDF2 giving me an invalid argument error

I'm trying to parse text from pdf file. while I was doing tutorial of how to PyPDF2 I got the following error. I did the search for an answer but ended up finding none. Any Help will be greatly appreciated.
Traceback (most recent call last):
File "D:/text_recognizer/main.py", line 4, in <module>
inputStream = PyPDF2.PdfFileReader(input)
File "D:\KimKanna's Class\python27\lib\site-packages\PyPDF2\pdf.py", line 1084, in __init__
self.read(stream)
File "D:\KimKanna's Class\python27\lib\site-packages\PyPDF2\pdf.py", line 1689, in read
stream.seek(-1, 2)
IOError: [Errno 22] Invalid argument
here is fullcode
import PyPDF2
with open(".\\pdf\\test_sample.pdf","rb") as input:
inputStream = PyPDF2.PdfFileReader(input)
In my case the .pdf I wanted to open is empty and not closed from previous python code in powershell(cmd prompt). So, when I tried to delete those files it says 'Close the file and try again'. (that was my "AHaa" moment)
So I stopped the py.exe from my Windows task manager and deleted those empty, not closed files. Then I run the same code with another files, It worked fine.. :)

iPython notebook not uploading my .txt file

I converted some excel files to .txt files (Text (tab delimited)), carefully saved them in the same folder as my notebook, made sure there were no copies anywhere on my computer, checked the .txt files could all be opened in Notebook, and after using the command '%pylab inline' to load all the functions I usually use, triple checked that mt .txt files were in the same folder as the notebook by using the 'ls' command. I then used loadtxt('filename.txt') to load my data and it gave me errno 2: no such file or directory: 'filename.txt'. I triple checked that I had spelled everything correctly and I can't understand why it's not working. I need these data analysing today for a lab report due in tomorrow - help! Here's my code:
%pylab inline
ls
loadtxt('Physical_lab_experiment_2_25_degrees_with_times.txt')
and here is the error:
FileNotFoundError Traceback (most recent call last)
<ipython-input-9-c8d929572f25> in <module>()
----> 1 loadtxt('Physical_lab_experiment_2_25_degrees_with_times.txt')
C:\Users\Daisy\Anaconda3\lib\site-packages\numpy\lib\npyio.py in loadtxt(fname, dtype, comments, delimiter, converters, skiprows, usecols, unpack, ndmin)
738 fh = iter(open(fname, 'U'))
739 else:
--> 740 fh = iter(open(fname))
741 else:
742 fh = iter(fname)
FileNotFoundError: [Errno 2] No such file or directory: 'Physical_lab_experiment_2_25_degrees_with_times.txt'
loadtxt is a numpy function. Import numpy like:
import numpy as np
data= np.loadtxt('Physical_lab_experiment_2_25_degrees_with_times.txt')
print data

pytesser IOError: [Errno 2] No such file or directory:

I´m trying to use pytesser but I´m getting this error:
IOError: [Errno 2] No such file or directory:
I´m using a mac machine and the code I´m using is this:
from pytesser import *
import os
im = Image.open('/screenshot.png')
text = image_to_string(im)
print text
Thanks in advance!