-2

I'm having a small yet quite annoying issue with Python. When I import the webbrowser module in a Python script that is run from IDLE, it works perfectly fine. However, if the script is run outside of IDLE, importing the webbrowser module makes the program stop and wait for user input.

I made the following basic example that shows the problem step by step:

print('the program has started')
print('importing some random modules')
import sys
print('sys imported')
import pyperclip
print('pyperclip imported')
import logging
print('logger imported')
print('this is the line before importing the webbrowser module')
import webbrowser
print('webbrowser module imported')
print('end of demo program')

Here is a screenshot of what happens when I launch the program. And finally, here is a screenshot of the program after I enter some text and press enter.

What is it that it stops the webbrowser module when importing it outside of IDLE? I only want the program to import the module and to continue normally.

Eryk Sun
  • 33,190
  • 5
  • 92
  • 111
  • Here is the third link : http://imgur.com/a/HNCs9 – Felix Tremblay Aug 25 '16 at 03:20
  • 1
    Do you have your own module named `webbrowser.py` in the current directory? – John Gordon Aug 25 '16 at 03:27
  • @JohnGordon The only webbrowser.py I have is the one in the lib directory, the one that comes with python. The debugger says that this is the one being imported when I run the program :/ – Felix Tremblay Aug 25 '16 at 16:09
  • @eryksun Yeah, sorry, I'm quite new to the world of programming. I know the cmd doesnt actually run python by itself and that's also why I don't understand what's happening differently from when I run it in the idle. It works perfectly in the idle. – Felix Tremblay Aug 25 '16 at 16:12
  • Oh and if I just run python.exe in the cmd, when I try to import webbrowser it also waits for an input – Felix Tremblay Aug 25 '16 at 16:16
  • Please run python.exe and tell me what the following prints: `import importlib.util; print(importlib.util.find_spec('webbrowser').origin)`. – Eryk Sun Aug 25 '16 at 18:14
  • @eryksun >>> import importlib.util; print(importlib.util.find_spec('webbrowser').origin) C:\Python35\lib\webbrowser.py – Felix Tremblay Aug 25 '16 at 22:07
  • @eryksun ok, this is complete nonsense... Now, it doesn't stop when I import webbrowser. However, when i run the demo script, it still does stop – Felix Tremblay Aug 25 '16 at 22:41

1 Answers1

2

Found the problem! there was a 'copy.py' script in the folder in which I store my scripts. The webbrowser module has to import a module named copy. Deleted 'copy.py' from the directory, everything works fine.