This is a simple copy file problem and I came here with my solution. There are some questions in Stackoverflow that are not closed as my problem. That's why I opened this.
Explanation:
Python gives errors while copying files, in my case I tried to copy the image data set to another file(318MB). Python gives these errors in random sequence.
Data Set: Data
Python Version: 3.8.13
IDE: VSCode
Code and Error Message:
for jpgfile in glob.iglob(os.path.join(imageData, "*.jpeg")):
shutil.copy(jpgfile, dst_dir)
C:/Users/user1/Desktop/imageData Traceback (most recent call last):
File "c:\Users\user1\Desktop\copyImageJPEG.py", line 35, in
shutil.copy(jpgfile, dst_dir) File "C:\Users\user1\AppData\Local\Programs\Python\Python38\lib\shutil.py",
line 418, in copy
copyfile(src, dst, follow_symlinks=follow_symlinks) File "C:\Users\user1\AppData\Local\Programs\Python\Python38\lib\shutil.py",
line 264, in copyfile
with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst: PermissionError: [Errno 13] Permission denied:
'C:/Users/user1/Desktop/copyFolder\person110_virus_207.jpeg'
What I've done till now,
Gave permission access with chmod
Tried to copy , copyFile, copy2 functions
Also this ref.
Wrote full path for both source and destination
Encoded the path for both source and destination
Run the python code as Admin
Also this ref.
r-prefix
Those solutions did not work for my problem. For those who can't find a solution like me, here is another solution:
Just close the copyFolder, don't disrupt it. In my case, I got the error while trying to see the last copied image, so the error popped up 50th, 100th, 150th, etc., depending on my check time.
Somehow the operating system blocks the code while we are using the folder.
I will update this post if I get another solution or the real reason for this disruption.
Edit: #Barmar Windows locks files while they're open in an editor. You get an error if you try to overwrite the locked file.
Related
I started by making a text file (requirements.txt) with all the versions of the libraries used in the code. So I opened a folder on GitHub and added all the necessary files.
I used Streamlit Sharing to deploy and it returned the following error:
File "/home/appuser/venv/lib/python3.7/site-packages/streamlit/script_runner.py", line 379, in _run_script
exec(code, module.__dict__)
File "/app/orbitas-relativistics/webapp.py", line 15, in <module>
image1 = Image.open(r'C:/Users/isabe/.streamlit/titulo11.png')
File "/home/appuser/venv/lib/python3.7/site-packages/PIL/Image.py", line 2953, in open
fp = builtins.open(filename, "rb")
My code doesn't have the command fp = builtins.open(filename, "rb") and it doesn't even have 2953 lines. It only has 395.
About the images, I uploaded them inside the .streamlit folder of my Visual Studio Code (where the code is hosted). And it gives the error
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/isabe/.streamlit/titulo11.png'
Does anyone know what I should do to fix this error and proceed with the deployment of my site?
Thanks for any help.
In general, referring to exact filenames isn't a good idea when deploying, as it's almost certain that the machine you deploy on will have different drive mappings than your development machine.
In this case, you are using a Windows filepath and Streamlit Cloud is a Debian image. Based on your Git link, your file is located in the root directory, so you can specify image1 = Image.open('titulo11.png') and it will work on Streamlit Cloud (though it may not work on your development machine).
To make your code work on both machines, I suggest using something like pathlib to programmatically determine where a file is located, instead of having to inspect what level of file directory it might be in.
i am using the cubemos skeleton tracking Api (using for extract skeleton keypoints from pictures and videos).
i have a very weird problem:
everything was working fine, until one day, i received this error (also added image):
Traceback (most recent call last):
File "C:/Users/omria/PycharmProjects/skeletonTracking/skeletonTracking.py", line 3, in <module>
from cubemos.skeleton_tracking.nativewrapper import Api, SkeletonKeypoints
File "C:\Users\omria\PycharmProjects\skeletonTracking\venv\lib\site-packages\cubemos\skeleton_tracking\__init__.py", line 1, in <module>
from .nativewrapper import *
File "C:\Users\omria\PycharmProjects\skeletonTracking\venv\lib\site-packages\cubemos\skeleton_tracking\nativewrapper.py", line 28, in <module>
os.path.join(cubemos_dir, "bin", "cubemos_skeleton_tracking.dll")
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\ctypes\__init__.py", line 364, in __init__
self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found
enter image description here
and line 3 is when i'm importing the library:
from cubemos.skeleton_tracking.nativewrapper import Api
another weird thing, is that the problem was fixed randomly without me doing anything, and then it returned again!
i tried reinstalling the cubemos SDK, rebooting the computer, debug, and i really don't know what is the source of this problem.
it seems like its some problem with my OS (i have windows 10, and using python 3.7 and VENV and PIP for the project)
i tried to figure out if the path is the problem, but again, it was working before, and i can't really tell if that is the problem. what do you think is causing this?
i will appreciate any help.
thanks !
I had the same problem using a conda env. Demos worked but not the python sample. I explicitly added %CUBEMOS_SKEL_SDK%\bin to my Path environment since I had nothing before. That got it going. The %CUBEMOS_SKEL_SDK% was set up okay from the start.
I am trying to run a python file. But i got this error.
Traceback (most recent call last):
File "modeltraining.py", line 29, in <module>
sr,audio = read(source + path)
File "C:\Users\RAAM COMPUTERS\Anaconda3\lib\site-packages\scipy\io\wavfile.py", line 233, in read
fid = open(filename, 'rb')
PermissionError: [Errno 13] Permission denied: 'development_set/'
Run Spyder as administrator
Right click --> run as administrator
Or may be you can change the permissions of the directory you want to save to so that all users have read and write permissions.
After some time relaunching Anaconda and Spyder, I got an alert from Avast antivirus about protecting me from a malicious file, the one I was trying to create.
After allowing it, the "[Errno 13] Permission denied" error disappeared.
In my case, it seem the cause of the problem was Avast locking the directory.
numpy.save(array, path) worked fine, but PIL.Image().save(path) was blocked.
I am completely late to the party, but here is a tip for someone who tried everything and it didn't work.
In Spyder go to python->PYTHONPATH manager and add path to the folder with your data there.
Worked for me
I had the permission error when accessing a file on an external card. I guess the error has nothing to do with anaconda, that is just accidentally in the traceback.
Traceback (most recent call last):
File "C:\Users\Admin\anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3343, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-2-219c041de52a>", line 105, in <module>
bs = open(filename, 'rb').read()
PermissionError: [Errno 13] Permission denied: 'D:\\[MYFILEPATH]\\test.bson'
I have checked this error in Spyder and PyCharm, it seems to be independent from the IDE. As the (Windows) solutions here (run as admin, add pythonpath) could not help me, my workaround was to copy the directory to my local disk and work from there.
Later I realised that it is obviously just the one file that is accessed ant that throws the permission that needs to be copied to your local disk, while you can use all your codework on externally.
Example:
Error. Get the permission error by accessing external drive "D:\":
filename = "D:\\test.bson"
# This throws the permission error
bs = open(filename, 'rb').read()
Solution. Avoid the permission error by accessing local drive "C:\":
filename = "C:\\Users\\Admin\\Documents\\test.bson"
# This throws no permission error
bs = open(filename, 'rb').read()
The whole code can now be saved on external "D:\test.py".
It might be the Windows Defender Firewall which was also mentioned when I installed PyCharm (and needed some automatic configurations which also did not solve the issue, but could be linked with it). It is clearly a problem of access rights, the firewall as the cause is quite plausible. Perhaps someone else finds out more about this.
I have a python script that builds a file by searching through folders and pulling in a list of files. This file runs fine and works as expected when I open and run it in IDLE, but if when I run the script in a commandline window I get this error:
C:\Windows\system32>python "C:\Users\ntreanor\Documents\RV Scripts\Server RV Sequence.py"
Traceback (most recent call last):
File "C:\Users\ntreanor\Documents\RV Scripts\Server RV Sequence.py", line 69,
in <module>
for foldername in os.listdir(pngFolders):
WindowsError: [Error 3] The system cannot find the path specified:
'Y:/20_temp_script_testing/pr126 movs\\04_comp_pngs/*.*'
In case it's not obvious, yes the path does exist. It not only works in IDLE but I double checked and the path definitely exists.
I also tried to create folders with a script that runs as a daemon and got a similar result
Traceback (most recent call last):
File "D:\shotgun\shotgunEventDaemon.py", line 888, in process
self._callback(self._shotgun, self._logger, event, self._args)
File "D:\shotgun\plugins\CreateAssetFolders.py", line 72, in createAssetFolders
os.makedirs(folder)
File "D:\Python27\Lib\os.py", line 150, in makedirs
makedirs(head, mode)
File "D:\Python27\Lib\os.py", line 150, in makedirs
makedirs(head, mode)
File "D:\Python27\Lib\os.py", line 150, in makedirs
makedirs(head, mode)
File "D:\Python27\Lib\os.py", line 157, in makedirs
mkdir(name, mode)
WindowsError: [Error 3] The system cannot find the path specified: 'Y:/'
This is what the script logged as a folder right before that:
Making folder:
Y:/07_design/04_environmental_elements\eec005-08_insect_ladybird_red_7_spots_wide
(the reason it's saying Y and not the whole path is that it attempts to make each folder back until it can't go back any further and that's when the exception is thrown)
Are the environment variables of the commandline window somehow affecting the drive mapping that should be pointing the script to the right location?
The issue is likely because IDLE and your command line are running with a different level of privileges. Mapped network drives are not automatically available to all user contexts. There is a superuser question on this here and plenty of other resources cover this topic. In short, the mapped network drive is only available to programs running at the level the mapping was made at.
If you have mapped the network drive through the windows UI, then it will be mapped for un-elevated programs. However if it was mapped with net use then it depends on the level of the command prompt when the mapping was made!
Disabling UAC will also affect change this behaviour, as will use of an elevated (or not) command prompt, which may explain why some PCs display different behaviour.
I think your problem is that you're trying to open the * file, which of course doesn't exist. open(path) takes path as a literal string and doesn't translate it in anyway, so it expects that value to be a valid filename. You should change your code to get a directory instead of a file, and then walking that directory.
I want to copy folder from my local server on my computer, using function shutil.copytree, i using macOS, but today i have problem,python always show me the same message,"[error 1] operation not permitted",but yesterday mine script work without problems with same folders...
Can someone tell me whats is the problem, what could have happened?
The reason of 'operation not permitted' error can be the fact that shutil.copytree (as well as shutil.copy and shutil.copy2) has some weird behavior when the source and destination are on different filesystems.
E.g. I had problems with shutil.copy while trying to copy a file from ext3 to ntfs volume on ubuntu using python2.7. I've just used shutil.copyfile instead.
Speaking about shutil.copytree: take a look at this answer, I like it - just write your own copytree.
You are trying to copy over an existing directory is my guess.
From the documentation
shutil.copytree = copytree(src, dst, symlinks=False, ignore=None)
Recursively copy a directory tree using copy2().
The destination directory must not already exist.
Note that last line.
I don't have a MAC OS machine to verify, but I'm guessing that the destination directory exists. Here is what happens on my Linux machine which gives a similar error
$ mkdir test1
$ touch test1/a
$ touch test1/b
Then in the interactive interpreter
>>> from shutil import copytree
>>> copytree("test1","test2")
>>> copytree("test1","test2")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/shutil.py", line 175, in copytree
os.makedirs(dst)
File "/usr/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 17] File exists: 'test2'
The error code is telling you that you don't have the permission to either read the source or write to the destination. Did the permission settings of your files and folders change?