Wednesday, October 31, 2018

Firewal issues resolved in forthcoming PyScripter 3.5

PyScripter, with the remote python engine option, runs python in a sub-process and communicates with it using sockets.  The connection is local and does not present a security risk.  As stated in an earlier post, in case the Firewall is an issue:  Go to Control Panel\System and Security\Windows Defender Firewall\Customise Settings and make sure the "Notify me when Windows Defender blocks a new app" is checked. It is checked by default.

However there are users running under strictly controlled corporate environments in which even these "innocent" local TCP/IP connections are not allowed.  So a few users could not load and connect to python.  What can be done with the current version is:

  • Enable the Internal Python Engine (Tools, Options, IDE options, Python, uncheck "Internal Interpreter hidden).
  • Then go to the Python Versions dialog and try to load a python version. 
The forthcoming version 3.5 offers another option: to communicate with the python engine using Windows named pipes.  There is no change in the user experience and it works faster than socket communication.  The big advantage is that this bypasses firewall issues, since it does not use sockets. For PyScripter to be able to use named pipes the python module pywin32 needs to be installed in your python version.  Conda releases include the module.  If you do a fresh install with versions from www.python.org you can add this module by issuing the command;

> pip install pywin32

at the command prompt or using the pip External tool in PyScripter.  If the module is not available in your python version PyScripter will revert to using sockets as before.  There is a new IDE option "Always use sockets" that will prevent PyScripter from using named pipes.  This option is on by default.  So if your firewall prevents for using the remote python engine, you should switch this option off.  (Tools, Options, IDE Options, Python Interpreter, "Always use sockets").

Monday, October 29, 2018

PyScripter understands type hints

The forthcoming version of PyScripter supports python 3 type hints. The main use of type hints by pyscripter is to improve code completion.  See for instance the following example.  (shame blogger does not provide code formatting)

class Airport:
    def __init__(self, name:str):
      self._name = name
    @property
    def location(self) -> str:
        return self._name
class Flight:
    def __init__(self, origin:str, dest:str):
        self.origin = origin
        self.dest = dest
class Plane:
    def do_flight(self, fligth:Flight):
        origin = fligth.origin  #code completion flight.
        dest = fligth.dest
        print("I am flying from {origin} to {dest}".format(origin=origin, dest=dest))
def catch_plane() -> Plane:
    return Plane();
Venizelos = Airport("Athens")
Fiumicino = Airport("Rome")
plane = catch_plane()
plane.do_flight(Flight(Venizelos.location, Fiumicino.location)) #code completion plane.

If you want full type checking of your code you can setup mypy as an external tool.

Thursday, October 25, 2018

Using PyScripter with QGIS

QGIS is a free and open source GIS System.  However it comes with an unusual setup.  To use it with Pyscripter you need to:

  • copy  python3.exe and python36.dll (or python37.dll for recent versions) from the bin folder (osgeo4w\bin) to the python folder (osgeo4w\apps\Python36 or osgeo4w\apps\Python36)
  • rename python3.exe to python.exe
Then the installation is similar to the ones described here

Using PyScripter with ArcGIS Pro

You can easily setup PyScripter to work with ArcGIS Pro.  Since ArcGIS Pro is a 64bit application you need to have Windows 64 bits.  Make sure you have installed PyScripter 64bits.
  • Install ArcGIS Pro.  I have used a single user installation and the product was installed in C:\Users\username\AppData\Local\Programs\ArcGIS\Pro.
  • Start PyScripter 64bit v 3.4,2
  • Go to the Python Versions dialog (Run, Python Versions, Setup Python..)
  • Add a new version pressing the + button and select the path C:\Users\username\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3
  • Activated the new unregistered version and pressing the first button
  • If you get a firewall notification allow the connection and voila

In case the Firewall is an issue:

Go to Control Panel\System and Security\Windows Defender Firewall\Customise Settings and make sure the "Notify me when Windows Defender blocks a new app" is checked. It is checked by default.

Wednesday, October 17, 2018

PyScripter project of the week at Sourceforge

PyScripter has been included in the projects of the week selection by SourceForge for the second time recently.  

New Feature: Run and Debug files on remote Windows and Linux machines using SSH

As hinted, the forthcoming version 3.5 of PyScripter will allow you to run and debug scripts on remote Windows and Linux SSH servers.  It introduces a new type of engine called "SSH engine",   which runs a python interpreter in a remote Windows or Linux computer or inside a virtual machine.  You first need to define one or more SSH servers as explained here .  This post also describes the requirements for using SSH with PyScripter.  Once you choose this type of engine you need to select a defined SSH server. PyScripter starts a python engine on the remote server using SSH and communicates with it using rpyc.  You can then run and debug remote or local scripts on the SSH server as if the scripts were running locally.  You can also use python running inside the SSH server with the Python Interactive Interpreter. While debugging, tracing into remote modules works transparently for the user.  If you are running python 2.x locally the remote version also needs to be 2.x and similarly if you run python version 3.x locally the remote version needs to be 3.x.  Beyond this constraint, the local and remote versions do not need to be the same.

Friday, October 5, 2018

Working with Remote Files. Preview of new feature.

In the next version, Pyscripter will support working with remote files i.e. files that may reside in different computers (servers) including Windows and Linux machines. You will be able to open, edit run debug and save back these files.  They work seamlessly with other PyScripter features such as the Recent File list, project files, and Run Configurations.
Requirements
To use PyScripter with remote files your computer need to have SSH client capabilities at the computer running PyScripter and an SSH server running on the remote computer.  SSH is a widely used network protocol for securely connecting to remote machines.  Windows 10 since the April 2018 update includes SSH. With earlier versions of Windows 10 you need to manually enable SSH through "Enable Optional Features".  For other versions of Windows you can install the latest version of OpenSSH for Windows using the provided installation instructions.

Configuring the SSH client side
Pyscripter requires password-less authentication using rsa keys.  You need to create the rsa keys and add them to the ssh-agent service which needs to be running.  Your public key needs to be added to the ~/.ssh/authorised_keys file on the server side.  Instructions are provided here.



Configuring the SSH server side

The SSH server service (sshd) and SSH agent service (ssh-agent) need to be running on the server side.  This is most likely true for Linux machines.  In Windows machines you need to start the server using the
    net start sshd
    net start ssh-agent
commands.   You can also configure these services to run automatically.

Testing the SSH connection
From a command prompt issue the following command:
    ssh username@hostname

where username is the user name on the server side and host name is the IP address of the SSH server.  If this works and you see the server shell, then PyScripter is ready to use the Server.




Opening remote files

You can open remote files using the File Menu.  You are then shown the Open Remote File dialog shown below:



In this dialog box you provide the path to the remote file and select an SSH server from a drop-down list.  You can also setup your SSH servers by pressing the button next to the SSH server field.   In PyScripter remote file names are shown in the UNC format \\server name\filepath.
Setting up SSH Servers


In this dialog box you add remove or modify SSH servers.  
Editing SSH sever information


For each SSH server you need to provide a Name that will be used to identify the server, as well as the user name and host name (or IP address) that will be used to connect to the server.  You also need to provide the command that will be used to execute Python on the server.