How to solve this'OSError: [Errno 22] Invalid argument:'

username: Foolish
cooked: <p>When I build a deep learning image dataset and use Spyder to package it, the following error occurs, what should I do?</p>
<p>Traceback (most recent call last):</p>
<p>File “”, line 1, in <br>
runfile(‘D:/360Downloads/VS/1203_2.py’, wdir=‘D:/360Downloads/VS’)</p>
<p>File “C:\Users\16147\Anaconda3\envs\tensorflow\lib\site-packages\spyder_kernels\customize\spydercustomize.py”, line 827, in runfile<br>
execfile(filename, namespace)</p>
<p>File “C:\Users\16147\Anaconda3\envs\tensorflow\lib\site-packages\spyder_kernels\customize\spydercustomize.py”, line 110, in execfile<br>
exec(compile(f.read(), filename, ‘exec’), namespace)</p>
<p>File “D:/360Downloads/VS/1203_2.py”, line 93, in <br>
x_train, y_train,x_val,y_val=datacreate(root)</p>
<p>File “D:/360Downloads/VS/1203_2.py”, line 53, in datacreate<br>
for batch_index, batch in train_data:</p>
<p>File “D:/360Downloads/VS/1203_2.py”, line 37, in <strong>getitem</strong><br>
img = Image.open(root+fn).convert(‘L’).resize((image_size,image_size))</p>
<p>File “C:\Users\16147\Anaconda3\envs\tensorflow\lib\site-packages\PIL\Image.py”, line 2766, in open<br>
fp = builtins.open(filename, “rb”)</p>
<p>OSError: [Errno 22] Invalid argument: ‘C:/Users/16147/Desktop/ss/shuiguo2/C:/Users/16147/Desktop/ss/shuiguo2/01h.bmp’</p>

username: ptrblck
cooked: <p>It seems <code>fn</code> already contains the complete file path, so you might need to just pass <code>fn</code> to <code>Image.open</code> instead of <code>root+fn</code>.</p>

username: Foolish
cooked: <p>Thank you very much for your answer，i have solved.</p>

username: Fay_Cal
cooked: <p>hello sir i have the same problem and i cant solve it can u help me pleas ?</p>

username: ptrblck
cooked: <p>This error is raised, if you pass an invalid file path to a method which tries to open this file.<br>
Could you check the path and verify, that this file really exists in this location?</p>

username: Fay_Cal
cooked: <p>can you give me your mail i want to send you the code</p>

username: ptrblck
cooked: <p>Please post the code here by wrapping it into three backticks ```, so that we can have a look. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

username: Fay_Cal
cooked: <pre><code class="lang-auto">	def pushButtonOuvrirClicked(self):
		print("Bouton &lt;OUVRIR&gt; appuyé")
        if self.lineEditChemin.text()=="":
			self.filename=QFileDialog.getOpenFileName(self, 'Ouvrir fichier', os.getenv('HOME')) 
			
		else:
			info=QFileInfo(self.lineEditChemin.text()) 
			print (info.absoluteFilePath()) # debug	
			self.filename=QFileDialog.getOpenFileName(self, 'Ouvrir fichier', info.absoluteFilePath())
	
		
		print(self.filename)
		self.lineEditChemin.setText(self.filename[0]) 
		myFile=open(self.filename[1],'r')
		myFileContent=open(myFile) 
		myFile.close()
		
		self.textEdit.setText(myFileContent) 
</code></pre>
<p>and thi is the error<br>
(‘C:/Users/hp/Desktop/CNC Data/drawing GCODE/Lamborghini Avantador.gcode’, ‘All Files (<em>)’)<br>
Traceback (most recent call last):<br>
File “c:/Users/hp/Desktop/machine cnc/cnc pyqt5/FinalCodeGUIMain.py”, line 1959, in pushButtonOuvrirClicked<br>
myFile=open(self.filename[1],‘r’) # ouvre le fichier en lecture<br>
OSError: [Errno 22] Invalid argument: 'All Files (</em>)’</p>

username: ptrblck
cooked: <p>I think the usage of <code>self.filename[1]</code> might be wrong, as the <a href="https://doc.qt.io/qtforpython/PySide2/QtWidgets/QFileDialog.html#PySide2.QtWidgets.PySide2.QtWidgets.QFileDialog.getOpenFileName">Qt documentation</a> gives the return type as:</p>
<blockquote>
<p>(fileNames, selectedFilter)</p>
</blockquote>
<p>So I assume <code>self.filename[0]</code> will contain all file names, while <code>self.filename[1]</code> would contain the <code>selectedFilter</code> class, which would fit the error message:</p>
<blockquote>
<p>‘All Files ( )’</p>
</blockquote>

username: Fay_Cal
cooked: <p>that give me this error<br>
File “c:/Users/hp/Desktop/machine cnc/cnc pyqt5/FinalCodeGUIMain.py”, line 1960, in pushButtonOuvrirClicked<br>
myFileContent=open(myFile)<br>
TypeError: expected str, bytes or os.PathLike object, not _io.TextIOWrapper</p>

username: ptrblck
cooked: <p>I’m not deeply familiar with the Qt Python API, but it seems you would need to use the <code>self.filename[0].name</code> attribute.</p>
<p>PS: You might get a better and faster answer on StackOverflow or a Qt support forum, as these errors are unrelated to PyTorch. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

username: Fay_Cal
cooked: <p>ok thank you sir you helped me so much ^^</p>

username: Rasika_Pandit
cooked: <p>I have written a python code to upload file in sharepoint from local machine directory. It is working fine in local machine. When i try to upload any file from C drive directly of virtual machine to sharepoint, i am facing below error. But sharepoint is getting opened in virtual machine with my credentials. Can you let me know it is an operating system issue or as virtual machine has many users, there is some security concern.</p>
<pre><code class="lang-auto">from sharepoint import SharePointSite, basic_auth_opener
import subprocess
import shutil
server_url = "https://abc.sharepoint.com/"
site_url = server_url + "sites/Report/"
opener = basic_auth_opener(server_url, "email ID", "Password")
site = SharePointSite(site_url, opener)
subprocess.call(r'net use Y: https://abc.sharepoint.com/sites/Report/')
shutil.copy(r"C:/log.txt","Y:\\",follow_symlinks=True)
</code></pre>
<p>error is as under: File “C:\ProgramData\Anaconda3\lib\shutil.py”, line 121, in copyfile with open(dst, ‘wb’) as fdst:</p>
<p>FileNotFoundError: [Errno 2] No such file or directory: ‘Y:’</p>

username: ptrblck
cooked: <p>I would recommend to rather post these kind of questions on e.g. StackOverflow, as they are not PyTorch-specific and you’ll most likely get a faster and better answer. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

username: Rasika_Pandit
cooked: <p>Oh thanks ptrblck for the suggestion! <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"> i have already posted on Stackoverflow.</p>