This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cant DEBUG os.spawnv()
Type: Stage:
Components: Windows Versions: Python 3.10
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, michaellongge, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2022-01-30 07:22 by michaellongge, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
20220131165155.png michaellongge, 2022-01-31 09:12
Messages (3)
msg412129 - (view) Author: michaellongge (michaellongge) Date: 2022-01-30 07:22
When i try to execute --link.exe *.obj-- on windows 11, i get one error
LIB : fatal error LNK1181: cannot open input file 'Files.obj'
It looks like a space path error
so i run [os.spawnv(link.exe)] alone try to find out where made this error.
But i cant DEBUG os.spawnv() on Pycharm.
When the cursor on os.spawnv() line then press [Step Into], cursor jump to ntpath.py (216) it's in "def basename()"  not in os.py "def spawnv()"

so this issue contain 2 parts
1.space error such as "Program Files (x86)"
2.DEBUG cant jump to right place

Here is my salmpe code.I have tried python3.8 and python3.10 both same error
```
import os

executable= 'D:\\VS2022\\VC\\Tools\\MSVC\\14.30.30705\\bin\\HostX86\\x64\\link.exe'

cmd310 = ["/LIBPATH:D:\\python310\\lib\\site-packages\\torch\\lib", "/LIBPATH:D:\\python310\\libs", "/LIBPATH:D:\\python310\\PCbuild\\amd64", "/LIBPATH:D:\\VS2019\\VC\\Tools\\MSVC\\14.29.30133\\ATLMFC\\lib\\x64", "/LIBPATH:D:\\VS2019\\VC\\Tools\\MSVC\\14.29.30133\\lib\\x64", "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.8\\lib\\um\\x64", "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.19041.0\\ucrt\\x64", "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\lib\\10.0.19041.0\\um\\x64", "/LIBPATH:D:\\VS2019\\VC\\Tools\\MSVC\\14.29.30133\\lib\\x64", "/LIBPATH:D:\\VS2019\\VC\\Tools\\MSVC\\14.29.30133\\atlmfc\\lib\\x64", "/LIBPATH:D:\\VS2019\\VC\\Auxiliary\\VS\\lib\\x64", "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.19041.0\\ucrt\\x64", "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.19041.0\\ucrt_enclave\\x64", "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.19041.0\\um\\x64", "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\NETFXSDK\\4.8\\lib\\um\\x64", "/LIBPATH:D:\\python310\\libs", "c10.lib", "torch.lib", "torch_cpu.lib", "torch_python.lib"]
rc = os.spawnv(os.P_WAIT, executable, cmd310)
```
msg412168 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2022-01-30 18:49
> cmd310 = ["/LIBPATH:D:\\python310\\lib\\site-packages\\torch\\lib",

The `argv` parameter of os.spawnv() should begin with a command name to ensure that the application parses its command-line correctly. This doesn't necessarily have to be a file path since the `path` argument is what gets executed. For example, in this case I would use `cmd310 = ["link", ...]`.

That said, for various reasons, including the correct quoting of command-line arguments that contain spaces, I recommend that you use the subprocess module instead of os.spawnv(). For example, use `p = subprocess.run(cmd310, executable=executable)`. The first item of the argument list still needs to be "link" in this case. Or include the full path of "link.exe" at the start of cmd310, and use `p = subprocess.run(cmd310)`.

> But i cant DEBUG os.spawnv() on Pycharm.

In Windows, os.spawnv() is a builtin function from the nt extension module, defined in Modules/posixmodule.c. It is not defined in os.py. The C implementation is a minimal wrapper around the C runtime's _wspawnv() function [1]. Probably PyCharm isn't capable of debugging a builtin function.

---
[1] https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/spawnv-wspawnv
msg412194 - (view) Author: michaellongge (michaellongge) Date: 2022-01-31 09:12
I can't use subprocess. Because the original problem is not that I want to use os.spawnv(). The original problem is that I go to install python3d, use setup.py install, the returned information shows that the compilation is completed, the link is also completed, and the installation is also completed. Done, but the pytorch3d folder is in the D:\Python38\Lib\site-packages\pytorch3d-0.6.1-py3.8-win-amd64.egg folder, which seems to be wrong because I moved it manually It can be used normally outside pytorch3d-0.6.1-py3.8-win-amd64.egg. (I wrote the detailed issue here [https://github.com/facebookresearch/pytorch3d/issues/1052]) So I I tried to use pycharm to debug the process. I wanted to see where the installation error was, so I encountered the problem of os.spawnv(). If you want to find the installation problem, you must first compile and link. This LIB: fatal error LNK1181: just Occurs in the link stage spawn.py (69). The strange thing is that the operation will not report an error, but DEBUG will report an error.
So my salmpe code is all separated from D:\Python38\Lib\distutils\spawn.py (69), when the breakpoint stops here, rc = os.spawnv(os.P_WAIT, executable, cmd) The corresponding parameters are written in samlpe, here is another sample of mine, which can also be installed on my PC, but cannot use DEBUG for Pycharm

https://github.com/michaellongge163/hellopythonextension
History
Date User Action Args
2022-04-11 14:59:55adminsetgithub: 90736
2022-01-31 09:12:43michaellonggesetfiles: + 20220131165155.png

messages: + msg412194
2022-01-30 18:49:04eryksunsetnosy: + paul.moore, tim.golden, eryksun, zach.ware, steve.dower
messages: + msg412168
components: + Windows, - Build
2022-01-30 07:22:42michaellonggecreate