cx-freeze PermissionError: [Errno 13] Permission denied - python

I am attempting to use cx_Freeze as an alternative to my usual application for converting .py to .exe (auto-py-to-exe). When I run it in cmd I get:
C:\WINDOWS\system32>cxfreeze-quickstart
Project name: FE
Version [1.0]: 1.0
Description: File Edit and more!!!
Python file to make executable from: File Create.py
Executable file name [File Create]: FileCreateExe
(C)onsole application, (G)UI application, or (S)ervice [C]: C
Save setup script to [setup.py]: C:\Users\tom\Documents\python\_Thiswill createfiles_
Overwrite C:\Users\tom\Documents\python\_Thiswillcreatefiles_ [n]? yes
Traceback (most recent call last):
File "c:\users\tom\appdata\local\programs\python\python38-32\lib\runpy.py", line 193, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\tom\appdata\local\programs\python\python38-32\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "C:\Users\tom\AppData\Local\Programs\Python\Python38-32\scripts\cxfreeze-quickstart.exe\__main__.py", line 7, in <module>
File "c:\users\tom\appdata\local\programs\python\python38-32\lib\site-packages\cx_Freeze\setupwriter.py", line 101, in main
writer.Write()
File "c:\users\tom\appdata\local\programs\python\python38-32\lib\site-packages\cx_Freeze\setupwriter.py", line 64, in Write
output = open(self.setupFileName, "w")
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\tom\\Documents\\python\\_This will create files_'
As you can see I am running my command prompt as administrator since I got the same error when running it normally. What can I do to fix this error? PermissionError: [Errno 13] Permission denied: 'C:\\Users\\tom\\Documents\\python\\_This will create files_'. I can not find any other sites that explain how to fix this. Why does this error occur? Please can I have some help... 😁😁😁

dude you are running the command from system32
cd to another directory using this command and try again
cd C:/Users/<your name>/Documents
if this doesnt work go here

Step 1: Add Python to Windows Path
Step 2: Open the Windows Command Prompt as administrator
Step 3: Install the Pyinstaller Package
In the Windows Command Prompt, type the following command to install the pyinstaller package (and then press Enter):
pip install pyinstaller
Step 4: Save your Python Script
I then saved the Python script in the following folder:
C:\Users\Ron\Desktop\MyPython
Where I named the Python script as ‘hello’
Step 5: Create the Executable using Pyinstaller
Now you’ll be able to create the executable from the Python script using pyinstaller.
Simply go to the Command Prompt, and then type:
cd followed by the location where your Python script is stored
In my case, I typed the following in the command prompt:
cd C:\Users\Ron\Desktop\MyPython
Next, use the following template to create the executable:
pyinstaller --onefile pythonScriptName.py
Since in our example, the pythonScriptName is ‘hello‘, then the command to create the executable is:
pyinstaller --onefile hello.py
Once you’re done, press Enter for the last time.
Step 6: Run the Executable
Your executable should now get created at the location that you specified.
In my case, I went back to the location where I originally stored the ‘hello’ script
(C:\Users\Ron\Desktop\MyPython).
Few additional files got created at that location. To find the executable file, open the dist folder:
Now I hope that solves the question..

Read this doc. Create a setup.py file in your project directory and copy the content from the docs into it.
Modify it as necessary, then run python setup.py build inside your project directory.

Related

FileNotFoundError Selenium Stealth Python

