PermissionError: [Errno 13] Permission denied on windows (pyinstaller) - python-3.x

I am creating an application in python (3.4) with tkinter and I am compiling it with pyinstaller. The code fragment that brings the error is this:
client = paramiko.SSHClient()
known_hosts = open(self.resource_path("known_hosts")) # Linea 73
client.load_host_keys(known_hosts)
The error is thrown when I click on a button that executes that part of the code, that is, the application runs rather well. The error is this:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1538, in __call__
File "prueba.py", line 73, in aceptar
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Hernan\\AppData\\Local\\Temp\\_MEI124282\\known_hosts'
I clarify that I am compiling it and running in windows 10.
I tried to execute the exe as administrator but still giving the same error. I verified the path of the file and it exists, so I discard that the file does not exist. I also tried to compile the exe in a cmd with administrator permissions, but it did not give me a solution either.
Any ideas ?
PD: add code...
def resource_path(self, relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)

Related

Two errors when trying to open firefox using selenium (Python); System cannot find the file specified; Geckodriver executable needs to be in PATH

import time
from selenium import webdriver
path = input("enter filepath: ")
driver = webdriver.Firefox(path)
driver.get("htpps://google.com")
This is the part of my code seemingly causing the error, I have been able to find any answers online. The code used to work when using r"c:\users\ellio\desktop\main" however this has since stopped working too, only without the top error. I have added the folder containg geckodriver to path and added the geckodriver exe to the same file as my code, but nothing seems to work.
Thanks in advance for any help.
Here are the errors
Traceback (most recent call last):
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\Users\ellio\Desktop\main\app.py", line 18, in <module>
driver = webdriver.Firefox(path)
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\ellio\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
give a specific path of your driver
from selenium import webdriver
driver = webdriver.Chrome('D:\\chrome\\chromedriver.exe') #give location of driver you download
driver.get('http://www.google.com/');
time.sleep(5)
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5)
driver.quit()

ValueError: root_directory must be an absolute path: Error when access directory in ADLS from Synapse Workspace

When trying to access ADLS directory with the following PySpark code in Apache Spark I get the error:
ValueError: root_directory must be an absolute path. Got abfss://root#adlspretbiukadlsdev.dfs.core.windows.net/RAW/LANDING/ instead.
Traceback (most recent call last):
File "/home/trusted-service-user/cluster-env/env/lib/python3.6/site-packages/great_expectations/core/usage_statistics/usage_statistics.py", line 262, in usage_statistics_wrapped_method
result = func(*args, **kwargs)
The code that gives the above error when I'm trying to access the directory is as follows:
data_context_config = DataContextConfig(
datasources={"my_spark_datasource": my_spark_datasource_config},
store_backend_defaults=FilesystemStoreBackendDefaults(root_directory='abfss://root#adlspretbiukadlsdev.dfs.core.windows.net/RAW/LANDING/'),
)
context = BaseDataContext(project_config=data_context_config)
When I change the code to
data_context_config = DataContextConfig(
datasources={"my_spark_datasource": my_spark_datasource_config},
store_backend_defaults=FilesystemStoreBackendDefaults(root_directory='/abfss://root#adlspretbiukadlsdev.dfs.core.windows.net/RAW/LANDING/'),
)
I get the following error message:
PermissionError: [Errno 13] Permission denied: '/abfss:'
Traceback (most recent call last):
When I enter the following code
data_context_config = DataContextConfig(
datasources={"my_spark_datasource": my_spark_datasource_config},
store_backend_defaults=FilesystemStoreBackendDefaults(root_directory='/'),
)
context = BaseDataContext(project_config=data_context_config)
I get the error message:
PermissionError: [Errno 13] Permission denied: '/expectations'
Traceback (most recent call last):
However, I don't have a directory called '/expectations
As a side note I'm trying to execute Great_Expectations.
The developers of Great_Expectations have informed me that this error will be fixed a new release of the Great_Expectations

I need to create a zip file using python. But unfortunately my code is not working.Is there any error on my part?

**So i wish to create a zip file named new.zip using python which also contains a text file called sample.txt. But after running the necessary code on my python editor i get the error as :
Traceback (most recent call last):
File "C:/Users/User/PycharmProjects/PYTHON_CODE/creatingZipFile.py", line 5, in
newZip.write('sample.txt', compress_type=zipfile.ZIP_DEFLATED)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\zipfile.py", line 1713, in write
zinfo = ZipInfo.from_file(filename, arcname)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\zipfile.py", line 506, in from_file
st = os.stat(filename)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'sample.txt'
My python code is as below :
import os, zipfile
os.chdir("F:\\")
newZip = zipfile.ZipFile('new.zip', 'a')
newZip.write('sample.txt', compress_type=zipfile.ZIP_DEFLATED)
newZip.close()
PLEASE SOMEONE HELP ME REGARDING THIS ISSUE.**
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'sample.txt'
will occur if the file is not present in the specified path, can you check if sample.txt is actually present in the path F:\sample.txt

