2

I am using VS code, Visual code extension for debugging (showing the state of the code, putting marks where to run before running line by line and always showing the state of the parameters etc..) and I am trying to think how I should begin to check what is wrong if my codes with python standard library called webbrowser works only when I am using my debugger extension. My different short python scripts function if I run them while using the debugger extension but not while running them without the debugging extension. I have an example code which worked fine earlier but don't work anymore.

The next code is an example which works if I have copied and address like "Tammiston kauppatie 10, 01510 Vantaa" (which is a Finnish street address to a climbing venue) and it is on my clipboard. This short script should take the address copied from the clipboard and open google maps site showing the address.

import webbrowser, sys, pyperclip


if len(sys.argv) >1:
    adress = " ".join(sys.argv[1:])
else:
    adress = pyperclip.paste()


webbrowser.open("https://www.google.com/maps/place/" + adress)

At the moment the code above doesn't open my current webbrowser and doesn't give any error messages either.

Any ideas how to make my code to work again? How to start checking what's wrong?

Other maybe useful info:

[tool.poetry.dependencies]
python = "3.9.13"
requests = "^2.28.1"
pyperclip = "^1.8.2"
VS Code:
Version: 1.70.1 (user setup)
OS: Windows

The debugger extension says that it supports the codes with Python language: >=3.7

Also -> using Chrome, up to date version.

Eriuth
  • 31
  • 5
  • 1
    The sample code works on my machine. Try checking your computer's default browser settings. – JialeDu Aug 22 '22 at 05:52
  • 1
    Thank you. I'll check them again and come back to you. Any ideas, what I may have specially missed? (Anyways, checking them again and checking more documentation.) It was good to know that it works on someone else's Visual Studio Code. – Eriuth Aug 23 '22 at 08:56
  • 1
    What extension are you using for debugging? – JialeDu Aug 24 '22 at 05:46
  • 1
    https://marketplace.visualstudio.com/items?itemName=ms-python.python – Eriuth Aug 26 '22 at 18:30
  • 1
    Sorry to bother you, can you describe the steps that failed to run in detail? What does it mean to be valid only when using the debugger extension? – JialeDu Aug 29 '22 at 05:54
  • 1
    No problem. I am happy to get help. Just say if there is something specific to check and I'll check it. I actually don't get any error messages and everything I have checked seems to be same (same virtual environment, python version, libraries called etc.) except that web browser opens only if I use debugger. The code runs and if the debugger is used the web browser also launches/opens. If it is not, the code runs but browser wont launch. To my eye everything looks the same. Also, I am using Chrome (up to date version Version 104.0.5112.102 ) and I thought to try out other browsers also. – Eriuth Aug 30 '22 at 07:38
  • 1
    Sorry, maybe I don't understand enough, how do you run the code without using the extension? – JialeDu Aug 30 '22 at 07:41
  • 1
    Thank you. Now I found my mistake! After checking this again few times, it seems that I have called Poetry Run wrong with these files. I thought I checked it and tested it the same way than the other codes that worked but it seems that I have done something wrong. – Eriuth Aug 30 '22 at 07:53

1 Answers1

1

After going through the basics again with the help of JialeDu, I found that I had actually used Poetry wrong. I thought I had used "Poetry Run Python " as mentioned in the documentation (https://python-poetry.org/docs/basic-usage/#using-poetry-run) correctly few times and on different occasions (without it working), and other ways to run the code, but while going everything a new, this was the step that had failed. The Debugger extension used virtual environment correctly from the start. After running the files in my folder in different ways I continued debugging elsewhere. Now, after working this out, I can continue the debugging easily and make my scripts work where and how they should. Thank you for the lesson.

In a way: For me, the real answer for this problem is to start the debugging from the basics again and not really trusting that the basics where all checked the first few times correctly and start again still "few times more with the basics". I had actually moved too fast with my debugging and was thinking too broadly about all the possible ways the code to fail.

Eriuth
  • 31
  • 5