FileNotFoundError Selenium Stealth Python - 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.

Related

How to add missing .dll files while preparing .exe file with pyinstaller

I have just prepared simple script importing some module and printing something:
from clicknium import clicknium as cc
print(cc.edge.browsers)
So I have created the venv, installed clicknium (pip3 install clicknium==0.1.9).
After that I have prepared spec file:
pyi-makespec spec_file_name script_name.py
After running the command with created .spec file:
pyinstaller spec_file_name.spec
The pyinstaller is creating the .exe file.
After running the .exe I got an error:
System.IO.FileNotFoundException: Unable to find assembly 'C:\Users\user_1\AppData\Local\Temp\_MEI197042\clicknium\.lib\automation\ClickniumJavaBridge-32.dll'
Of course I understand the error but I'm not sure how to fix it.
When I has some problems with missing files I have added it by using --add-data while making the spec file. But It's not working for me with .dll files.
clicknium==0.1.9
pyinstaller==5.4.1
Update
Right now I'm using velow command to create .spec file:
pyi-makespec --onefile --add-data="C:\Users\...\project_name\venv\Lib\site-packages\clicknium\.lib\automation\*;clicknium\.lib\automation" --name app app.py
The error above is fixed but there is something new.
The code below causes the error:
clr.AddReference(Apath)
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\user_1\AppData\Local\Temp\_MEIxxxxxx\clicknium\.lib\automation\ClickniumJavaBridge-32.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
So as I understand the .dll file is still not visible there and clicknium is still looking for the dll files in Temp files.
clicknium supplied package project/folder function, can generate the exe.
you can refer to this: https://www.clicknium.com/documents/tutorial/vscode/project_management
first, in vscode, run command "Clicknium: Create Project", you can select the current folder;
then, run command "Clicknium: Package Project", it will generate the exe file
Sometimes you have to add *.dll files to your build process in the *.spec file
Look here, there is a lot of discussion about it:
Bundling data files with PyInstaller (--onefile)
If it not work for you try using other options like one file:
pyi-makespec -F script_name.py spec_file_name
also the order need to be the script first
pyi-makespec script_name.py -n spec_file_name

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

Adding an individual file to PyInstaller

I'm attempting to use PyInstaller with pyarmor. I'm using pyarmors "super mode", which creates pytransform.pyd at the root of my module.
For the record, I'm not using a spec file, instead I'm doing it python with PyInstaller.__main__.run(args). Not sure if that makes any difference.
Directory structure:
c:/dist/
module/
*.py # Obfuscated code
data/
stuff.json
pytransform.pyd
I'm already using --add-data C:/dist/module;module and --add-data C:/dist/data;data to include most of the necessary files, however I'm struggling with pytransform.pyd.
If I use --add-data C:/dist/pytransform.pyd;pytransform.pyd, I get this error when running the built executable. It looks like it's assuming it's a directory.
pytransform.pyd\pytransform.pyd could not be extracted!
fopen: No such file or directory
If I use --add-binary C:/dist/pytransform.pyd;pytransform.pyd, I get this error when building:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Peter\\AppData\\Roaming\\pyinstaller\\bincache00_py37_64bit\\pytransform.pyd\\pytransform.pyd'
I checked the bincache folder, and it actually contains pytransform.pyd, so it's halfway there.
How can I add just a single file to the executable?
It worked when adding it as a hidden import, using --hidden-import=pytransform.
I would still be interested knowing why the --add-data and --add-binary didn't work though.

cx-freeze PermissionError: [Errno 13] Permission denied

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.

Creating Python Tkinter exe file with Pyinstaller problem

I have created GUI python2.7 program with Tkinter successfully without error. Now I want to make an executable file of it using pyinstaller in anaconda environment (I'm using windows 10).
Using this command
pyinstaller --onefile main.py I am able to create exe file successfully in dist folder. But when I tried to run the exe file, it showed error :
Traceback (most recent call last):
File "main.py", line 333, in <module>
File "main.py", line 90, in __init__
File "lib-tk\ttk.py", line 715, in current
_tkinter.TclError: Index 0 out of range
[22668] Failed to execute script main
Is the problem related to tkinter? I've tried the solution here : Problems with Pyinstaller with tkinter app on python 3.5 and here : How to make pyinstaller import the ttk theme? . But still same error
Try and do:
pyinstaller --onefile -w main.py
The -w flag stops python from bringing up the console, and so this could be why tkinter is failing.
Source:
This cool video
I highly recommend you watch this video as it also goes a little in depth on how to clean up after building the exe.
I used pyinstaller to create single exe file for a tkinter project, which contained several py files:
Main.py is my main python file which calls tkinter UI and I had several other python files imported to this Main.py.
Some libraries which I used include pandas,pyodbc
Open cmd in the same directory of the project; Use following command:
pyinstaller --noconfirm --onedir --windowed --icon=XYZ.ico "C:/Users/.../Tkinter_Project/Main.py"
Application was created with no dependencies. If there is any config or image files used, simply copy paste it to the 'dist' folder which gets created.

Categories