Permission Error and unable to import PIL.image on jupyter

I have to apply this code for computer vision project https://www.quora.com/How-do-I-load-train-and-test-data-from-the-local-drive-for-a-deep-learning-Keras-model which is load train and test data from the local drive for Keras model.
I was tried but appears some errors such as:
PermissionError Traceback (most recent call last)
<ipython-input-10-3806351fb2b0> in <module>
14 for sample in train_batch:
15 img_path = train_path+sample
---> 16 x = image.load_img(img_path)
17 # preprocessing if required
18 x_train.append(x)
~\Anaconda3\lib\site-packages\keras_preprocessing\image\utils.py in load_img(path, grayscale, color_mode, target_size, interpolation)
108 raise ImportError('Could not import PIL.Image. '
109 'The use ofload_imgrequires PIL.')
--> 110 img = pil_image.open(path)
111 if color_mode == 'grayscale':
112 if img.mode != 'L':
~\Anaconda3\lib\site-packages\PIL\Image.py in open(fp, mode)
2768
2769 if filename:
-> 2770 fp = builtins.open(filename, "rb")
2771 exclusive_fp = True
2772
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\ASUS\\Desktop\\step2_dir/datasets/dataset/Alfalfa'
Note: I already sure about installed PIL successfully.
So, I need some help if anyone can try to apply the code and tell me how to fix the errors.
Thanks.
You don't have the permission to access the filepath:
PermissionError: [Errno 13] Permission denied:
C:\\Users\\ASUS\\Desktop\\step2_dir/datasets/dataset/Alfalfa
Easily solvable! Are you on Windows?
You most likely open jupyter notebook from a Powershell, you just have to open a shell with administrator rights (right-click on cmd and/or powershell --> Run as administrator).
If you are on a bash shell run jupyter notebook as a superuser, and you will have the permission needed:
sudo jupyter notebook

shutil.move conditional errors

I have a short python script (called VaultTransferScript.py) that should transfer a zip file from one machine to another. The destination machine is a mapped network-attached-storage machine, which I have assigned to be the Z: drive.
The script is:
import shutil
import os
from datetime import datetime
time_stamp = datetime.now().strftime('%Y-%m-%d_%H_%M')
title_str = 'VaultBackup.zip'
name = time_stamp + title_str
shutil.move('C:\\Users\\Hawking\\Desktop\\VaultBackups\\MyBackup.zip',
os.path.join('Z:\\VaultBackups\\'+name))
I can run this script from the notepad++ run facility, using
cmd /C python "$(FULL_CURRENT_PATH)"
But running it in a batch script as:
echo off
C:\Users\Hawking\AppData\Local\Programs\Python\Python37-32\python.exe C:\Users\Hawking\Desktop\VaultBackupTransfer.py
results in this:
C:\Users\Hawking\Desktop>echo off
Traceback (most recent call last):
File "C:\Users\Hawking\AppData\Local\Programs\Python\Python37-32\lib\shutil.py", line 557, in move
os.rename(src, real_dst)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\Users\\Hawking\\Desktop\\VaultBackups\\MyBackup.zip' -> 'Z:\\VaultBackups\\2018-09-21_14_30VaultBackup.zip'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Hawking\Desktop\VaultBackupTransfer.py", line 7, in <module>
shutil.move('C:\\Users\\Hawking\\Desktop\\VaultBackups\\MyBackup.zip', os.path.join('Z:\\VaultBackups\\'+name))
File "C:\Users\Hawking\AppData\Local\Programs\Python\Python37-32\lib\shutil.py", line 571, in move
copy_function(src, real_dst)
File "C:\Users\Hawking\AppData\Local\Programs\Python\Python37-32\lib\shutil.py", line 257, in copy2
copyfile(src, dst, follow_symlinks=follow_symlinks)
File "C:\Users\Hawking\AppData\Local\Programs\Python\Python37-32\lib\shutil.py", line 121, in copyfile
with open(dst, 'wb') as fdst:
FileNotFoundError: [Errno 2] No such file or directory: 'Z:\\VaultBackups\\2018-09-21_14_30VaultBackup.zip'
WHat is the difference in how I invoke the python script, and why does it error out from the batch script, but not notepad++?
You might be running the Python program with different user permissions in Notepad++ versus the command prompt. Alternatively, another Python VM might be used. Although, nothing in particular makes me think that the later is true.

Resources