I am running selenium-stealth in Python 3.9.3 on MacOS.
When I build to an app using PyInstaller (
pyinstaller --noconfirm --onefile --console --hidden-import "cmath" "/Users/name/Downloads/AmazonSellerCentral/main.py") I get the following error:
Traceback (most recent call last):
File "main.py", line 141, in <module>
File "main.py", line 77, in create_driver
File "selenium_stealth/__init__.py", line 45, in stealth
File "selenium_stealth/utils.py", line 8, in with_utils
File "pathlib.py", line 1255, in read_text
File "pathlib.py", line 1241, in open
File "pathlib.py", line 1109, in _opener
FileNotFoundError: [Errno 2] No such file or directory: '/var/folders/7z/3spcsmdx5n344dh0fb5j0hl40000gn/T/_MEIqfmicz/selenium_stealth/js/utils.js'
.
However, simply running python3 main.py works fine.
Reinstalling selenium-stealth did nothing, I'm unsure what I can try to fix/change from here?
quick turnaround (for issue pls refer to my comment in comments section):
step 1: build the package , refer the command in code section)
step 2: create folder --> dist\your package(in my case slhpackage)\selenium_stealth\js
step 3- copy the js files from https://github.com/diprajpatra/selenium-stealth/tree/main/selenium_stealth/js and put it in folder created in step 2.
and now your executable should run fine.
pyinstaller slhpackage.py # build package (1)
#Python version ==> Python: 3.9.2 (conda)
I used Python 3.9 and encountered the same issue today. As #simpleApp said, I followed the same with least number of modifications and it works for me as of now.
Follow below given steps:
Make sure you that you copy all the files from this link.
Paste all the files in folder_name(might be anthing you wish)/selenium_stealth/js.
[Make sure you that you keep the names selenium_stealth/js with no modifications at any cost, else you'll face conflicts.]
Then run the executable command with the folder_name added.
For convenience, I'm adding it here so that it'd be easier not only for you, but for everyone who uses it.
pyinstaller --noconfirm --onefile --console --icon "dir:\path\to\icon.ico" --add-data "dir:\path\to\folder_name\mentioned\above;." --add-binary "dir:/path/to/chromedriver/chromedriver.exe;./selenium/webdriver" "dir:/path/to/your/python/file.py"
Copy the code, modify it based on your file paths (I've given generic names).
I'd recommend you to make a .bat file for paste the code in it for future use.
Here's the snippet of my code:
#ECHO OFF
color 09
echo Immediate direct Conversion of .py to .exe standalone by PiXinCreate
echo.
pyinstaller --noconfirm --onefile --console --icon "dir:\path\to\icon.ico" --add-data "dir:\path\to\folder_name\mentioned\above;." --add-binary "dir:/path/to/chromedriver/chromedriver.exe;./selenium/webdriver" "dir:/path/to/your/python/file.py"
echo.
echo .exe has been successfully created for .py
echo.
pause.
exit
My code actually creates a onefile, which is standalone executable, in the terminal window.
You can remove the icon part if not needed.
Feel free to revert back if anything goes wrong.
The error that you're getting indicates that maybe something is wrong with the path of the file.
Make sure that the file utils.js exists at the path where it's trying to be located.
If not you could try to download it externally and placing it inside that path. I don't think that would be a good recommendation though.
first remove --onefile from the command and build the app, after building you would find selenium-stealth folder inside of the folder that apeared after build,put this folder(js) inside of selenium-stealth and run the app.
i was looking for solution and it worked for me.

How to make an executable file?

Code for the background image of the GUI :
bg = PhotoImage(file='images/all_button.png')
lbl_bg = Label(root, image=bg)
lbl_bg.place(x=0, y=0, relwidth=1, relheight=1)
Error
Traceback (most recent call last):
File "finalbilling.py", line 14, in <module>
File "tkinter\__init__.py", line 4061, in __init__
File "tkinter\__init__.py", line 4006, in __init__
_tkinter.TclError: couldn't open "images/all_button.png": no such file or directory
[7912] Failed to execute script finalbilling
There are many ways in which you can convert it into an executable program.
But one such easy way is to use pyinstaller.
Firstly, download a module named pyinstaller by entering the below code into your console:
pip install pyinstaller
Then, open the folder in which you have kept your program with console.
In windows, you can go to the folder and press shift key and right click to get the option to open with powershell.
In Mac, you can head to the folder > Right click on the folder > Click New Terminal at folder.
Then in the terminal you can either:
pyinstaller (name of your file).py
In this one you will get many other files associated with your executable program.
Don't try to delete those files else your executable file may get affected.
Instead, try the below one to get only one executable file.
pyinstaller --onefile (name of file).py
You can get the executable program into dist folder of the folder you opened into console.
And then you can convert it to zip and send others.
If you are getting any type of errors like:
No such file or directory [7912] Failed to execute script finalbilling
Then there might be an issue with your script or while opening or importing any file an error occurred.
As the same happened with me and after resolving the issue in script it worked.
So, try to resolve the issue in script and then try the above steps it will definitely work.
You can convert the python script to a standalone executable with all its dependencies included using different python packages. One such package is pyinstaller which can be used to create executable for Windows, Mac OS X, or GNU/Linux. pyinstaller
pip install pyinstaller
pyinstaller --onefile main.py
OR
pyinstaller --onefile -w main.py # (will not work for console app)
-w means not to open CMD

No such file or directory on Mac terminal for python

hello.py is my first python program. It is saved on my desktop.
In the terminal I write in front of
user#AA-MacBook-Air ~ % python3 hello.py
The error is
can't open file 'hello.py': [Errno 2] No such file or directory
Kindly help me understand the problem and solve it.
In the terminal you are currently in the directory ~. This signifies the folder /Users/<username>. Your script is on your desktop.
Type cd Desktop to change to /Users/<username>/Desktop and then run python3 hello.py.
you first need to change destination with cd
The error message, No such file or directory pretty much gives the explanation. Check if the file hello.py is present in the correct working directory. This can done graphically or using the ls command. If it is not present, copy the file the to the directory or navigate to the location of the file hello.py in terminal using cd.

Running python programmes for the command line

I am trying to run a python programme called helloWorld.py from the command line on MacOS.
I am typing into bash:
Ryans-MacBook-Air:~ ryanunderwood$ python3 helloWorld.py
But I am getting the following:
/Library/Frameworks/Python.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'helloWorld.py': [Errno 2] No such file or directory
There is definitely a file with this name in the directory. Why is this programme not running?
Try ./helloworld.py or python3. /hello World.py
And make sure you have the right permissions

No such file or directory - Python

ANSWERED! THANKS EVERYONE!
I'm trying to get my script to run, however I'm getting this error. I'm not brilliant with Python, so any form of basic explanation would be appreciated.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Brad>c:\python27\python.exe c:\python27\vsauce.py
ERROR:root:Error opening settings.json.
Traceback (most recent call last):
File "c:\python27\vsauce.py", line 76, in loadSettings
settingsFile = open("settings.json", "r")
IOError: [Errno 2] No such file or directory: 'settings.json'
The line in question
settingsFile = open("settings.json", "r")
Yes, the file exists. Yes, it is named "settings.json" exactly. I can't for the life of me figure out what the hell I have done wrong. This is not my script by the way.
Thanks in advance for any help!
try
$ cd C:\Python27
$ python.exe vsauce.py
this will move you to Python27 directory. so it will look there for settings.json
since you ran it from C:\Users\Brad it was looking for C:\Users\Brad\settings.json
The reason your script isn't working is because you're running it from C:\Users\Brad, so when
settingsFile = open("settings.json", "r")
runs, it looks for settings.json in the directory the script was run from, not the directory the script is stored in. You either need to hardcode the path the settings.json in your .py file, or you need to run the script from the C:\Python27 directory. To do this, after starting cmd.exe, enter
cd c:\Python27
python vsauce.py
Try opening while writing out the full directory. It may be that your current working directory is not the same as where the file is. By default when you use "open" python looks for files wherever you ran the program from. Such as 'C:\Users\Brad... whatever'. You need to change the directory if the file is saved elsewhere
settingsFile = open('C:\\Users\\Brad\\Documents\\PythonFiles\\YourDirectory\\settings.json', 'r')

Categories