PyCharm run succeeds but debugger fails with error OSError: [Errno 2] No such file or directory

I have a script that creates a subprocess by calling:

process = subprocess.Popen(run_args, env=self.ENV)

where run_args starts with ['python', '/path/to/script.py', ... ]

When I run my script in PyCharm it succeeds but when I try to debug it, it fails immediately with this error:

==============================================================================
python /path/to/script.py 
==============================================================================
Traceback (most recent call last):
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 2060, in <module>
main()
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 2054, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1405, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1412, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File "/path/to/main_script.py", line 17, in <module>
File "/path/to/main_script.py", line 194, in main
File "/path/to/main_script.py", line 152, in run
process = subprocess.Popen(run_args, env=self.ENV)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 394, in __init__
errread, errwrite)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

Process finished with exit code 1

 

Also when I untick the option "attach to subprocess automatically while debugging" in Preferences -> Python Debugger, the script runs but obviously I can't use breakpoints in my code that's running within the subprocess.

I am running:

PyCharm 2019.2 (Community Edition)
Build #PC-192.5728.105, built on July 23, 2019
Runtime version: 11.0.3+12-b304.10 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.6
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 16
Registry:
Non-Bundled Plugins: com.millennialmedia.intellibot, org.toml.lang

 

5 comments
Comment actions Permalink

Hi, I could not reproduce the issue in PyCharm 2019.2.1

Please update if you haven't already and try again: https://www.jetbrains.com/pycharm/download

If the issue is still reproduced, can you provide a code sample to reproduce the issue?

0
Comment actions Permalink

Just happened again after updating PyCharm:

PyCharm 2019.2.1 (Community Edition)
Build #PC-192.6262.63, built on August 22, 2019
Runtime version: 11.0.3+12-b304.39 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.6
GC: ParNew, ConcurrentMarkSweep
Memory: 1979M
Cores: 16
Registry:
Non-Bundled Plugins: com.millennialmedia.intellibot, org.toml.lang

 

Ok here is a reproducible code sample:

https://github.com/omrihaviv/python-subprocess-sample

Very important: I use pipenv for this sample and for the original code which could be the problem. You should have pipenv installed in order to run this sample.

I have pipenv version 2018.11.26

and python version 2.7.16

0
Comment actions Permalink

Unfortunately I could not reproduce the issue using Python 2.7 and Pipenv.

Are there any other unmentioned specifics in your setup which could be relevant to the issue?

0
Comment actions Permalink

Sorry Andrey but I can't think of anything else that is specific to my setup. Can you elaborate what can I check for?

0
Comment actions Permalink

Thank you, I've managed to reproduce the issue. Seems to be not related to Pipenv, but to Python 2 in general: https://youtrack.jetbrains.com/issue/PY-37804

Please follow the ticket for updates. 

0

Please sign in to leave a comment.