WORKAROUND FOUND, MAYBE?
I have yet more info.
Short Summary
I have things working now, but I’m not exactly sure why.
I found a problem with where Python was looking for its libraries - PySerial was getting installed but wasn’t in the search path.
I worked around it by updating PYTHONPATH, and things started working.
But then at some later point, I tried removing my PYTHONPATH mod, and it was still working. It’s possible that I changed which Python interpreter I was using? But not sure. I did at one point go into the Robot Framework Language Server extension settings, but I don’t think I actually changed anything.
At some point, VS Code ceased trying to run “conda activate” at the start of each test session, although things started working before that.
So it’s working now, and I don’t know why.
Full Details
What’ I discovered was going on is that PySerial is getting installed into
C:\ProgramData\robocorp\ht\lib\site-packages\serial
as can be seen here:
C:\ProgramData\robocorp\ht\3ed6a10_b1f3c24_691db988>.\python
Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 16:51:29) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import serial
>>> print(serial.__dict__.keys())
dict_keys(['__name__', '__doc__', '__package__', '__loader__', '__spec__', '__path__', '__file__', '__cached__', '__builtins__', 'absolute_import', 'sys', 'importlib', 'serialutil', 'io', 'time', 'unicode', 'basestring', 'iterbytes', 'to_bytes', 'XON', 'XOFF', 'CR', 'LF', 'PARITY_NONE', 'PARITY_EVEN', 'PARITY_ODD', 'PARITY_MARK', 'PARITY_SPACE', 'STOPBITS_ONE', 'STOPBITS_ONE_POINT_FIVE', 'STOPBITS_TWO', 'FIVEBITS', 'SIXBITS', 'SEVENBITS', 'EIGHTBITS', 'PARITY_NAMES', 'SerialException', 'SerialTimeoutException', 'PortNotOpenError', 'Timeout', 'SerialBase', '__version__', 'VERSION', 'os', 'win32', 'serialwin32', 'Serial', 'protocol_handler_packages', 'serial_for_url'])
>>> print(serial.__path__)
['C:\\ProgramData\\robocorp\\ht\\lib\\site-packages\\serial']
>>> print(serial.__file__)
C:\ProgramData\robocorp\ht\lib\site-packages\serial\__init__.py
but that folder wasnot in the PYTHONPATH when RobotFramework runs. This is the PYTHONPATH that was being printed out at the start of each run.
PYTHONPATH:
c:\Users\brad\Nextcloud\Documents\_TMT\Software\m1cs\UpperSegBox\UsebGui
c:\ProgramData\robocorp\ht\3ed6a10_b1f3c24_691db988\lib\site-packages\win32
c:\ProgramData\robocorp\ht\3ed6a10_b1f3c24_691db988\lib\site-packages\win32\lib
c:\ProgramData\robocorp\ht\3ed6a10_b1f3c24_691db988\lib\site-packages\Pythonwin
I notice in the VS Code terminal window that there is a call to “conda” to start the process, which fails:
PS C:\Users\brad\Nextcloud\Documents\_TMT\Software\m1cs\UpperSegBox\UsebGui> conda activate c:\ProgramData\robocorp\ht\3ed6a10_b1f3c24_691db988
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program.
There is no conda.exe on my system, other than in a folder where I do some Julia programming, and it is not in my path. There is no Conda.exe is the robocorp tree.
The workaround fix would appear to be to augment PYTHONPATH to include C:\ProgramData\robocorp\ht\lib\site-packages by adding an “env” clause to my launch.json:
"program": "${file}",
"env": {
"PYTHONPATH": "C:\\ProgramData\\robocorp\\ht\\lib\\site-packages;${PYTHONPATH}"
}
The question is why conda is getting called, or maybe why it isn’t included in the robocorp tree? Or maybe this stuff should be being set up in the .bat file that runs just after Conda fails?
In any event, when I made that mod, things started working.
And then later when I removed that mod, they continued to work.
Very baffling, but perhaps this will help someone if they run into the same problem.