Python Forum
Can anyone help me successfully run this code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can anyone help me successfully run this code?
#1
Sad 
OK, so I'm a TOTAL newbie to Python, & I hope this is the only time I will ever have to use it! But in any case, this is my dilemma...

(Oh, an important note: I fear that listing the whole input codes for every article will make the post difficult to read, so if any of you would like screencaps of the code inputs & results instead, please let me know.)

To begin, I am running Python 3.11 on Windows 10. I wish to execute the Python 3.11 program in CMD Prompt so that I may run my .py file "the-great-suspender-restore-urls", which will help to, well, restore the broken Great Suspender links in my saved Chrome session (named tabs.json) by changing them all back to their actual URLs. (There's another list of broken links I want to restore, but the same answers will apply, so it's redundant & not in need of posting.) The commands I need to run this Python script are as follows:

C:\Users>cd Desktop\the-great-suspender-restore-urls-0.4

C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4>python thegreatsuspender.py

restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs-restored.json
As I have been directed by another Python user, I have both the G.S.R.U. Python script & the Tabs JSON file(s) that needs fixing in the same folder (which is highlighted in blue in the picture below). After that, I changed the Path user variable by putting the link to the aforementioned folder as its value. I also changed the Path system variable value to the folder where my Python program is (highlighted in faint gray).

[Image: EIXQP.png]

So, it seems like everything should work out perfectly from this point on, right? WRONG! For as soon as I told CMD Prompt to do the second & third of the three commands listed above, I got this instead:

C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4>python thegreatsuspender.py
usage: thegreatsuspender.py [-h] --in-file IN_FILE --out-file OUT_FILE [--session-name-suffix SESSION_NAME_SUFFIX]
                            [--extension-id EXTENSION_ID] [--verbose]
Error:
thegreatsuspender.py: error: the following arguments are required: --in-file, --out-file
C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4>restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs-restored.json
Error:
'restore-the-great-suspender-urls' is not recognized as an internal or external command, operable program or batch file.
So, how am I supposed to overcome THIS hurdle? All I wanna do is just run this freaking Python script to restore my broken Great Suspender URLS:

restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs-restored.json
I've been trying to accomplish this task for over a month, & I'm really getting frustrated & desperate. :-(

---

Additional attempts I've made thus far:

Attempt 1: I tried saying in respective order:

python restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs-restored.json

python restore-the-great-suspender-urls --in-file=./tabs.json --out-file=./tabs-restored.json
Outcome: I got this message instead.

Error:
C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4> python restore-the-great-suspender-urls --in-file=./tabs.json --out-file=./tabs-restored.json python: can't open file C:\\Users\\User\\Desktop\\the-great-suspender-restore-urls-0.4\\restore-the-great-suspender-urls': [Errno 2] No such file or directory
Attempt 2: Added the .py extension to the name of the script I wanted to run, but got almost the exact same message as above.

Attempt 3: Simply typed in "restore-the-great-suspender-urls.py". That only gave me this output:
Error:
The system cannot find the file specified.
OK, just so we're on the up & up: I linked environmental variable paths to the respective locations of my Python program & the Python script I want to run to restore my broken Great Suspender URLs. I can get Python itself to be recognized & used by Command Prompt, but any commands involving my Great Suspender Restore URLs are totally bust.

Attempt 4: I checked the (first) tabs.json file & G.S.R.U. Python script, & both were spelled correctly. Nothing still happened.

Attempt 5: I tried to navigate to the directory via CMD, run "dir", & post the output. This is the output I got:

Error:
Directory of C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4 05/20/2023 10:28 AM <DIR> . ///// 05/20/2023 10:28 AM <DIR> .. ///// 02/09/2021 06:22 PM 833 CHANGELOG.rst ///// 02/04/2021 05:04 PM 1,073 LICENSE ///// 02/04/2021 07:26 PM 107 MANIFEST.in ///// 02/09/2021 06:31 PM 6,306 PKG-INFO 02/09/2021 06:26 PM 4,082 README.rst ///// 02/09/2021 06:31 PM 53 setup.cfg ///// 02/09/2021 06:21 PM 1,810 setup.py ///// 04/07/2023 01:46 PM 4,048,672 tabs.json ///// 02/09/2021 06:31 PM 40,960 the-great-suspender-restore-urls-0.4.tar ///// 02/09/2021 06:21 PM 5,978 thegreatsuspender.py ///// 05/20/2023 10:28 AM <DIR> the_great_suspender_restore_urls.egg-info
Attempt 6: I checked to see if PIP was installed, & if the G.R.S.U. Python package was also installed. Both were positive! ^_^ All I had to do then, was navigate to the Desktop directory with my tabs JSON file(s) & GRSU script, & run the command:

C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4> python thegreatsuspender.py
usage: thegreatsuspender.py [-h] --in-file IN_FILE --out-file OUT_FILE [--session-name-suffix SESSION_NAME_SUFFIX]
                            [--extension-id EXTENSION_ID] [--verbose]
Still didn't work. Result was this:

Error:
python thegreatsuspender.py: error: the following arguments are required: --in-file, --out-file
Attempt 7: Apparently, the problem with the last attempt was that I was running the command one at a time, instead of as a part of the application. So just running --in-file for instance, had no effect, because the system knows nothing about a command named --in-file. What I needed to do was run the following command, all in one line, in the directory where my tabs JSON files were:

restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs-restored.json
Then came this problem:

İmage


Attempt 8: The application threw the previous error, because it was basically trying to parse the data in a way that it couldn't. Thus, at an acquaintance's suggestion, I tried converting the tabs JSON file first in Notepad++, changing the encoding style from UTF-8-BOM to UTF. I saved, closed, & reopened the tabs JSON file to check if its encoding had successfully converted. Upon seeing that it did, I copied & pasted the new tabs JSON file into my tabs directory. Then, with a little help from Google, I found & subsequently saved all of the right input codes I needed to finally run the command! ^_^

The initial input codes:
restore-the-great-suspender-urls \
    --in-file=tabs.json \
    --out-file=tabs-restored.json \
    --extension-id='ahmkjjgdligadogjedmnogbpbcpofeeo' \
    --verbose
The input codes formatted for CMD:
usage: thegreatsuspender.py [-restore-the-great-suspender-urls] --in-file=tabs.json --out-file=tabs-restored.json [--session-name-suffix=' - FIXED']
                            [ --extension-id='ahmkjjgdligadogjedmnogbpbcpofeeo'] [--verbose]
With that, I put the final codes into CMD...& then came this freaking problem!

C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4>	--in-file=tabs.json \
Error:
'--in-file' is not recognized as an internal or external command, operable program or batch file.
C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4>	--out-file=tabs-restored.json \
Error:
'--out-file' is not recognized as an internal or external command, operable program or batch file.
C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4>	--extension-id='ahmkjjgdligadogjedmnogbpbcpofeeo' \
Error:
'--extension-id' is not recognized as an internal or external command, operable program or batch file.
C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4>	--verbose
Error:
'--verbose' is not recognized as an internal or external command, operable program or batch file.
Attempt 9: I typed in the input codes all in one line, & that also failed.

And that's where I'm stuck right now. So, I need to know the proper answers to the following questions:
1. What exactly am I doing wrong? What mistakes did I make, if any?
2. What are the complete steps I should take in order to get the code to finally run?
3. How exactly should I format the final code in CMD?

Please, please help me out! I don't wanna have to keep trying & failing to restore my broken tab URLs ad nauseum... :-(
Reply
#2
Always better to walk before you try to run!

Can you run something simple?

Something like print('Hello World my Baby!')

Does what you want to run work in your Python shell?
Gribouillis likes this post
Reply
#3
1. install the-great-suspender-restore-urls by typing pip install the-great-suspender-restore-urls in the CMD

2. run restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs-restored.json
tabs.json must be in the current working directory or supply the full path

It is all described in the docs
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
1. So, if I change the directory to C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4, which is where the tabs file(s) & Python script are both located...it should finally work?

2. But what about my changes to the environment variable paths I showed in my first picture? Were they made correctly, or do I need to start over?

3. Also, the name of the Python script in my folder is "thegreatsuspender", NOT "restore-the-great-suspender-urls". Do I need to change the script file name to match the command, or leave it as is?
Reply
#5
(Jun-20-2023, 12:14 PM)buran Wrote: 1. install the-great-suspender-restore-urls by typing pip install the-great-suspender-restore-urls in the CMD

2. run restore-the-great-suspender-urls --in-file=tabs.json --out-file=tabs-restored.json
tabs.json must be in the current working directory or supply the full path

It is all described in the docs

1. So, if I change the directory to C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4, which is where the tabs file(s) & Python script are both located...it should finally work?

2. But what about my changes to the environment variable paths I showed in my first picture? Were they made correctly, or do I need to start over?

3. Also, the name of the Python script in my folder is "thegreatsuspender", NOT "restore-the-great-suspender-urls". Do I need to change the script file name to match the command, or leave it as is?
Reply
#6
(Jun-21-2023, 02:41 PM)TheMouseAvenger Wrote: 2. But what about my changes to the environment variable paths I showed in my first picture? Were they made correctly, or do I need to start over?
Just need to add Scripts folder (where pip.exe is) in System Variables.
C:\Users\User\AppData\Local\Programs\Python\Python311
C:\Users\User\AppData\Local\Programs\Python\Python311\Scripts
It easier if you make folder that has shorther Path eg C:\div_code.
Here a quick run with virtual enviromnet,and rember restore-the-great-suspender-urls it's a command line tool.
So now need to run it with python.
G:\div_code
λ python -V
Python 3.11.3

G:\div_code
λ pip -V
pip 23.1.2 from C:\python311\Lib\site-packages\pip (python 3.11)

# Make enviroment
G:\div_code
λ python -m venv suspender_env

G:\div_code
λ cd suspender_env\

G:\div_code\suspender_env
λ G:\div_code\suspender_env\Scripts\activate.bat

# Install
(suspender_env) G:\div_code\suspender_env
λ pip install the-great-suspender-restore-urls
Collecting the-great-suspender-restore-urls
  Downloading the_great_suspender_restore_urls-0.4-py3-none-any.whl (5.8 kB)
Installing collected packages: the-great-suspender-restore-urls
Successfully installed the-great-suspender-restore-urls-0.4

# As it's a command line tool --help will work
(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --help
usage: restore-the-great-suspender-urls [-h] --in-file IN_FILE --out-file OUT_FILE [--session-name-suffix SESSION_NAME_SUFFIX]
                                        [--extension-id EXTENSION_ID] [--verbose]

Restore the broken URLs of the Great Suspender browser extension

options:
  -h, --help            show this help message and exit
  --in-file IN_FILE     Input file. Could be relative (to current directory)
  --out-file OUT_FILE   Output file. Could be relative (to current directory)
  --session-name-suffix SESSION_NAME_SUFFIX
                        Session name suffix. Defaults to ` - cleaned`.
  --extension-id EXTENSION_ID
                        ID of ``The Great Suspender`` extension. If left blank, regularexpression match will be used.
  --verbose             Verbose output.
Now would i need to have tabs.json in this folder the run command and it will work.
Reply
#7
(Jun-21-2023, 07:28 PM)snippsat Wrote:
(Jun-21-2023, 02:41 PM)TheMouseAvenger Wrote: 2. But what about my changes to the environment variable paths I showed in my first picture? Were they made correctly, or do I need to start over?
Just need to add Scripts folder (where pip.exe is) in System Variables.
C:\Users\User\AppData\Local\Programs\Python\Python311
C:\Users\User\AppData\Local\Programs\Python\Python311\Scripts
It easier if you make folder that has shorther Path eg C:\div_code.
Here a quick run with virtual enviromnet,and rember restore-the-great-suspender-urls it's a command line tool.
So now need to run it with python.
G:\div_code
λ python -V
Python 3.11.3

G:\div_code
λ pip -V
pip 23.1.2 from C:\python311\Lib\site-packages\pip (python 3.11)

# Make enviroment
G:\div_code
λ python -m venv suspender_env

G:\div_code
λ cd suspender_env\

G:\div_code\suspender_env
λ G:\div_code\suspender_env\Scripts\activate.bat

# Install
(suspender_env) G:\div_code\suspender_env
λ pip install the-great-suspender-restore-urls
Collecting the-great-suspender-restore-urls
  Downloading the_great_suspender_restore_urls-0.4-py3-none-any.whl (5.8 kB)
Installing collected packages: the-great-suspender-restore-urls
Successfully installed the-great-suspender-restore-urls-0.4

# As it's a command line tool --help will work
(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --help
usage: restore-the-great-suspender-urls [-h] --in-file IN_FILE --out-file OUT_FILE [--session-name-suffix SESSION_NAME_SUFFIX]
                                        [--extension-id EXTENSION_ID] [--verbose]

Restore the broken URLs of the Great Suspender browser extension

options:
  -h, --help            show this help message and exit
  --in-file IN_FILE     Input file. Could be relative (to current directory)
  --out-file OUT_FILE   Output file. Could be relative (to current directory)
  --session-name-suffix SESSION_NAME_SUFFIX
                        Session name suffix. Defaults to ` - cleaned`.
  --extension-id EXTENSION_ID
                        ID of ``The Great Suspender`` extension. If left blank, regularexpression match will be used.
  --verbose             Verbose output.
Now would i need to have tabs.json in this folder the run command and it will work.

Only one more question: If my "tabs.json" & "tabs_oldercopywithalternatelinks.json" files, & my "the-great-suspender-urls-restore" script, are all located in C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4, how should I specifically type/input those specific file names & folder paths into the code? (It would help if you could repost the code with those file names & folder paths incorporated within, so I'll know exactly what to type. :-) )
Reply
#8
Do you really mean "C:\Users\User\Desktop" or do you mean the desktop for the current user? If the latter, you can ask windows for the current user's %HOMEPATH%. This program lists all the files on your desktop.
import os
from pathlib import Path

desktop = Path(os.environ["USERPROFILE"]) / "Desktop"
print(*desktop.iterdir(), sep="\n")
To get paths for Desktop\tabs.json and Desktop\tabs_oldercopywithalternatelinks.json:
work_files = desktop / "the-great-suspender-restore-urls-0.4"
tabs_path = work_files / "tabs.json"
tabs_copy_path = work_files / "bs_oldercopywithalternatelinks.json" 
if the path is really hard coded (will always be C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4), use a string. I suggest changing the "\" to "/" so Python doesn't interpret "\the" as "<tab>he".
from pathlib import Path

work_files = Path("C:/Users/User/Desktop/the-great-suspender-restore-urls-0.4")
tabs_path = work_files / "tabs.json"
tabs_copy_path = work_files / "bs_oldercopywithalternatelinks.json"
Reply
#9
(Aug-17-2023, 02:50 PM)TheMouseAvenger Wrote: C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4, how should I specifically type/input those specific file names & folder paths into the code?
You give path to where file is,so my Windows User name is Tom.
# Activate 
G:\div_code\suspender_env
λ G:\div_code\suspender_env\Scripts\activate

# Now give path to file rand.json
(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --in-file=C:/Users/Tom/Desktop/rand.json --out-file=C:/Users/Tom/Desktop/jsontabs-restored.json
Output:
Tested <jsontabs-restored.json> works
It's easier when work with CLI tool if navigate to folder where filers are,and i would not use Desktop for this at all,make your own folder as advised.
With simpler path eg C:\div_code
Here a demo on navigate to a folder,now don't have to give path
(suspender_env) G:\div_code\suspender_env
λ c:

(suspender_env) C:\Users\Tom
λ cd ..

(suspender_env) C:\Users
λ cd ..

# If start for root C:
(suspender_env) C:\
λ cd Users\tom\Desktop

# Now in Desktop folder
(suspender_env) C:\Users\Tom\Desktop
λ restore-the-great-suspender-urls --in-file=rand.json --out-file=tabs-restored.json
Reply
#10
(Aug-17-2023, 02:50 PM)TheMouseAvenger Wrote:
(Jun-21-2023, 07:28 PM)snippsat Wrote: Just need to add Scripts folder (where pip.exe is) in System Variables.
C:\Users\User\AppData\Local\Programs\Python\Python311
C:\Users\User\AppData\Local\Programs\Python\Python311\Scripts
It easier if you make folder that has shorther Path eg C:\div_code.
Here a quick run with virtual enviromnet,and rember restore-the-great-suspender-urls it's a command line tool.
So now need to run it with python.
G:\div_code
λ python -V
Python 3.11.3

I selected the third mini-code, as it's precisely what I need to use! ^_^ Just one more question: Where exactly do I put the mini-code in the main code?

G:\div_code
λ pip -V
pip 23.1.2 from C:\python311\Lib\site-packages\pip (python 3.11)

# Make enviroment
G:\div_code
λ python -m venv suspender_env

G:\div_code
λ cd suspender_env\

G:\div_code\suspender_env
λ G:\div_code\suspender_env\Scripts\activate.bat

# Install
(suspender_env) G:\div_code\suspender_env
λ pip install the-great-suspender-restore-urls
Collecting the-great-suspender-restore-urls
  Downloading the_great_suspender_restore_urls-0.4-py3-none-any.whl (5.8 kB)
Installing collected packages: the-great-suspender-restore-urls
Successfully installed the-great-suspender-restore-urls-0.4

# As it's a command line tool --help will work
(suspender_env) G:\div_code\suspender_env
λ restore-the-great-suspender-urls --help
usage: restore-the-great-suspender-urls [-h] --in-file IN_FILE --out-file OUT_FILE [--session-name-suffix SESSION_NAME_SUFFIX]
                                        [--extension-id EXTENSION_ID] [--verbose]

Restore the broken URLs of the Great Suspender browser extension

options:
  -h, --help            show this help message and exit
  --in-file IN_FILE     Input file. Could be relative (to current directory)
  --out-file OUT_FILE   Output file. Could be relative (to current directory)
  --session-name-suffix SESSION_NAME_SUFFIX
                        Session name suffix. Defaults to ` - cleaned`.
  --extension-id EXTENSION_ID
                        ID of ``The Great Suspender`` extension. If left blank, regularexpression match will be used.
  --verbose             Verbose output.
Now would i need to have tabs.json in this folder the run command and it will work.

Only one more question: If my "tabs.json" & "tabs_oldercopywithalternatelinks.json" files, & my "the-great-suspender-urls-restore" script, are all located in C:\Users\User\Desktop\the-great-suspender-restore-urls-0.4, how should I specifically type/input those specific file names & folder paths into the code? (It would help if you could repost the code with those file names & folder paths incorporated within, so I'll know exactly what to type. :-) )
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how do I successfully use PDO with my ODBC for MSSQL? cyberion1985 3 6,593 Jun-26-2018, 04:44 PM
Last Post: Maverick494
  Cannot successfully install NumPy aniketmone2017 3 7,367 Dec-29-2016, 02:14 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020