Advice on remote interpreter (Windows to Windows)

Hello,

I could use some help with difficulties I'm experiencing. I hope I'm in the right place and some witty minds can nudge me in the right direction. I use PyCharm Professional 2017.2.3 on my notebook(Windows 10 Pro). I would like to be able to run/debug/deploy scripts to an remote machine currently with Windows 10 Pro, could be downgraded to Windows 7 if necessary. The scripts I'm creating are for automating UI stuff on Windows applications. I'm using packages like pywinauto and selenium

I've tried two possible main solutions, but both did not provided me with satisfactory results.

 

WSL

On the remote machine I've installed WSL following the instructions provided by Jetbrains, and am able to setup a working remote interpreter by SSH.

The problem occurs on running my scripts. I guess because the Python instance used is running under Bash, I can't make use of pywinauto because it needs win32process. So unless there is a way to support win32process, or to redirect to a Windows instance of Python, this option can't be used.

Native Windows

Another option I tried is installing Python in Windows on the remote machine. I've also installed Win32 OpenSSH and the connections seems fine. When I add it as a remote interpreter it seems incorrect because it states "unknowns interpreter" and is not able to show a list of installed packages. 

When I select the "Install packaging tools" it gives an error about not recognising "env". 

 

I could really use some help here. Thank you in advance.

With kind regards,

 

2 comments
Comment actions Permalink

Hi there,

Nice experiments!

I've got a similar case. I'd like to run my Python code on Windows 10 via remote interpreter. And my code uses CUDA.

 

Exp0 - WSL

WSL itself won't work for me – they do not provide access to the GPU. Here's another post, Is there anyway to make remote interpreter point to a windows version python.exe?, about an attempt to use WSL to access native Windows python. AFAIU, it doesn't work.

 

Exp1 - KpyM ssh server

The KpyM ssh server is yet another ssh server for windows (some other options: 1,2). Easy to install, works exactly like normal local cmd. I’m not sure if there’s any difference in PyCharm behavior for KpyM vs OpenSSH, but I’d like to add some details I’ve noticed:

  • I can easily activate anaconda environment (like in local cmd) and run my python script (that uses GPU). This part looks very promising.
  • I’m able to browse files with filezilla - SFTP is working. Paths look like “/C$/Temp”.

However, there’s something broken in PyCharm 2017.3.2.

  1. “Test SFTP connection…” only works if I put “/” in “Root path”.
  2. The “browse” button is not working. Usually, it just shows an orange exclamation mark:,

    sometimes, there’s also an error message:
  3. If I press “Autodetect”, the “Root path” changes to “/C$/Users/ivarfolomeev”. And now “Test SFTP connection…” is broken as well.
  4. Note that the server says “Active code page: 437”. I had “Windows-1252” by default in the “Advanced options…”. I’ve tried to change it to “437”, “cp437” and “l;kasdjf;lksadjkl;fjsda” – surprisingly, nothing changes.

 

Exp2 - Cygwin ssh server + native windows python / in-cygwin python

Cygwin sounds less like “native windows”. It feels weird to use it to run a native Windows app. And it’s less easy to install (personally, I’ve mostly followed this).

  • I’ve not managed to make normal conda “activate” work. I’m not sure what’s wrong, maybe this. I’ve simply added all I need to PATH. Again, I’m able to run the python script I need.
  • The SFTP via Filezilla is works OK.

However, there’s something broken in PyCharm again.

  1. The “Test SFTP connection…” and “browse” button work OK this time.
  2. Next, I get those weird “Python packaging tools not found” (just like on the pic in the message above).
  3. Next, I get
    Couldn't refresh skeletons for remote interpreter

    failed to run generator3.py for sftp://IVarfolomeev@slb-9cgpq52:2225/cygdrive/c/Users/ivarfolomeev/Anaconda3/envs/odl/python.exe, exit code 2, stderr:

    -----

    C:\Users\ivarfolomeev\Anaconda3\envs\odl\python.exe: can't open file '/home/IVarfolomeev/.pycharm_helpers/generator3.py': [Errno 2] No such file or directory
    Unix-style path to ".py" is not working with python for windows. The in-cygwin python from "/usr/bin/python" works OK here, but, this is not the python I need.
  4. The same error happens  if I directly try this is console:
    $ python.exe /home/IVarfolomeev/.pycharm_helpers/generator3.py
    Windows-style path works OK:
    $ python.exe "C:\cygwin64\home\IVarfolomeev\.pycharm_helpers\generator3.py"
    The full correct version (that works in the console) would be:
    $ /cygdrive/c/Users/ivarfolomeev/Anaconda3/envs/odl/python.exe "C:\cygwin64\home\IVarfolomeev\.pycharm_helpers\generator3.py"
    (Here’s a related answer on stackoverflow.)
  5. Same thing happens when I try to run any my own script from PyCharm with a regular “run” button – the path to the “py” file is global and uses incorrect format. 
  6. OK. PyCharm silently gives us unix-style-paths, and it's not possible (?) to change it. it looks like a quick-and-dirty workaround is to convert path with a wrapper-script for "python.exe". I've created the following "\home\python_exe_wrapper.sh" (note:there's a lot to improve in this script):

    #!/bin/sh
    if [ "${1}" = "-u" ];
    then
    XPATH="$(cygpath -C ANSI -w "${2}")";
    echo "OK, starting python with path="
    echo $XPATH
    echo "............ "
    else
    echo "First argument is not '-u', probably this is some unknown format."
    echo "Exiting"
    exit
    fi

    # Here's a good place to mess with environment variables...
    PATH=$PATH:"/cygdrive/c/Program Files/blahblahblah"

    /cygdrive/c/Users/ivarfolomeev/Anaconda3/envs/odl/python.exe -u $XPATH
  7. Surprisingly, this Frankenstein works. And there's no issues with access to GPU.
    E.g. it is possible to run the script and copy files back-and-forth. The rest (debug, list of packages, ...) is broken.
    (Debug works for the in-cygwin python)

 

Other experiments

There's a bunch of related issues on YouTrack. Most of them are linked PY-20952. Vote for it. Some of them contain interesting workarounds. E.g. PY-14404 and PY-22016 suggest to put windows-style path into "PyCharm helpers path" field. I've tried this trick (with my ".sh" wrapper and without it), and I can confirm that it fixes one thing (now the list of packages is displayed correctly) at the expense of two others (interpreter config is now highlighted with red "incomplete" mark and helpers auto-uploading/auto-update is unlikely to work).

Thus:

  • It would be even nice if JetBrains would fix how PyCharm works with remote ssh servers on Windows hosts.
  • Could anyone suggest any better workarounds? 
  • Any other experiments?
3
Comment actions Permalink

Hi,I hope this information can be useful. I am dealing with this issue too.

Here:

https://youtrack.jetbrains.com/issue/PY-20952 

You can read the developer assigned for this issue, Alexander Koshevoy, saying to a user:

@Vladimir Avdoshka as for now we have no plans for implementing this in the next 2018.3 version unfortunately.

I voted for this issue to be addressed...

0

Please sign in to leave a comment.