'In MacOS, the webbrowser open function not return
I want to open a web browser tab with this simple python script:
import webbrowser
print('About to open')
webbrowser.open('http://google.fr')
print('Opened')
When I try it in my MacOS terminal, the tab is correctly opened but the script does not return:
> python test.py
About to open
When I finally interrupt the terminal with 'ctrl-c', I obtain this stacktrace:
^CTraceback (most recent call last):
File "/Users/florianbaune/Forge/freya/test.py", line 4, in <module>
webbrowser.open('http://google.fr')
File "/opt/homebrew/anaconda3/envs/freya/lib/python3.10/webbrowser.py", line 86, in open
if browser.open(url, new, autoraise):
File "/opt/homebrew/anaconda3/envs/freya/lib/python3.10/webbrowser.py", line 688, in open
rc = osapipe.close()
File "/opt/homebrew/anaconda3/envs/freya/lib/python3.10/os.py", line 1004, in close
returncode = self._proc.wait()
File "/opt/homebrew/anaconda3/envs/freya/lib/python3.10/subprocess.py", line 1204, in wait
return self._wait(timeout=timeout)
File "/opt/homebrew/anaconda3/envs/freya/lib/python3.10/subprocess.py", line 1938, in _wait
(pid, sts) = self._try_wait(0)
File "/opt/homebrew/anaconda3/envs/freya/lib/python3.10/subprocess.py", line 1896, in _try_wait
(pid, sts) = os.waitpid(self.pid, wait_flags)
KeyboardInterrupt
I have the same behaviour with an ipykernel. The function was correctly returning with my previous configuration (Linux / Intel).
Configuration: MacOS Monterey, Apple M1 Pro
Python/conda env:
# Name Version Build Channel
appnope 0.1.2 pypi_0 pypi
asttokens 2.0.5 pyhd3eb1b0_0
backcall 0.2.0 pyhd3eb1b0_0
beautifulsoup4 4.9.3 pyhb0f4dca_0 anaconda
blas 1.0 mkl anaconda
bottleneck 1.3.4 pypi_0 pypi
brotli 1.0.9 h5eb16cf_7 conda-forge
brotli-bin 1.0.9 h5eb16cf_7 conda-forge
bzip2 1.0.8 h1de35cc_0
ca-certificates 2020.10.14 0 anaconda
certifi 2021.10.8 pypi_0 pypi
cycler 0.11.0 pyhd8ed1ab_0 conda-forge
dateparser 1.1.1 pyhd8ed1ab_0 conda-forge
debugpy 1.5.1 pypi_0 pypi
decorator 5.1.1 pyhd3eb1b0_0
entrypoints 0.3 pypi_0 pypi
executing 0.8.3 pyhd3eb1b0_0
fonttools 4.32.0 pypi_0 pypi
freetype 2.10.4 h4cff582_1 conda-forge
giflib 5.2.1 hbcb3906_2 conda-forge
intel-openmp 2021.4.0 hecd8cb5_3538
ipykernel 6.9.1 pypi_0 pypi
ipython 8.2.0 pypi_0 pypi
jbig 2.1 h0d85af4_2003 conda-forge
jedi 0.18.1 pypi_0 pypi
jpeg 9e h0d85af4_0 conda-forge
jupyter-core 4.9.2 pypi_0 pypi
jupyter_client 7.1.2 pyhd3eb1b0_0
jupyter_core 4.9.2 py310hecd8cb5_0
kiwisolver 1.3.1 pypi_0 pypi
lcms2 2.12 h577c468_0 conda-forge
lerc 2.2.1 h046ec9c_0 conda-forge
libbrotlicommon 1.0.9 h5eb16cf_7 conda-forge
libbrotlidec 1.0.9 h5eb16cf_7 conda-forge
libbrotlienc 1.0.9 h5eb16cf_7 conda-forge
libcxx 12.0.0 h2f01273_0
libdeflate 1.7 h35c211d_5 conda-forge
libffi 3.3 hb1e8313_2
libpng 1.6.37 h7cec526_2 conda-forge
libsodium 1.0.18 h1de35cc_0
libtiff 4.3.0 h1167814_1 conda-forge
libwebp 1.2.2 h28dabe5_0 conda-forge
libwebp-base 1.2.2 h0d85af4_1 conda-forge
lz4-c 1.9.3 he49afe7_1 conda-forge
matplotlib 3.5.1 pypi_0 pypi
matplotlib-base 3.5.1 py310hfc59cd6_0 conda-forge
matplotlib-inline 0.1.2 pyhd3eb1b0_2
mkl 2021.4.0 hecd8cb5_637
mkl-fft 1.3.1 pypi_0 pypi
mkl-random 1.2.2 pypi_0 pypi
mkl-service 2.4.0 pypi_0 pypi
mkl_fft 1.3.1 py310hf879493_0
mkl_random 1.2.2 py310hc081a56_0
munkres 1.1.4 pyh9f0ad1d_0 conda-forge
ncurses 6.3 hca72f7f_2
nest-asyncio 1.5.5 pypi_0 pypi
numexpr 2.8.1 pypi_0 pypi
numpy 1.21.5 pypi_0 pypi
numpy-base 1.21.5 py310hfd2de13_1
openssl 1.1.1n h6c3fc93_0 conda-forge
packaging 20.4 py_0 anaconda
pandas 1.4.1 pypi_0 pypi
parso 0.8.3 pyhd3eb1b0_0
pexpect 4.8.0 pyhd3eb1b0_3
pickleshare 0.7.5 pyhd3eb1b0_1003
pillow 9.0.1 pypi_0 pypi
pip 21.2.4 pypi_0 pypi
prompt-toolkit 3.0.20 pyhd3eb1b0_0
ptyprocess 0.7.0 pyhd3eb1b0_2
pure_eval 0.2.2 pyhd3eb1b0_0
pygments 2.11.2 pyhd3eb1b0_0
pyparsing 2.4.7 py_0 anaconda
python 3.10.4 hdfd78df_0
python-dateutil 2.8.2 pyhd3eb1b0_0
python-tzdata 2022.1 pyhd8ed1ab_0 conda-forge
python_abi 3.10 2_cp310 conda-forge
pytz 2020.1 py_0 anaconda
pytz-deprecation-shim 0.1.0.post0 pypi_0 pypi
pyzmq 22.3.0 pypi_0 pypi
readline 8.1.2 hca72f7f_1
regex 2021.8.3 pypi_0 pypi
setuptools 61.2.0 pypi_0 pypi
six 1.16.0 pyhd3eb1b0_1
soupsieve 2.0.1 py_0 anaconda
sqlite 3.38.2 h707629a_0
stack_data 0.2.0 pyhd3eb1b0_0
tk 8.6.11 h7bc2e8c_0
tornado 6.1 pypi_0 pypi
traitlets 5.1.1 pyhd3eb1b0_0
tzdata 2022a hda174b7_0
tzlocal 4.2 pypi_0 pypi
unicodedata2 14.0.0 pypi_0 pypi
wcwidth 0.2.5 pyhd3eb1b0_0
wheel 0.37.1 pyhd3eb1b0_0
xz 5.2.5 h1de35cc_0
zeromq 4.3.4 h23ab428_0
zlib 1.2.11 h4dc903c_4
zstd 1.5.0 hcb37349_1
Solution 1:[1]
Suprise this morning.
After rebooting my Mac, it finally worked properly. I uncountered some problems on Firefox (strange errors, impossible to launch it).
I think mistake is due to firefox and not webbrowser python module. We'll see if it happen again...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Froz Armony |
