Wing Tipshttps://wingware.com/Tips, tricks, and helpful hints for Wingware's Python IDEsFri, 24 Mar 2023 23:04:52 GMTPyRSS2Gen-1.0.0http://www.dalkescientific.com/Python/PyRSS2Gen.htmlTurbo Completion Mode in Wing Prohttps://wingware.com/hints/turbo-completion<p>In this issue of <a class="reference" href="/hints">Wing Tips</a> we look at how to use Wing Pro's turbo completion mode for Python. Auto-completion normally requires pressing a completion key, as configured by the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-completion</span> <span class="pre">&gt;</span> <span class="pre">Completion</span> <span class="pre">Keys</span></tt> preference, before a completion is entered into the editor.</p> <p>Wing Pro also provides a <tt class="literal"><span class="pre">Python</span> <span class="pre">Turbo</span> <span class="pre">Mode</span></tt> for auto-completion, where completion occurs on any key that cannot be part of a symbol. This allows you to type just enough of a symbol until it is selected in the completer, then move right on to typing the code that follows that symbol. It takes some getting used to, but it can greatly reduce typing once you become comfortable with it.</p> <p>The following example shows the code that can be produced simply by typing the characters <tt class="literal"><span class="pre">p=x.p.e.P(</span></tt> without pressing any completion keys:</p> <img src="https://wingware.com/images/blog/turbo-completion/turbo-completion.gif" alt="/images/blog/turbo-completion/turbo-completion.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" width="800px" /><p>This particular case requires only a single character to match each symbol in the auto-completer. In a more cluttered name space, it may take more characters to match the desired symbol, but in many cases two or three characters is all that is needed before you can move on to the next part of the expression you are trying to type.</p> <p>Notice that turbo mode distinguishes between contexts where a new symbol may be defined and those where an existing symbol must be used. For example, if you type <tt class="literal"><span class="pre">c</span></tt> followed by <tt class="literal"><span class="pre">=</span></tt> on a new line, Wing knows that the <tt class="literal"><span class="pre">=</span></tt> indicates you may be defining a new symbol and does not place the current selection from the auto-completer. When you do want completion to occur in a defining context, you can press <tt class="literal"><span class="pre">Tab</span></tt> or another completion key.</p> <p>In a context where you are trying to type something other than what is in the completer, you can press <tt class="literal"><span class="pre">Ctrl</span></tt>, <tt class="literal"><span class="pre">Alt</span></tt> or <tt class="literal"><span class="pre">Command</span></tt> briefly by itself to hide the auto-completer and thus disable turbo-completion until you type more symbol characters and the completer is displayed once again.</p> <p>Turbo completion is enabled with the <tt class="literal"><span class="pre">Editor</span> <span class="pre">&gt;</span> <span class="pre">Auto-completion</span> <span class="pre">&gt;</span> <span class="pre">Python</span> <span class="pre">Turbo</span> <span class="pre">Mode</span></tt> preference in Wing Pro.</p> <br> <br><p>That's it for now! We'll be back next week with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> https://wingware.com/hints/turbo-completionWed, 19 Jan 2022 01:00:00 GMTDebug Python Code Run by Docker Compose with Wing Prohttps://wingware.com/hints/docker-compose<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to configure Docker Compose so that Python code running on selected container services can be debugged with <a class="reference" href="https://wingware.com/downloads/wing-pro">Wing Pro</a>. This makes it easy to develop and debug containerized applications written in Python.</p> <div class="section"> <h3 class="title-3">Getting Started</h3> <p>Before you can work with Docker Compose you will need to download and install it and then create a working test cluster. See <a class="reference" href="https://docs.docker.com/compose/install/">Install Docker Compose</a> for details.</p> <p>You should also install <a class="reference" href="https://wingware.com/downloads/wing-pro">Wing Pro</a> if you don't already have it.</p> </div> <div class="section"> <h3 class="title-3">Configuration</h3> <p>To configure Wing to use <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. After selecting your source directory, choose <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Python</span></tt> on the second dialog page, and then select <tt class="literal"><span class="pre">Cluster</span></tt>:</p> <img src="https://wingware.com/images/blog/docker-compose/python-executable.png" alt="/images/blog/docker-compose/python-executable.png" backrefs="" class="doc-image" dupnames="" height="246px" ids="" names="" width="686px" /><p>Next create a new cluster configuration by pressing the <tt class="literal"><span class="pre">New</span></tt> button. This displays the cluster configuration dialog. You will need to enter an identifier to use within Wing and point it at the <tt class="literal"><span class="pre">docker-compose.yml</span></tt> file for the cluster. You will also need to select the main service to use as the default place to run your <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and unit test processes:</p> <img src="https://wingware.com/images/blog/docker-compose/cluster-config.png" alt="/images/blog/docker-compose/cluster-config.png" backrefs="" class="doc-image" dupnames="" height="298px" ids="" names="" width="418px" /><p>Once you have created your cluster configuration, submit the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog to complete your project setup.</p> </div> <div class="section"> <h3 class="title-3">Working with the Cluster</h3> <p>You can now control your cluster from Wing's <tt class="literal"><span class="pre">Containers</span></tt> tool, found in the <tt class="literal"><span class="pre">Tools</span></tt> menu. This tool lists the services in your cluster and their status. You can right-click on items here or use the <tt class="literal"><span class="pre">Options</span></tt> menu to build, start, debug, and stop your cluster:</p> <img src="https://wingware.com/images/blog/docker-compose/containers-tool.png" alt="/images/blog/docker-compose/containers-tool.png" backrefs="" class="doc-image" dupnames="" height="389px" ids="" names="" width="467px" /><p>Debug processes, unit tests, Wing's integrated <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> and <tt class="literal"><span class="pre">OS</span> <span class="pre">Commands</span></tt> can all be run in context of the cluster, or optionally instead within isolated containers that match the cluster configuration but run without launching the whole cluster.</p> <p>See <a class="reference" href="/doc/howtos/docker-compose">Using Wing Pro with Docker Compose</a> for more information working with clusters in Wing Pro.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems, have any questions, or have topic suggestions for future Wing Tips!</p> </div> https://wingware.com/hints/docker-composeTue, 21 Sep 2021 01:00:00 GMTUsing Docker with Wing Pro 8https://wingware.com/hints/docker<p>Wing Pro 8 significantly improved support for working with Python code that runs on containers like those provided by <a class="reference" href="https://www.docker.com/">Docker</a>, making it easier to configure projects that use Docker, and adding support for creating new Docker environments during project creation.</p> <div class="section"> <h3 class="title-3">Prerequisites</h3> <p>Before you can work with Docker you will need to download and install it.</p> <p><strong>On Windows and macOS</strong>, downloading Docker Desktop from the <a class="reference" href="https://www.docker.com/">Docker</a> website is the easiest way to install it. Be sure to launch the Docker Desktop after you install it, so the daemon is started.</p> <p><strong>On most Linux distributions</strong>, Docker CE (the free community edition) can be installed with the <tt class="literal"><span class="pre">docker-engine</span></tt> package as <a class="reference" href="https://runnable.com/docker/install-docker-on-linux">described here</a>.</p> <p>You should also install <a class="reference" href="https://wingware.com/downloads/wing-pro">Wing Pro</a> if you don't already have it.</p> </div> <div class="section"> <h3 class="title-3">Project Configuration</h3> <p>You can either create a new Docker container along with a new Wing project or use an existing container configuration.</p> <p>In order to experiment with Docker, the easier of these two options is to create a new Docker container along with your project. To do this, choose <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu, select or create a source directory, and then on the second dialog screen choose <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Environment</span></tt> with environment type <tt class="literal"><span class="pre">Docker</span></tt> and <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Container</span></tt>. You should be able to use the default values entered for <tt class="literal"><span class="pre">Image</span> <span class="pre">ID</span></tt>, <tt class="literal"><span class="pre">Host-side</span> <span class="pre">Directory</span></tt>, and <tt class="literal"><span class="pre">Container-side</span> <span class="pre">Directory</span></tt> and simply go ahead with the environment and project creation by pressing <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt>:</p> <img src="https://wingware.com/images/blog/docker/create-new.png" alt="/images/blog/docker/create-new.png" backrefs="" class="doc-image" dupnames="" height="425px" ids="" names="" width="694px" /><p>If you want to use an existing Docker container configuration instead, create a new project with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu, select or create a source directory, and then on the second dialog page select <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Environment</span></tt> with environment type <tt class="literal"><span class="pre">Docker</span></tt> and <tt class="literal"><span class="pre">With</span> <span class="pre">Existing</span> <span class="pre">Container</span></tt>. You will need to enter at least the container image and host-to-container file mapping. In most cases, selecting a <tt class="literal"><span class="pre">Dockerfile</span></tt> is easier than entering and image ID, since this also reads the host to container file mapping from the <tt class="literal"><span class="pre">Dockerfile</span></tt>:</p> <img src="https://wingware.com/images/blog/docker/use-existing.png" alt="/images/blog/docker/use-existing.png" backrefs="" class="doc-image" dupnames="" height="657px" ids="" names="" width="684px" /><p>Both of these options create a new container configuration and set up <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in your new project's <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> to use that container. You can make later changes to your configuration from there.</p> <p>If you created a new Docker container, it will be built in the <tt class="literal"><span class="pre">Containers</span></tt> tool, which is available in Wing's <tt class="literal"><span class="pre">Tools</span></tt> menu. The container won't be ready for use until that process completes. This may take some time if container images are being downloaded.</p> </div> <div class="section"> <h3 class="title-3">How it Works</h3> <p>Once your project setup is complete and the Docker container has been built, Wing will run debug processes, unit tests, and the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> on an instance of the selected container. Filenames are mapped automatically between the local and container-side copy of files. The debugger will display the local file even though the container's copy of the file is being executed.</p> <p>OS Commands can optionally run commands on the container or on the local host. This is controlled by toggling the <tt class="literal"><span class="pre">Run</span> <span class="pre">in</span> <span class="pre">Container</span></tt> option in the <tt class="literal"><span class="pre">OS</span> <span class="pre">Command</span></tt> configuration.</p> <p>Note that each debug process, each unit test run, and each instance of the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> creates its own independent instance of the container.</p> </div> <div class="section"> <h3 class="title-3">Further Reading</h3> <p>For more detailed instructions for setting up Wing Pro with Docker, see <a class="reference" href="/doc/howtos/docker">Using Wing Pro with Docker</a>.</p> <p>For more information on Wing's support for containers in general, see <a class="reference" href="/doc/proj/container-intro">Working with Containers and Clusters</a>.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/dockerMon, 13 Sep 2021 01:00:00 GMTPython Package Management in Wing Python IDEhttps://wingware.com/hints/packages<p>Last time we looked at how to configure and create Python environments from Wing Pro. In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we'll take a look at managing your pip, pipenv, or conda Python environment from Wing Pro's <tt class="literal"><span class="pre">Packages</span></tt> tool.</p> <div class="section"> <h3 class="title-3">Prerequisites</h3> <p>Wing Pro's <tt class="literal"><span class="pre">Packages</span></tt> tool (in the <tt class="literal"><span class="pre">Tools</span></tt> menu) can work with Python environments that are managed by pip, pipenv, or conda. Regardless of which one is used, Wing assumes that pip is available in your selected Python installation. This is almost always the case in modern Python versions, or use <a class="reference" href="https://github.com/pypa/get-pip">getpip.py</a> to install it.</p> <p>Before trying Wing's package management features, you will want to set up a new project with a new virtualenv, pipenv, or conda environment and save the project to the top level of your source directory. This way you can experiment with the <tt class="literal"><span class="pre">Packages</span></tt> tool without altering one of your Python environments unexpectedly.</p> <div class="note"> Conda package management will only work from Wing if the base Anaconda installation can be found. See <a class="reference" href="/doc/packages/conda">Package Management with conda</a> for details.</div> </div> <div class="section"> <h3 class="title-3">Viewing Packages</h3> <p>Once your project is saved, Wing should auto-detect which package manager is in use in the Python environment you selected for the project and determine whether a <tt class="literal"><span class="pre">requirements.txt</span></tt> file is in use. A summary of the found Python environment is shown in the <tt class="literal"><span class="pre">Packages</span></tt> tool, along with a list of packages installed into that environment:</p> <img src="https://wingware.com/images/blog/packages/packages.png" alt="/images/blog/packages/packages.png" backrefs="" class="doc-image" dupnames="" height="534px" ids="" names="" width="622px" /></div> <div class="section"> <h3 class="title-3">Managing Packages</h3> <p>To install new packages into your environment, use <tt class="literal"><span class="pre">Install</span> <span class="pre">New</span> <span class="pre">Packages</span></tt> in the <tt class="literal"><span class="pre">Packages</span></tt> tool's <tt class="literal"><span class="pre">Options</span></tt> menu:</p> <img src="https://wingware.com/images/blog/packages/install.png" alt="/images/blog/packages/install.png" backrefs="" class="doc-image" dupnames="" height="202px" ids="" names="" width="383px" /><p>You can remove, update, or set a specific package version by right-clicking on the packages list:</p> <img src="https://wingware.com/images/blog/packages/right-click.png" alt="/images/blog/packages/right-click.png" backrefs="" class="doc-image" dupnames="" height="298px" ids="" names="" width="509px" /><p>Wing runs the appropriate package management operations, updates the package list, and displays any output from the package management command in a console that may be viewed with <tt class="literal"><span class="pre">Show</span> <span class="pre">Console</span></tt> in the <tt class="literal"><span class="pre">Packages</span></tt> tool's <tt class="literal"><span class="pre">Options</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Updating requirements.txt</h3> <p>If you are using pip or conda, Wing can automatically update a <tt class="literal"><span class="pre">requirements.txt</span></tt> that is located in the same directory as your project file or in the <tt class="literal"><span class="pre">Project</span> <span class="pre">Home</span> <span class="pre">Directory</span></tt> configured under the <tt class="literal"><span class="pre">Options</span></tt> tab of <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>.</p> <p>A new <tt class="literal"><span class="pre">requirements.txt</span></tt> file may be created from your current Python environment with <tt class="literal"><span class="pre">Initialize</span> <span class="pre">requirements.txt</span></tt> from the <tt class="literal"><span class="pre">Options</span></tt> menu and later updated with <tt class="literal"><span class="pre">Freeze</span> <span class="pre">to</span> <span class="pre">requirements.txt</span></tt>. If the <tt class="literal"><span class="pre">Auto-Update</span> <span class="pre">requirements.txt</span></tt> item is checked in the <tt class="literal"><span class="pre">Options</span></tt> menu, then the file will automatically be updated after all package management operations run from Wing:</p> <img src="https://wingware.com/images/blog/packages/auto-update.png" alt="/images/blog/packages/auto-update.png" backrefs="" class="doc-image" dupnames="" height="530px" ids="" names="" width="383px" /><p>From here you can also set up your Python environment based on an existing <tt class="literal"><span class="pre">requirements.txt</span></tt> file, with <tt class="literal"><span class="pre">Install</span> <span class="pre">Missing</span> <span class="pre">Packages</span></tt> and <tt class="literal"><span class="pre">Remove</span> <span class="pre">Unused</span> <span class="pre">Packages</span></tt>. This is useful the first time you check out a code base on a new machine, in order to get your Python environment set up quickly.</p> <div class="section"> <h4 class="title-4">Pipenv</h4> <p>If you are using pipenv, <tt class="literal"><span class="pre">Pipfile</span></tt> and <tt class="literal"><span class="pre">Pipfile.lock</span></tt> are used instead of <tt class="literal"><span class="pre">requirements.txt</span></tt>. Wing defers to pipenv to keep the <tt class="literal"><span class="pre">Pipfile</span></tt> up to date as you issue package management commands. You can however refresh the <tt class="literal"><span class="pre">Pipfile.lock</span></tt> file from the <tt class="literal"><span class="pre">Packages</span></tt> tool's <tt class="literal"><span class="pre">Options</span></tt> menu and <tt class="literal"><span class="pre">Install</span> <span class="pre">Missing</span> <span class="pre">Packages</span></tt> can be used to initialize a pipenv environment from <tt class="literal"><span class="pre">Pipfile.lock</span></tt> on a new development machine.</p> </div> </div> <div class="section"> <h3 class="title-3">Conclusion</h3> <p>In most cases, these are all the package management operations you will need in order to set up and manage your Python environment on each development machine.</p> <p>See the <a class="reference" href="/doc/packages/intro">Package Manager</a> documentation for a detailed description of all the available package management features and options. This also describes the quirks of each package management system, some of which you may need to understand in order to use them successfully with Wing.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/packagesSun, 12 Sep 2021 01:00:00 GMTUsing virtualenv, pipenv, and Anaconda environments with Wing Python IDEhttps://wingware.com/hints/environments<p>Last time we looked at how to create projects in Wing. In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> let's look more closely at how to configure your project to use or create Python environments managed by virtualenv, pipenv, or Anaconda.</p> <div class="section"> <h3 class="title-3">Configuring an Existing Project</h3> <p>For an existing Wing project, you can specify an environment as the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> (from the <tt class="literal"><span class="pre">Project</span></tt> menu) in one of two ways:</p> <p><strong>(1)</strong> Select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> and enter the full path to the environments activation script. This is the <tt class="literal"><span class="pre">activate</span></tt> or <tt class="literal"><span class="pre">activate.bat</span></tt> associated with the environment:</p> <img src="https://wingware.com/images/blog/environments/properties.png" alt="/images/blog/environments/properties.png" backrefs="" class="doc-image" dupnames="" height="383px" ids="" names="" width="658px" /><p>The drop down menu next to the entry area lists discovered environments and those which have been used recently:</p> <img src="https://wingware.com/images/blog/environments/recent-envs.png" alt="/images/blog/environments/recent-envs.png" backrefs="" class="doc-image" dupnames="" height="535px" ids="" names="" width="446px" /><p><strong>or (2)</strong> Select <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and enter the full path to the environment's <tt class="literal"><span class="pre">python</span></tt> or <tt class="literal"><span class="pre">python.exe</span></tt>. This executable both activates the env and runs Python, so all the code Wing launches will run in the environment:</p> <img src="https://wingware.com/images/blog/environments/command-line.png" alt="/images/blog/environments/command-line.png" backrefs="" class="doc-image" dupnames="" height="75px" ids="" names="" width="619px" /><p>When in doubt about which path to use, run your environment outside of Wing and inspect the value of <tt class="literal"><span class="pre">sys.executable</span></tt> after <tt class="literal"><span class="pre">import</span> <span class="pre">sys</span></tt>. That is the value you want to use.</p> <p>Activated environments can be used in the same way in other settings where a <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> can be specified, for example for Launch Configurations and in a Remote Host configuration.</p> </div> <div class="section"> <h3 class="title-3">Creating a New Project</h3> <p>There are two options available for environments, when starting a new project from the <tt class="literal"><span class="pre">Project</span></tt> menu: (1) Creating a new enviroment and new Wing project at the same time, or (2) Creating a new Wing project that uses an existing environment.</p> <div class="section"> <h4 class="title-4">Creating a New Environment</h4> <p>To create a new environment along with your project, select <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu, select or create your source directory, and press <tt class="literal"><span class="pre">Next</span></tt>. On the second screen, choose <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Environment</span></tt> and select the type of environment you wish to create. You will then need to enter the name for the environment, select a parent directory, and optionally specify packages to install and/or the base <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to use. For example:</p> <img src="https://wingware.com/images/blog/environments/new-project-new.png" alt="/images/blog/environments/new-project-new.png" backrefs="" class="doc-image" dupnames="" height="432px" ids="" names="" width="600px" /><p>The options to enter vary slightly by type of environment being created. For example, pipenv uses the selected source directory and does not need environment name and parent directory. Also, Anaconda environments require that you install at least one package.</p> <p>When you press <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt>, Wing will create the environment, install packages, and then configure and save a project file. You can immediately start working in your new environment, which Wing automatically activates for you whenever you have the project open.</p> </div> <div class="section"> <h4 class="title-4">Using an Existing Environment</h4> <p>To use an existing virtualenv or Anaconda environment, select <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu, select or create your source directory, and press <tt class="literal"><span class="pre">Next</span></tt>. On the second screen, select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Python</span></tt> and select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> under <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt>. You can then select a recent or found environment from the drop down or manually enter your activation command:</p> <img src="https://wingware.com/images/blog/environments/new-project-existing.png" alt="/images/blog/environments/new-project-existing.png" backrefs="" class="doc-image" dupnames="" height="246px" ids="" names="" width="570px" /><p>To use an existing pipenv, you instead simply select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> in the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog and Wing will auto-detect that this directory already contains a pipenv to use with the project:</p> <img src="https://wingware.com/images/blog/environments/new-project-existing-pipenv.png" alt="/images/blog/environments/new-project-existing-pipenv.png" backrefs="" class="doc-image" dupnames="" height="281px" ids="" names="" width="471px" /><p>In this case, Wing immediately displays the <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt> button and will use that pipenv with your project.</p> </div> </div> <div class="section"> <h3 class="title-3">Notes</h3> <p>Once your project has been set up, you can use the <tt class="literal"><span class="pre">Packages</span></tt> tool in the <tt class="literal"><span class="pre">Tools</span></tt> menu to add, remove, or upgrade packages in your Python environment. We'll describe this in more details the next Wing Tip, or see <a class="reference" href="/doc/packages/intro">Package Manager</a> for details.</p> <p>For some additional details on each type of environment, see <a class="reference" href="/doc/howtos/virtualenv">Using Wing with virtualenv</a>, <a class="reference" href="/doc/howtos/pipenv">Using Wing with pipenv</a>, and <a class="reference" href="/doc/howtos/anaconda">Using Wing with Anaconda</a>.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/environmentsSat, 11 Sep 2021 01:00:00 GMTCreating a Project for an Existing Code Basehttps://wingware.com/hints/create-project<p>Wing 8 introduced some improvements and new capabilities for the project creation process. In this <a class="reference" href="/hints">Wing Tip</a>, we'll take a look at the options available during project creation in Wing Pro.</p> <div class="note"> Note that Wing Personal also has the concept of projects, but omits support for remote development, cloning from revision control repositories, creating Python environments with the project, and support for specific third party packages and tools like Django, Flask, Jupyter, Docker, pipenv, and others. As a result, many of the options described below are not available in Wing Personal.</div> <div class="section"> <h3 class="title-3">Selecting Directory and Project Type</h3> <p>New projects are created with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. This displays a dialog that allows you to select the source code to use with the new project and to select or configure the Python environment you plan to use:</p> <img src="https://wingware.com/images/blog/create-project/new-project.png" alt="/images/blog/create-project/new-project.png" backrefs="" class="doc-image" dupnames="" height="279px" ids="" names="" width="525px" /><p>From here it's possible to create an entirely blank project, which you can configure later, or you can set up your project with an existing source directory or create a new source directory along with the project.</p> <p>Note that you can create a project for remote development here, but for now ignore this option and leave <tt class="literal"><span class="pre">Host</span></tt> set to <tt class="literal"><span class="pre">Local</span> <span class="pre">Host</span></tt>. We'll talk about remote development in future Wing Tips.</p> <div class="section"> <h4 class="title-4">Using an Existing Directory</h4> <p>If you already have a Python code base you want to use with Wing, select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> and choose the directory to use:</p> <img src="https://wingware.com/images/blog/create-project/existing-dir.png" alt="/images/blog/create-project/existing-dir.png" backrefs="" class="doc-image" dupnames="" height="370px" ids="" names="" width="525px" /></div> <div class="section"> <h4 class="title-4">Creating a New Directory</h4> <p>If you are starting a new project from scratch, select <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Directory</span></tt> and enter the directory name, parent directory, optionally select a revision control repository to clone into the new directory (for example, by entering a Github repository url), and select the unit testing framework that you plan to use, if any:</p> <img src="https://wingware.com/images/blog/create-project/new-dir.png" alt="/images/blog/create-project/new-dir.png" backrefs="" class="doc-image" dupnames="" height="449px" ids="" names="" width="525px" /></div> <div class="section"> <h4 class="title-4">Project Type</h4> <p>Whether you're using an existing directory or creating a new one, you will be able to specify a <tt class="literal"><span class="pre">Project</span> <span class="pre">Type</span></tt> from this page of the <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog. If you are using a Python package listed in the <tt class="literal"><span class="pre">Project</span> <span class="pre">Type</span></tt> drop down, select that also. This tells Wing how to configure your project to work properly with your code:</p> <img src="https://wingware.com/images/blog/create-project/project-type.png" alt="/images/blog/create-project/project-type.png" backrefs="" class="doc-image" dupnames="" height="140px" ids="" names="" width="323px" /><p>If your project type is not listed, leave this value set to <tt class="literal"><span class="pre">Custom</span></tt>. In this case, you can opt to ask Wing to configure your project to allow debug processes to be launched from outside of the IDE, for example by a web server or another app. If this will be the case, check on the <tt class="literal"><span class="pre">Use</span> <span class="pre">wingdbstub</span> <span class="pre">for</span> <span class="pre">Debugging</span></tt> option. If you don't yet know how you will launch debug, leave this unchecked. You can always configure this later.</p> </div> </div> <div class="section"> <h3 class="title-3">Selecting a Python Environment</h3> <p>At this point, if you used an existing source directory, Wing looks in the directory for a Python environment managed by pipenv or virtualenv and pip. If it finds one, it will use that with the new project and you can simply press the <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt> button.</p> <p>Otherwise, press <tt class="literal"><span class="pre">Next</span></tt> to select or configure a Python environment for the project.</p> <p>You can then either use an existing Python environment with your project or create a new one. If you already have a Python environment to use, select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Python</span></tt>:</p> <img src="https://wingware.com/images/blog/create-project/existing-env.png" alt="/images/blog/create-project/existing-env.png" backrefs="" class="doc-image" dupnames="" height="250px" ids="" names="" width="686px" /><p>You can specify the Python to use by selecting the default Python, entering a custom command line that invokes Python, selecting an activated environment, or setting up a container or cluster environment. The latter two options will be described in future Wing Tips.</p> <p>The <tt class="literal"><span class="pre">Use</span> <span class="pre">default</span></tt> option causes Wing to use the Python that is run from the command line or the latest found version if Python is not on the <tt class="literal"><span class="pre">PATH</span></tt>.</p> <p><tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> is used to specify the full path command line that invokes Python. For <tt class="literal"><span class="pre">virtualenv</span></tt> and <tt class="literal"><span class="pre">pipenv</span></tt> this can be the <tt class="literal"><span class="pre">python</span></tt> or <tt class="literal"><span class="pre">python.exe</span></tt> executable that is found in the environment.</p> <p><tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> is used to specify the activation command for an existing Python environment. Wing runs this command and then starts Python within the env.</p> <p>Both the <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> options provide a drop down that lists all the found Python installations and environments Wing was able to find on your system.</p> </div> <div class="section"> <h3 class="title-3">Creating a Python Environment</h3> <p>Another option is to create a new Python environment along with your project. This is done by selecting <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">Environment</span></tt> on the second <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> screen and then choosing the type of environment to create:</p> <img src="https://wingware.com/images/blog/create-project/new-env.png" alt="/images/blog/create-project/new-env.png" backrefs="" class="doc-image" dupnames="" height="427px" ids="" names="" width="653px" /><p>Wing can create environments managed by Anaconda, Docker, pipenv, and virtualenv with pip. The options entered for each of these differ. We'll describe this in more detail in the next Wing Tip or take a look at these links for more information: <a class="reference" href="/doc/howtos/anaconda">Anaconda</a> | <a class="reference" href="/doc/howtos/docker">Docker</a> | <a class="reference" href="/doc/howtos/pipenv">pipenv</a> | <a class="reference" href="/doc/howtos/virtualenv">virtualenv</a></p> </div> <div class="section"> <h3 class="title-3">Finishing Up</h3> <p>Once your Python environment has been selected or configured, press <tt class="literal"><span class="pre">Create</span> <span class="pre">Project</span></tt> and Wing will show a progress dialog as it creates and configures everything.</p> <p>As part of this process, Wing saves the project automatically if you created a new source directory. Otherwise, you will need to save the project, which is typically best done to the top level of your project source tree.</p> <br> <br><p>That's it for now! We'll be back next week to continue this <a class="reference" href="/hints">Wing Tips</a> mini-series on navigating Python code with Wing.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/create-projectFri, 10 Sep 2021 01:00:00 GMTMultiple Selections in Wing Python IDEhttps://wingware.com/hints/multiselection<p>In this issue of <a class="reference" href="/hints">Wing Tips</a> we look at how to use multiple concurrent selections in Wing's editor. These can be used to replace all occurrences of some text or to apply the same edits to any number of selections, for example surround them all with quotes or remove common surrounding characters. Multiple selections can be created from the keyboard, from the mouse, or by using commands that select all occurrences of some text found within a selected code.</p> <div class="section"> <h3 class="title-3">Creating Multiple Selections</h3> <p>The most common way to make multiple selections is to select a range of text in Wing's editor and then add other occurrences of the same text with <tt class="literal"><span class="pre">Add</span> <span class="pre">Selection</span> <span class="pre">for</span> <span class="pre">Next</span> <span class="pre">Occurrence</span></tt> in the <tt class="literal"><span class="pre">Edit</span> <span class="pre">&gt;</span> <span class="pre">Multiple</span> <span class="pre">Selections</span></tt> menu. The default key binding for this is <tt class="literal"><span class="pre">Ctrl-D</span></tt>, or <tt class="literal"><span class="pre">Command-D</span></tt> on macOS, and <tt class="literal"><span class="pre">Ctrl-&gt;</span></tt> in the emacs keyboard personality.</p> <p>Another way to add selections is to click on the multi-selection toolbar item <img src="https://wingware.com/images/doc/en/icons/wingide-multiple-selections.png" alt="toolbaritem" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" />. This menu includes items to select all occurrences in a file, class, function/method, or block of code:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-menu.png" alt="/images/blog/multi-selection/multi-select-menu.png" backrefs="" class="doc-image" dupnames="" height="333px" ids="" names="" width="335px" /></div> <div class="section"> <h3 class="title-3">Editing Selections</h3> <p>Once the selections are made your edits will be applied to all of them in the same way, as in the following example which replaces all occurrences of the word &quot;stocks&quot; with &quot;trades&quot;:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-1.gif" alt="/images/blog/multi-selection/multi-select-1.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Edits applied to all selections may include cursor movement, pasting, and other editing actions. For example selecting a number of commas, pressing the right arrow key, and then <tt class="literal"><span class="pre">Space</span></tt> adds a space after all the commas:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-2.gif" alt="/images/blog/multi-selection/multi-select-2.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Multi-Selecting with the Mouse</h3> <p>Multiple selections can also be made by clicking or double-clicking the mouse while holding <tt class="literal"><span class="pre">Ctrl-Alt</span></tt> (or <tt class="literal"><span class="pre">Option-Command</span></tt> on macOS). This allows selecting ranges that don't necessarily contain the same text:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-3.gif" alt="/images/blog/multi-selection/multi-select-3.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Omitting Selections</h3> <p>By default, Wing displays a floating window that enumerates the selection made. You can omit selections from here by moving the mouse over an item and clicking on the red <tt class="literal"><span class="pre">X</span></tt> icon that appears over it. Edits made subsequently are applied only to the selections that remain:</p> <img src="https://wingware.com/images/blog/multi-selection/multi-select-4.gif" alt="/images/blog/multi-selection/multi-select-4.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Configuration Options</h3> <p>Whether occurrences used for multi-selection match any text or only whole words, and whether they are case sensitive, may be controlled from the <tt class="literal"><span class="pre">Edit</span> <span class="pre">&gt;</span> <span class="pre">Multiple</span> <span class="pre">Selections</span></tt> menu or the multi-selection toolbar item <img src="https://wingware.com/images/doc/en/icons/wingide-multiple-selections.png" alt="toolbaritem" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" />.</p> <p>The multi-selection popup window can also be entirely enabled or disabled from here, with the <tt class="literal"><span class="pre">Configure</span> <span class="pre">Selections</span> <span class="pre">Window</span></tt> item.</p> <br> <br><p>That's it for now! We'll be back next week with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> </div> https://wingware.com/hints/multiselectionThu, 01 Oct 2020 01:00:00 GMTExtend Microsoft Excel with Python Using Wing and PyXLLhttps://wingware.com/hints/pyxll<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to use Wing and <a class="reference" href="https://www.pyxll.com">PyXLL</a> to develop and debug Microsoft Excel add-ins that are written in Python. PyXLL is a commercial product that embeds Python into Microsoft Excel on Windows. It allows you to expose Python code to Excel as worksheet functions, macros, menus, and ribbon toolbars.</p> <div class="section"> <h3 class="title-3">Install PyXLL</h3> <p>Before getting started you will need to install Microsoft Excel, <a class="reference" href="https://python.org/">Python</a> or <a class="reference" href="https://www.anaconda.com">Anaconda</a>, <a class="reference" href="https://wingware.com/">Wing</a>, and <a class="reference" href="https://www.pyxll.com/download.html">PyXLL</a> if you don't already have them.</p> <p><strong>Important:</strong> Excel, PyXLL and Python all need to be either 32 bit or 64 bit and can't be mixed. To find out what version of Excel you have see <a class="reference" href="https://support.pyxll.com/hc/en-gb/articles/360036821613-Do-I-have-32-bit-or-64-bit-Excel-">Do I have 32 bit or 64 bit Excel?</a> You will also need to match the version of PyXLL that you download to your Python version.</p> <p>To install PyXLL, unzip the download and then edit the included <tt class="literal"><span class="pre">pyxll.cfg</span></tt> and set <tt class="literal"><span class="pre">executable</span></tt> to the full path of your Python executable. This can be a <tt class="literal"><span class="pre">python.exe</span></tt> from a virtualenv or conda env, or a base Python install. For example:</p> <pre class="literal-block"> [PYTHON] executable = C:\Users\joebloggs\Anaconda\envs\py38\python.exe </pre> <p>Next, install the PyXLL add-in into Excel. To do that, open Excel and select the <tt class="literal"><span class="pre">File</span></tt> menu. Navigate to <tt class="literal"><span class="pre">Options</span></tt>, then <tt class="literal"><span class="pre">Add-Ins</span></tt>, and click the <tt class="literal"><span class="pre">Manage</span> <span class="pre">Excel</span> <span class="pre">Add-Ins</span></tt> button. Select <tt class="literal"><span class="pre">Browse</span></tt>, navigate to the folder where you unzipped the PyXLL download, and select the <tt class="literal"><span class="pre">pyxll.xll</span></tt> file. If Excel asks if you want to copy the add-in to your add-ins folder, select <tt class="literal"><span class="pre">No</span></tt> as you want to leave it where it is. The PyXLL add-in should now appear in your list of loaded add-ins.</p> <p>If you're having trouble installing the add-in, check the PyXLL log file located in the <tt class="literal"><span class="pre">logs</span></tt> folder where you unzipped PyXLL. You can change the log level to <tt class="literal"><span class="pre">debug</span></tt> in your <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file to obtain more detailed logging. If you get stuck contact the <a class="reference" href="https://www.pyxll.com/contact.html">PyXLL support team</a> who will help you get started.</p> <p>You can also find more detailed installation instructions in <a class="reference" href="https://www.pyxll.com/docs/userguide/installation.html">Installing the PyXLL Excel Add-In</a>.</p> </div> <div class="section"> <h3 class="title-3">Create a Wing Project</h3> <p>Next create a new project in Wing with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">Project</span></tt> menu. Select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Directory</span></tt> and select the directory where you installed PyXLL and set <tt class="literal"><span class="pre">Project</span> <span class="pre">Type</span></tt> to <tt class="literal"><span class="pre">PyXLL</span></tt>.</p> <p>After pressing <tt class="literal"><span class="pre">Next</span></tt>, select <tt class="literal"><span class="pre">Use</span> <span class="pre">Existing</span> <span class="pre">Python</span></tt>, set <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and enter the same Python used as the <tt class="literal"><span class="pre">executable</span></tt> in <tt class="literal"><span class="pre">pyxll.cfg</span></tt> above:</p> <img src="https://wingware.com/images/blog/pyxll/new-project.png" alt="/images/blog/pyxll/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="650px" /><p>Now you can submit the dialog and Wing will create and configure your new project.</p> </div> <div class="section"> <h3 class="title-3">Write an Excel Function With PyXLL</h3> <p>Before we look at setting up Wing's debugger, let's write an Excel function to debug. This example uses pandas and numpy, so you will need to make sure those are installed into the Python you configured above. If you are using Anaconda, then you should already have them. In other cases, this can be done with pip. For example:</p> <pre class="literal-block"> C:\Users\joebloggs\Anaconda\envs\py38\python.exe -m pip install pandas numpy </pre> <p>Now create a Python module for your Excel function by creating a new directory on disk and placing a Python file into that directory, with the following contents:</p> <div class="python-highlight"><pre><span></span><span class="kn">from</span> <span class="nn">pyxll</span> <span class="kn">import</span> <span class="n">xl_func</span> <span class="kn">import</span> <span class="nn">pandas</span> <span class="kn">as</span> <span class="nn">pd</span> <span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span> <span class="nd">@xl_func</span><span class="p">(</span><span class="s2">&quot;int, int: dataframe&lt;index=True&gt;&quot;</span><span class="p">,</span> <span class="n">auto_resize</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> <span class="k">def</span> <span class="nf">random_dataframe</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="p">):</span> <span class="sd">&quot;&quot;&quot;</span> <span class="sd"> Creates a DataFrame of random numbers.</span> <span class="sd"> :param rows: Number of rows to create the DataFrame with.</span> <span class="sd"> :param columns: Number of columns to create the DataFrame with.</span> <span class="sd"> &quot;&quot;&quot;</span> <span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="p">)</span> <span class="n">column_names</span> <span class="o">=</span> <span class="p">[</span><span class="nb">chr</span><span class="p">(</span><span class="nb">ord</span><span class="p">(</span><span class="s1">&#39;A&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span><span class="p">)</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">columns</span><span class="p">)]</span> <span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="o">.</span><span class="n">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">column_names</span><span class="p">)</span> <span class="k">return</span> <span class="n">df</span> </pre></div> <p>The directory and filenames can be anything, but in this example we'll use <tt class="literal"><span class="pre">C:\Users\joebloggs\Projects\PyXLL\src</span></tt> for the directory and <tt class="literal"><span class="pre">xlfuncs.py</span></tt> as the file name.</p> <p>Next update the <tt class="literal"><span class="pre">pythonpath</span></tt> and <tt class="literal"><span class="pre">modules</span></tt> setting in the same <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file where you set <tt class="literal"><span class="pre">executable</span></tt> earlier:</p> <pre class="literal-block"> [PYTHON] pythonpath = C:\Users\joebloggs\Projects\PyXLL\src [PYXLL] modules = xlfuncs </pre> <p>Note that the entry under modules omits the <tt class="literal"><span class="pre">.py</span></tt> in the filename.</p> <p>Once this is done, reload the PyXLL add-in via the PyXLL ribbon tool bar or the add-ins menu in Excel, or restart Excel. PyXLL can also be configured to auto-reload after any change made to the Python code. See <a class="reference" href="https://www.pyxll.com/docs/userguide/reloading.html">Reloading</a> in the PyXLL guide for details.</p> <div class="section"> <h4 class="title-4">How it Works</h4> <p>As you may already have figured out, the example Excel function <tt class="literal"><span class="pre">random_dataframe</span></tt> given above creates a pandas <tt class="literal"><span class="pre">DataFrame</span></tt> containing random data, and returns that to Excel as an array function.</p> <p>The <tt class="literal"><span class="pre">&#64;xl_func</span></tt> decorator tells PyXLL to use it as an Excel worksheet function. The first argument to the decorator is an optional function signature. PyXLL uses this to determine how arguments and return values should be converted between the Excel and Python data types. The example here uses the <tt class="literal"><span class="pre">dataframe</span></tt> return type to tell PyXLL to expand the pandas <tt class="literal"><span class="pre">DataFrame</span></tt> to an array of values when returning to Excel, including the index. The <tt class="literal"><span class="pre">auto_resize</span></tt> option tells PyXLL that the Excel formula should be resized automatically to fit the size of the returned array.</p> <div class="note"> <strong>Tip:</strong> In order for Wing to recognise the <tt class="literal"><span class="pre">&#64;xl_func</span></tt> decorator as a valid defined symbol, you will need to install the <tt class="literal"><span class="pre">.whl</span></tt> file included in the PyXLL download using <tt class="literal"><span class="pre">pip</span> <span class="pre">install</span></tt> followed by the full path of the <tt class="literal"><span class="pre">.whl</span></tt> file. You can also invoke pip with the <tt class="literal"><span class="pre">-m</span></tt> command line argument for Python, as shown above for installation of pandas and numpy.</div> </div> </div> <div class="section"> <h3 class="title-3">Invoke the PyXLL Function</h3> <p>Now you should be able to call the <tt class="literal"><span class="pre">random_dataframe</span></tt> function from Excel by entering it as a formula in an Excel worksheet. This is done in the same way as Excel's standard functions by using <tt class="literal"><span class="pre">=</span></tt> followed by the function name, for example <tt class="literal"><span class="pre">=random_dataframe(10,</span> <span class="pre">10)</span></tt>:</p> <img src="https://wingware.com/images/blog/pyxll/random-dataframe.gif" alt="Enter random DataFrame into Excel" backrefs="" caption="Shown Above: Type &quot;=random_dataframe(10,10)&quot; and press Enter to insert a random DataFrame into Excel" class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown Above: Type "=random_dataframe(10,10)" and press Enter to insert a random DataFrame into Excel</i></p><p>For complete instructions on writing Excel worksheet functions in Python with PyXLL, please see <a class="reference" href="https://www.pyxll.com/docs/userguide/udfs/introduction.html">Worksheet Functions</a> in the PyXLL user guide.</p> </div> <div class="section"> <h3 class="title-3">Set up Wing's Debugger</h3> <p>To enable debugging, you need to tell Wing to accept connections from Python code running under Excel and then configure and load the debugger into Excel. To do this from the project you created earlier, click on the bug icon in the lower left of Wing's window, and check <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt>:</p> <img src="https://wingware.com/images/blog/pyxll/accept-debug-connections.jpg" alt="Accept Debug Connections" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Now hovering your mouse over the bug icon should show that Wing is listening for externally initiated debug connections on the local host:</p> <img src="https://wingware.com/images/blog/pyxll/listening-for-connections.jpg" alt="Listening for Connections" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>If Wing is not listening, it may be that it has not been allowed to do so by Windows. In that case, try restarting Wing so that Windows will prompt you to allow network connections.</p> <p>Next, find the <tt class="literal"><span class="pre">Install</span> <span class="pre">Directory</span></tt> listed in the <tt class="literal"><span class="pre">About</span></tt> box accessed from the <tt class="literal"><span class="pre">Help</span></tt> menu in Wing. Copy <tt class="literal"><span class="pre">wingdbstub.py</span></tt> from that directory to the directory that contains <tt class="literal"><span class="pre">xlfuncs.py</span></tt>.</p> <p>Then open your copy of <tt class="literal"><span class="pre">wingdbstub.py</span></tt> and make the following changes:</p> <blockquote> <div class="ordered-list"><ul><li><span class="bullet"> Make sure <tt class="literal"><span class="pre">WINGHOME</span></tt> is set to the full path of your Wing installation, where you just found <tt class="literal"><span class="pre">wingdbstub.py</span></tt>. This is usually set automatically during installation of the IDE.</span></li> <li><span class="bullet"> Change the value of <tt class="literal"><span class="pre">kEmbedded</span></tt> to <tt class="literal"><span class="pre">1</span></tt>. This alters some aspects of how code is debugged, to match the environment your Python code will be running in.</span></li> </ul></div></blockquote> <p>To get Excel to load Wing's debugger, add <tt class="literal"><span class="pre">wingdbstub</span></tt> to the modules list in your <tt class="literal"><span class="pre">pyxll.cfg</span></tt> file:</p> <pre class="literal-block"> [PYXLL] modules = wingdbstub xlfuncs </pre> <p>Finally, restart Excel or reload the PyXLL add-in. When the <tt class="literal"><span class="pre">wingdbstub</span></tt> module is loaded it will connect to Wing and the bug icon in the lower left of Wing's window will turn green, in order to let you know that the debugger is connected:</p> <img src="https://wingware.com/images/blog/pyxll/connected-to-excel.jpg" alt="Connected to Excel" backrefs="" class="doc-image" dupnames="" ids="" names="" /></div> <div class="section"> <h3 class="title-3">Debugging Python Code Invoked from Excel</h3> <p>You can now step through the Python code running in Excel.</p> <p>To try it out, set a breakpoint in <tt class="literal"><span class="pre">xlfuncs.py</span></tt> by opening it in Wing and clicking on the leftmost margin next to the the line that reads <tt class="literal"><span class="pre">data</span> <span class="pre">=</span> <span class="pre">np.random.rand(rows,</span> <span class="pre">columns)</span></tt> within <tt class="literal"><span class="pre">random_dataframe</span></tt>. When you call the function from Excel, the debugger will stop on the breakpoint:</p> <img src="https://wingware.com/images/blog/pyxll/debugging-excel.gif" alt="Debugging Excel" backrefs="" caption="Shown Above: Enter &quot;random_dataframe(10,10)&quot; into Excel on the left, reach a breakpoint in Wing on the right, and step through code" class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown Above: Enter "random_dataframe(10,10)" into Excel on the left, reach a breakpoint in Wing on the right, and step through code</i></p><p>From here, you can inspect your debug process in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> (Wing Pro only) or <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt> in Wing's <tt class="literal"><span class="pre">Tools</span></tt> menu, set other breakpoints or conditional breakpoints (Wing Pro only), step through code, and so forth. For more information on the capabilities of Wing's debugger, see the <a class="reference" href="/doc/howtos/quickstart">Debugger Quick Start</a> or the <tt class="literal"><span class="pre">Tutorial</span></tt> in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems, have any questions, or have topic suggestions for future Wing Tips!</p> </div> https://wingware.com/hints/pyxllWed, 24 Jun 2020 01:00:00 GMTConfiguring Wing's Python Debugger for Your Code Basehttps://wingware.com/hints/debug-overview<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> provides a roadmap to the configuration options available for <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a>'s debugger, to make it easier to understand the available possibilities and how these can be applied to your development projects.</p> <p><strong>In short:</strong> Wing can develop and debug just about any kind of Python code, regardless of whether is resides locally or on a remote host, on a container or cluster, whether it's launched by the IDE from from the outside, and whether it is asynchronous, threaded, or runs in multiple processes. Read on for the details.</p> <div class="section"> <h3 class="title-3">Configuration Options</h3> <p>Broadly speaking there are six ways to configure Wing's debugger:</p> <p><strong>Local Stand-Alone Code</strong> -- Wing can debug stand-alone scripts and applications that run on your local machine and that are launched on demand from within Wing. This development approach can be used for anything that is convenient to launch from the IDE, including scripts, desktop apps, and most web frameworks. See the <a class="reference" href="/doc/debug/quick-start">Debugger Quick-Start</a> for a quick introduction to this simple case.</p> <p><strong>Remote Stand-Alone Code</strong> -- <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> can also debug stand-alone code running on a remote host, virtual machine or device, in the same way as it debugs locally running code. Wing uses a remote agent launched by SSH in order to work directly with files stored on the remote host, as if Wing were itself running on that system. For details, see <a class="reference" href="/hints/remote-dev-2">Remote Development with Wing Pro</a>.</p> <p><strong>Container and Cluster Code</strong> -- <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> can debug code that runs on a container like those hosted by Docker or LXC/LXD, or clusters hosted by Docker Compose. In this case, editing, version control, and search operate files stored on your local disk, but code is transparently executed and debugged in the context of a container instance. For details, see <a class="reference" href="https://wingware.com/doc/proj/container-intro">Working with Containers and Clusters</a>.</p> <p><strong>Local Externally Launched or Embedded Code</strong> -- Wing can debug locally running code that is launched by a web server or framework, embedded Python code that is used to script a larger application, and any other Python code that cannot be directly launched from the IDE. In this case, the code is started from outside of Wing and connects to the IDE by importing Wing's debugger. Debug can be controlled from the IDE and through an API accessible from the debug process. For details, see <a class="reference" href="/doc/debug/debugging-externally-launched-code">Debugging Externally Launched Code</a></p> <p><strong>Remote Externally Launched or Embedded Code</strong> -- <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> can also debug externally launched or embedded code that is running on a remote system. In this case, Wing uses a remote agent to access the remote host via SSH and the debugged code imports Wing's debugger in order to connect back to the IDE through an automatically established reverse SSH tunnel. See <a class="reference" href="/doc/debug/remote-debugging">Debugging Externally Launched Remote Code</a> for brief instructions or <a class="reference" href="/doc/howtos/debugging-web-remote">Remote Web Development</a> for a more detailed guide.</p> <p><strong>Manually Configured Remote Debugging</strong> -- For remote hosts and devices that are not accessible through SSH, or where Wing's remote agent cannot be run, Wing provides a manual configuration option to make debugging on these systems possible. In this case, the device must be able to connect to the host where Wing is running via TCP/IP, and there must be some file sharing configuration so files are available both locally and on the remote system. In this approach, connectivity, file sharing, and other configuration needed to make debugging possible is accomplished entirely manually, so it can be tailored to unusual custom environments. For details, see <a class="reference" href="/doc/debug/manual-remote-debugging">Manually Configured Remote Debugging</a>.</p> </div> <div class="section"> <h3 class="title-3">VirtualEnv, pipenv, and Anaconda Environments</h3> <p>In context of the above , Wing may be used with or without an environment created by <tt class="literal"><span class="pre">virtualenv</span></tt>, <tt class="literal"><span class="pre">pipenv</span></tt>, or Anaconda's <tt class="literal"><span class="pre">conda</span> <span class="pre">create</span></tt>.</p> <p>Environments can be created with your Wing project as described in <a class="reference" href="/doc/proj/creating-python-envs">Creating Python Environments</a>.</p> <p>Alternatively, environments may be selected after the fact. For local debugging, this is done by setting the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt>. For remote debugging, it is set in the remote host configuration.</p> <p>For <tt class="literal"><span class="pre">virtualenv</span></tt> and <tt class="literal"><span class="pre">pipenv</span></tt>, you can either set the <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> to <tt class="literal"><span class="pre">Command</span> <span class="pre">Line</span></tt> and enter the full path to the virtualenv's Python, or you can select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> and enter the command that activates the environment. See <a class="reference" href="/doc/howtos/virtualenv">Using Wing with virtualenv</a> and <a class="reference" href="/doc/howtos/pipenv">Using Wing with pipenv</a> for details.</p> <p>For Anaconda environments, you must select <tt class="literal"><span class="pre">Activated</span> <span class="pre">Env</span></tt> and then choose the environment from the drop down list to the right of this field. See <a class="reference" href="/doc/howtos/anaconda">Using Wing with Anaconda</a> for details.</p> <div class="note"> If you are working with containers or clusters, Wing uses the environment set up and managed by the container. See <a class="reference" href="/doc/proj/container-intro">Working with Containers and Clusters</a>, <a class="reference" href="/doc/howtos/docker">Using Wing with Docker</a>, and <a class="reference" href="/doc/howtos/lxc">Using Wing with LXC/LXD</a> for details.</div> </div> <div class="section"> <h3 class="title-3">Specific Frameworks and Tools</h3> <p>Some frameworks and tools require some additional custom configuration to make them easy to work with in Wing. In addition to understanding the general options explained above, it is a good idea to seek out configuration details for the frameworks and tools that you use:</p> <div class="bullet-list"><ul><li><span class="bullet"> Wing's documentation contains configuration instructions for specific frameworks and tools such as <a class="reference" href="/doc/howtos/flask">Flask</a>, <a class="reference" href="/doc/howtos/django">Django</a>, <a class="reference" href="/doc/howtos/jupyter">Jupyter</a>, <a class="reference" href="/doc/howtos/wxpython">wxPython</a>, <a class="reference" href="/doc/howtos/pyqt">PyQt</a>, <a class="reference" href="/doc/howtos/blender">Blender</a>, <a class="reference" href="/doc/howtos/maya">Maya</a>, and <a class="reference" href="/doc/howtos">others</a>.</span></li> <li><span class="bullet"> There is also additional information available for specific kinds of remote development for <a class="reference" href="/doc/howtos/aws">AWS</a>, <a class="reference" href="/doc/howtos/docker">Docker</a>, <a class="reference" href="/doc/howtos/vagrant">Vagrant</a>, <a class="reference" href="/doc/howtos/wsl">Windows Subsystem for Linux</a>, <a class="reference" href="/doc/howtos/raspberry">Raspberry Pi</a>, and <a class="reference" href="/doc/howtos">others</a>.</span></li> </ul></div><p>The <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> dialog accessed from the <tt class="literal"><span class="pre">Project</span></tt> menu provides some assistance for setting up new Wing projects for most of these.</p> </div> <div class="section"> <h3 class="title-3">Multi-threaded and Multi-process Debugging</h3> <p>Wing automatically debugs any multi-threaded code without any additional configuration.</p> <p>Multi-process code can also be debugged but requires turning on the <tt class="literal"><span class="pre">Debug/Execute</span> <span class="pre">&gt;</span> <span class="pre">Debug</span> <span class="pre">Child</span> <span class="pre">Processes</span></tt> option in <tt class="literal"><span class="pre">Project</span> <span class="pre">Properties</span></tt> before child processes are automatically debugged. In this case, you may also want to configure specific options for how Wing handles and terminates child processes. See <a class="reference" href="/doc/debug/multiprocess">Multi-Process Debugging</a> for details.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/debug-overviewThu, 04 Jun 2020 01:00:00 GMTConditional Breakpoints Wing Pro's Python Debuggerhttps://wingware.com/hints/conditional-breakpoints<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to use conditional breakpoints in <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a> to stop in Python code only when certain conditions are true. This is useful for isolating a single case out of many that may be processed by the same code in a particular run, in order to investigate how that case is being handled.</p> <p>Conditional breakpoints are also a great way to select the runtime state for which you want to write new Python code, with the ability to immediately try out what you write.</p> <div class="section"> <h3 class="title-3">Use Conditional Breakpoints in Debugging</h3> <p>To set a conditional breakpoint, right-click on the breakpoint margin in the editor and select <tt class="literal"><span class="pre">Set</span> <span class="pre">Conditional</span> <span class="pre">Breakpoint</span></tt>:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/set-conditional.gif" alt="Set Conditional Breakpoint" backrefs="" caption="Shown above: Right-click on the breakpoint margin to set a conditional breakpoint." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Right-click on the breakpoint margin to set a conditional breakpoint.</i></p><p>Then start debug with <tt class="literal"><span class="pre">Start/Continue</span></tt> in the <tt class="literal"><span class="pre">Debug</span></tt> menu, from the toolbar, or as shown here with <tt class="literal"><span class="pre">Debug</span> <span class="pre">Tests</span></tt> in the <tt class="literal"><span class="pre">Testing</span></tt> tool:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/debug-to-bp.gif" alt="Debug Unit Tests with a Conditional Breakpoint" backrefs="" caption="Shown above: Select a set of unit tests and debug them to reach the conditional breakpoint, then run to the next hit, step over a few lines, and press Shift-Space to view the value of all visible variables." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Select a set of unit tests and debug them to reach the conditional breakpoint, then run to the next hit, step over a few lines, and press Shift-Space to view the value of all visible variables.</i></p></div> <div class="section"> <h3 class="title-3">Use Conditional Breakpoints to Write New Code</h3> <p>Since Wing lets you stop at breakpoints to work on new Python code interactively in the live runtime state of the debug process, conditional breakpoints are also a great way to select the specific runtime case for which you want to write new code. You'll have access to auto-completion that works off the actual runtime state, and can try your code right away in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>:</p> <img src="https://wingware.com/images/blog/conditional-breakpoints/interactive.gif" alt="Interactive Development at a Conditional Breakpoint" backrefs="" caption="Shown above: Enter code with auto-completion and auto-editing features that inspect the live runtime state of the debug process, then try out an invocation in the Debug Console." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Enter code with auto-completion and auto-editing features that inspect the live runtime state of the debug process, then try out an invocation in the Debug Console.</i></p><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/conditional-breakpointsWed, 20 May 2020 01:00:00 GMTMoving the Program Counter in Wing's Python Debuggerhttps://wingware.com/hints/move-program-counter2<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> describes how to move the program counter while debugging Python code in Wing Personal and Wing Pro. This is a good way to go back and re-execute previously visited Python code, in order to trace through to the cause of a bug without having to restart the debug process.</p> <p>To move the program counter, the debugger must be running and paused or stopped at a breakpoint. Then right-click on the target line in the editor and select <tt class="literal"><span class="pre">Move</span> <span class="pre">Program</span> <span class="pre">Counter</span> <span class="pre">Here</span></tt>:</p> <img src="https://wingware.com/images/blog/move-program-counter2/move-program-counter.gif" alt="Move Program Counter" backrefs="" caption="Shown above: Right-click to select Move Program Counter Here, then continue stepping with Step Over and Step Into in the toolbar." class="doc-image" dupnames="" ids="" names="" style="padding-bottom:5px;margin-bottom:5px;" /><p style="padding-top:0px;"><i>Shown above: Right-click to select Move Program Counter Here, then continue stepping with Step Over and Step Into in the toolbar.</i></p><p><strong>Limitations:</strong> Due to the way Python is implemented, the program counter can only be moved within the current inner-most stack frame and it may not be moved within an exception handler, after an exception has been raised but not yet handled.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> https://wingware.com/hints/move-program-counter2Tue, 12 May 2020 01:00:00 GMTQuick Navigation to Project Files in Wing Python IDEhttps://wingware.com/hints/open-from-project<p>This <a class="reference" href="https://wingware.com/hints">Wing Tip</a> highlights a simple but useful feature in Wing Personal and Wing Pro that you might have missed up until now: <tt class="literal"><span class="pre">Open</span> <span class="pre">from</span> <span class="pre">Project</span></tt> in the <tt class="literal"><span class="pre">File</span></tt> menu.</p> <p>This is usually accessed with its key binding, <tt class="literal"><span class="pre">Ctrl-Shift-O</span></tt>, or <tt class="literal"><span class="pre">Command-Shift-O</span></tt> on macOS. If you've selected a non-default <tt class="literal"><span class="pre">Keyboard</span> <span class="pre">Personality</span></tt> in the <tt class="literal"><span class="pre">Edit</span></tt> menu, a different key binding may be used. Or, if none is defined for that keyboard setting, you can add a binding for command <tt class="literal"><span class="pre">open-from-project</span></tt> with the <tt class="literal"><span class="pre">User</span> <span class="pre">Interface</span> <span class="pre">&gt;</span> <span class="pre">Keyboard</span> <span class="pre">&gt;</span> <span class="pre">Custom</span> <span class="pre">Key</span> <span class="pre">Bindings</span></tt> preference.</p> <p>Executing the command displays a dialog. Entering a fragment narrows the list to include only matching project files:</p> <img src="https://wingware.com/images/blog/open-from-project/open-from-project.gif" alt="/images/blog/open-from-project/open-from-project.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Matching is on the file name only. However, if the fragment includes the path separator, then the match is applied to the full path of the file, including also enclosing directory names:</p> <img src="https://wingware.com/images/blog/open-from-project/match-full-path.gif" alt="/images/blog/open-from-project/match-full-path.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>Before any fragment is typed, the first few items in the dialog are the most recently opened files. These can be selected quickly with the down arrow and by pressing <tt class="literal"><span class="pre">Enter</span></tt>. Even if a file is already open, using <tt class="literal"><span class="pre">Open</span> <span class="pre">From</span> <span class="pre">Project</span></tt> is often the fastest way to move between different source files.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="https://wingware.com/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> https://wingware.com/hints/open-from-projectWed, 22 Apr 2020 01:00:00 GMTDebug Python Services Running on AWS with Wing Prohttps://wingware.com/hints/aws-2<p>In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we're continuing our look at how to use <a class="reference" href="https://wingware.com/downloads/wing-pro">Wing Pro</a> to remotely develop Python code running on an AWS instance. This time we'll set up remote debugging of code that is launched from outside of the IDE. This can be useful in debugging web apps and other services.</p> <div class="section"> <h3 class="title-3">Prerequisites</h3> <p>Before getting started, you will need an AWS instance that you can SSH into, and you'll want to set up a Wing project for that AWS instance. If you don't already have this working, take a look at last's weeks Wing Tip: <a class="reference" href="/hints/aws-1">Remote Python Development on AWS with Wing Pro</a>.</p> <p>The small debugging example given in the above link launched the remote code being debugged from the IDE. The code actually runs on the AWS instance, but Wing launches it with the help of its remote agent. Now we're instead going to set up debugging remote code that is launched outside of control of the IDE.</p> <p>This is done by (1) using Wing Pro's remote development support to set up a reverse SSH tunnel to the remote AWS instance, so that the debugger can connect back to the IDE, and then (2) inserting an import into code that starts debug and makes the connection to the IDE.</p> </div> <div class="section"> <h3 class="title-3">Setting up Remote Listening</h3> <p>In the project you have set up for your remote AWS instance, click on the bug icon in the lower left of Wing's window to check on <tt class="literal"><span class="pre">Accept</span> <span class="pre">Debug</span> <span class="pre">Connections</span></tt>:</p> <img src="https://wingware.com/images/blog/aws-2/debug-menu.png" alt="/images/blog/aws-2/debug-menu.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="383px" /><p>Now if you hover the mouse over the bug icon, you will see that Wing reports that it is listening for debug connections on the remote host on port <tt class="literal"><span class="pre">50050</span></tt>, as well as listening on the local host:</p> <img src="https://wingware.com/images/blog/aws-2/debug-status.png" alt="/images/blog/aws-2/debug-status.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="781px" /></div> <div class="section"> <h3 class="title-3">Starting Debug</h3> <p>To keep things simple, rather than setting up a web development framework or other service, we'll test with a simple <tt class="literal"><span class="pre">helloworld.py</span></tt> example that we launch manually from the command line outside of Wing.</p> <p>You can create this file on the AWS instance by right-clicking on a directory you previously added to Wing's <tt class="literal"><span class="pre">Project</span></tt> tool and selecting <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">File</span></tt>. This collects the new file name in a dialog or, in some keyboard configurations, in the status area at the bottom of Wing's window, and then opens the file in the editor.</p> <p>Then paste in the following code and save the file:</p> <div class="python-highlight"><pre><span></span><span class="kn">import</span> <span class="nn">wingdbstub</span> <span class="n">x</span> <span class="o">=</span> <span class="mi">1</span> <span class="k">print</span><span class="p">(</span><span class="s2">&quot;Hello&quot;</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span> <span class="n">x</span> <span class="o">+=</span><span class="mi">1</span> <span class="k">print</span><span class="p">(</span><span class="s2">&quot;Goodbye&quot;</span><span class="p">,</span><span class="n">x</span><span class="p">)</span> </pre></div> <p>Notice that the first line <tt class="literal"><span class="pre">import</span> <span class="pre">wingdbstub</span></tt> starts debug and connects to the IDE through the reverse SSH tunnel you set up in the previous section.</p> <p>In order for this to work, you need to copy the automatically preconfigured file <tt class="literal"><span class="pre">~/.wingpro7/remote-#.#.#.#/wingdbstub.py</span></tt> on the remote host (where #.#.#.# is the version of Wing you running) into the same directory as <tt class="literal"><span class="pre">helloworld.py</span></tt>. This can be done by opening the file in Wing and using <tt class="literal"><span class="pre">Save</span> <span class="pre">As</span></tt>. Or just connect to your AWS instance, <tt class="literal"><span class="pre">cd</span></tt> into your target directory, and copy it into place:</p> <pre class="literal-block"> cp ~/.wingpro7/remote-#.#.#.#/wingdbstub.py . </pre> <p>If you are using Lightsail, a convenient way to connect to your instance is <tt class="literal"><span class="pre">Connect</span> <span class="pre">Using</span> <span class="pre">SSH</span></tt> under the <tt class="literal"><span class="pre">Connect</span></tt> tab in the Amazon Lightsail management interface.</p> <p>Finally, set a breakpoint on line 3 of the test code so it will not just run to completion, but instead will stop in Wing's debugger. This is done by clicking on the leftmost margin in the editor:</p> <img src="https://wingware.com/images/blog/aws-2/breakpoint.png" alt="/images/blog/aws-2/breakpoint.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="309px" /><p>Now you can start debug just by launching the test code outside of Wing:</p> <pre class="literal-block"> python3 helloworld.py </pre> <p>The first time you do this, Wing may refuse the connection and ask whether you want to accept the security token for this host. This happens if you installed the remote agent earlier from a different Wing installation:</p> <img src="https://wingware.com/images/blog/aws-2/security-token.png" alt="/images/blog/aws-2/security-token.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="722px" /><p>If this dialog appears, click <tt class="literal"><span class="pre">Accept</span></tt> and then start the test code a second time:</p> <pre class="literal-block"> python3 helloworld.py </pre> <p>This time Wing will accept the connection and should stop on your breakpoint:</p> <img src="https://wingware.com/images/blog/aws-2/stopped.png" alt="/images/blog/aws-2/stopped.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="351px" /><p>From here, you can inspect your debug process in the <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt> or <tt class="literal"><span class="pre">Stack</span> <span class="pre">Data</span></tt>, set other breakpoints or conditional breakpoints, step through code, and so forth. For more information on the capabilities of Wing's debugger, see the <a class="reference" href="/doc/debug/quick-start">Debugger Quick Start</a> or the tutorial in Wing's <tt class="literal"><span class="pre">Help</span></tt> menu.</p> </div> <div class="section"> <h3 class="title-3">Notes</h3> <p>To actually set up Wing to work with a web development framework on your AWS instance, see our How-Tos for <a class="reference" href="/doc/howtos/flask">Flask</a>, <a class="reference" href="/doc/howtos/django">Django</a>, or <a class="reference" href="/doc/howtos/web">other web development frameworks</a>. These explain additional configuration that may be needed in each case.</p> <p>Wing's debugger also provides a simple <a class="reference" href="/doc/debug/debugger-api">debugger API</a> that may be useful, for example in developing a way to turn the debugger on and off on demand or controlling which threads are debugged.</p> <p>For detailed documentation see the <a class="reference" href="/doc/debug/index">Debugger</a> and <a class="reference" href="/doc/debug/advanced">Advanced Debugging Topics</a> chapters in Wing Pro's user manual.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/aws-2Tue, 07 Apr 2020 01:00:00 GMTRemote Python Development on AWS with Wing Prohttps://wingware.com/hints/aws-1<p>In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we'll start looking at how to use <a class="reference" href="https://wingware.com/downloads/wing-pro">Wing Pro</a> to remotely develop Python code running on an AWS instance. With minimal configuration, Wing Pro can edit, debug, test, inspect, and navigate Python code residing on an AWS instance, as if it were on the local host.</p> <div class="section"> <h3 class="title-3">Minimum Requirements</h3> <p>You will need an AWS instance that has Python installed on it, is running 32-bit or 64-bit Intel Linux, and that you can connect to using OpenSSH or PuTTY. PuTTY is recommended on Windows because it tends to be prone to fewer problems. You will need the following in order to configure Wing Pro to use your AWS instance:</p> <p><strong>(1)</strong> The user name and static IP address or DNS name used to connect to the AWS instance. Amazon Lightsail typically uses an IP address while EC2 and other variants of AWS may provide a DNS name as well. The static IP address will work in any case.</p> <p><strong>(2)</strong> The SSH key pair in a <tt class="literal"><span class="pre">*.pem</span></tt> file, as downloaded from AWS.</p> <p>If you do not already have Wing Pro installed, <a class="reference" href="https://wingware.com/downloads/wingpro">download it now</a>.</p> </div> <div class="section"> <h3 class="title-3">Setting up AWS</h3> <p><em>If you already have an AWS instance to work with, you can skip this section.</em></p> <p><a class="reference" href="https://aws.amazon.com/lightsail/">Amazon Lightsail</a> is the easiest way to get an AWS instance, in about 5 minutes. You will need to set up an account. Then create a <tt class="literal"><span class="pre">Linux/Unix</span></tt> instance, selecting the <tt class="literal"><span class="pre">OS</span> <span class="pre">Only</span></tt> option and the most recent <tt class="literal"><span class="pre">Ubuntu</span></tt> or any other Intel Linux with Python 2 or 3 on it.</p> <p>While setting up your instance, you can download your SSH key pair under the AWS <tt class="literal"><span class="pre">SSH</span> <span class="pre">key</span> <span class="pre">pair</span> <span class="pre">manager</span></tt>. You'll need this on your local machine, where Wing is running, in order to be able to connect to the instance.</p> <p>After the instance is created, it will remain in <tt class="literal"><span class="pre">pending</span></tt> state for a minute or so. Once it is up and running, create a static IP address under the <tt class="literal"><span class="pre">Network</span></tt> tab in the AWS Lightsail management area and attach it to your instance.</p> <p>At this point you have all that is needed to start using Wing Pro with AWS: (1) The SSH key pair that you downloaded, and (2) the user name and IP address, which are shown on the Lightsail instance management page.</p> </div> <div class="section"> <h3 class="title-3">Testing the SSH Connection</h3> <p>Before trying to use your new instance from Wing Pro, you should first try to connect using <tt class="literal"><span class="pre">ssh</span></tt> or PuTTY's <tt class="literal"><span class="pre">plink.exe</span></tt> on the command line, to make sure those are working. This is important because Wing invokes those command lines to connect to the instance.</p> <p><strong>OpenSSH</strong></p> <p>On Linux or macOS using <tt class="literal"><span class="pre">ssh</span></tt>, you need to make your <tt class="literal"><span class="pre">*.pem</span></tt> SSH key pair file readable only by the user running Wing, for example with:</p> <pre class="literal-block"> chmod 600 aws.pem </pre> <p>Otherwise, <tt class="literal"><span class="pre">ssh</span></tt> will reject it as potentially compromised.</p> <p>Once that is done, try connecting as follows, substituting the actual path to your downloaded SSH key pair and your instance's username and IP address or DNS name:</p> <pre class="literal-block"> ssh -i /path/to/mykey.pem ubuntu&#64;11.22.33.44 </pre> <p>You will be asked to add the instance's identity to your known hosts file, which you should do by typing <tt class="literal"><span class="pre">yes</span></tt>. If this is not done, <tt class="literal"><span class="pre">ssh</span></tt> will fail to connect and Wing will also not be able to connect to the instance.</p> <p><strong>PuTTY</strong></p> <p>With PuTTY on Windows, you will need to first convert the SSH key to a format that PuTTY can use. This is done by launching <tt class="literal"><span class="pre">puttygen</span></tt>, pressing the <tt class="literal"><span class="pre">Load</span></tt> button to read the <tt class="literal"><span class="pre">*.pem</span></tt> SSH key file you downloaded from the AWS management site, and then using <tt class="literal"><span class="pre">Save</span> <span class="pre">Private</span> <span class="pre">Key</span></tt> to write a <tt class="literal"><span class="pre">*.ppk</span></tt> file.</p> <p>Then you invoke <tt class="literal"><span class="pre">plink.exe</span></tt> to connect to the AWS instance as follows, substituting in the actual path to your downloaded SSH key pair and the correct username and IP address or DNS name for the AWS instance:</p> <pre class="literal-block"> plink.exe -i C:\path\to\mykey.ppk ubuntu&#64;11.22.33.44 </pre> <p>You will be asked to accept the AWS instance's identity the first time you connect, and this must be done before Wing's remote development support will work with the AWS instance.</p> </div> <div class="section"> <h3 class="title-3">Creating a Wing Project</h3> <p>Now you're ready to create a project in Wing Pro. This is done with <tt class="literal"><span class="pre">New</span> <span class="pre">Project</span></tt> from the <tt class="literal"><span class="pre">Project</span></tt> menu. Select <tt class="literal"><span class="pre">Create</span> <span class="pre">Configuration</span></tt> from the <tt class="literal"><span class="pre">Host</span></tt> dropdown. Then choose <tt class="literal"><span class="pre">AWS</span></tt> as the remote host type and enter an identifier for the remote host (any short string to identify it in Wing's UI), and the user name and IP address or DNS name used to connect to the host:</p> <img src="https://wingware.com/images/blog/aws-1/new-project.png" alt="/images/blog/aws-1/new-project.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="716px" /><p>As in the above example, <tt class="literal"><span class="pre">Python</span> <span class="pre">Executable</span></tt> will usually be <tt class="literal"><span class="pre">Use</span> <span class="pre">default</span></tt>, which first tries <tt class="literal"><span class="pre">python3</span></tt> and then <tt class="literal"><span class="pre">python</span></tt>. If Python is not on the <tt class="literal"><span class="pre">PATH</span></tt> on your AWS instance or you want to specify a particular Python executable or activate a virtual environment, you can do this here.</p> <p>You will also need to point Wing at the SSH key pair file you downloaded from AWS earlier. This is done under the <tt class="literal"><span class="pre">Options</span></tt> tab using the <tt class="literal"><span class="pre">Private</span> <span class="pre">Key</span></tt> field as follows:</p> <img src="https://wingware.com/images/blog/aws-1/private-key-file.png" alt="/images/blog/aws-1/private-key-file.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="716px" /><p>Pressing <tt class="literal"><span class="pre">OK</span></tt> in the <tt class="literal"><span class="pre">New</span> <span class="pre">Remote</span> <span class="pre">Host</span></tt> dialog will create your remote configuration and install Wing's remote agent on the AWS instance.</p> <p>Next, you can continue through the project creation process by selecting or creating a source directory, and then optionally creating a new Python environment to use with the project.</p> </div> <div class="section"> <h3 class="title-3">Testing a Hello World</h3> <p>To try out a simple example of editing and debugging code on the remote AWS instance, create a file <tt class="literal"><span class="pre">helloworld.py</span></tt> temporarily on the instance. This is done by right-clicking on one of the files in the <tt class="literal"><span class="pre">Project</span></tt> tool in Wing Pro and selecting <tt class="literal"><span class="pre">Create</span> <span class="pre">New</span> <span class="pre">File</span></tt>. Enter the file name (in some key bindings this is in the data entry area at the bottom of Wing's window) and type or paste the following into the new file:</p> <div class="python-highlight"><pre><span></span><span class="kn">import</span> <span class="nn">time</span> <span class="k">print</span><span class="p">(</span><span class="s2">&quot;Hello World! {}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">time</span><span class="o">.</span><span class="n">time</span><span class="p">()))</span> </pre></div> <p>After saving the file, set a breakpoint on the second line by clicking on the leftmost margin in the editor:</p> <img src="https://wingware.com/images/blog/aws-1/breakpoint.png" alt="/images/blog/aws-1/breakpoint.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="382px" /><p>Then select <tt class="literal"><span class="pre">Starting/Continue</span></tt> from the <tt class="literal"><span class="pre">Debug</span></tt> menu to start debug, or use the green play icon <img src="https://wingware.com/images/doc/en/icons/wingide-debug-continue.png" alt="play" backrefs="" class="inline-image" dupnames="" height="18" ids="" names="" width="18" /> in the toolbar.</p> <p>There is a slight delay to get the process started, depending on your network distance from the AWS instance, but then you should see Wing stop on the breakpoint:</p> <img src="https://wingware.com/images/blog/aws-1/breakpoint-stop.png" alt="/images/blog/aws-1/breakpoint-stop.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="382px" /><p>There's not much to see here, but you can poke around a little in the live runtime state of the paused debug process, using Wing Pro's <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>, from the <tt class="literal"><span class="pre">Tools</span></tt> menu:</p> <img src="https://wingware.com/images/blog/aws-1/debug-console.png" alt="/images/blog/aws-1/debug-console.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="526px" /><p>Once you continue debugging, the process will exit and print to the <tt class="literal"><span class="pre">Debug</span> <span class="pre">I/O</span></tt> tool:</p> <img src="https://wingware.com/images/blog/aws-1/debug-io.png" alt="/images/blog/aws-1/debug-io.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="581px" /><br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/aws-1Tue, 24 Mar 2020 01:00:00 GMTGoto-Definition From the Interactive Shells in Winghttps://wingware.com/hints/goto-definition-in-shells<p>In this <a class="reference" href="https://wingware.com/hints">Wing Tip</a> we'll take a quick look at a lesser-known but often useful feature in Wing: Jumping from symbols in the integrated Python shells to their point of definition in source code. This makes it a snap to bridge from runtime symbols to the source code where they are actually defined and used.</p> <div class="section"> <h3 class="title-3">Debug Console Example</h3> <p>In this example, the debugger is stopped and I'm working in <a class="reference" href="https://wingware.com/download/wingpro">Wing Pro</a>'s <tt class="literal"><span class="pre">Debug</span> <span class="pre">Console</span></tt>, which is an interactive shell that runs in the context of the currently selected debug stack frame. While trying to determine why <tt class="literal"><span class="pre">handler.exit_status</span></tt> is <tt class="literal"><span class="pre">None</span></tt>, I jump to its point of definition from the right-click context menu:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/debug-console.gif" alt="/images/blog/goto-definition-in-shells/debug-console.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>From here, I could set a breakpoint and restart debug, or right-click on the editor to select <tt class="literal"><span class="pre">Find</span> <span class="pre">Points</span> <span class="pre">of</span> <span class="pre">Use</span></tt> to see all the points of use of <tt class="literal"><span class="pre">exit_status</span></tt>.</p> </div> <div class="section"> <h3 class="title-3">Python Shell Example</h3> <p>Similarly, I can import a module in the <tt class="literal"><span class="pre">Python</span> <span class="pre">Shell</span></tt> in Wing Pro or Wing Personal and jump to the point of definition of symbols in the module. Here I'm using this technique to bring up the source code for numpy's <tt class="literal"><span class="pre">ndarray</span></tt>:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/python-shell.gif" alt="/images/blog/goto-definition-in-shells/python-shell.gif" backrefs="" class="doc-image" dupnames="" ids="" names="" /><p>In this case, I'm pressing <tt class="literal"><span class="pre">F4</span></tt> to go to the definition, rather than using the right-click context menu.</p> </div> <div class="section"> <h3 class="title-3">Traversing Visit History</h3> <p>To get back from the point of definition to the previously displayed code in the editor, use the browser-like forward/back arrow buttons in the top left of the editor:</p> <img src="https://wingware.com/images/blog/goto-definition-in-shells/back-arrows.png" alt="/images/blog/goto-definition-in-shells/back-arrows.png" backrefs="" class="doc-image" dupnames="" ids="" names="" width="321px" /><p>Pressing <tt class="literal"><span class="pre">Alt-Left</span></tt> or using any other key binding for the command <tt class="literal"><span class="pre">visit-history-previous</span></tt> also goes back in the editor's visit history.</p> <br> <br><p>That's it for now! We'll be back soon with more <a class="reference" href="/hints">Wing Tips</a> for Wing Python IDE.</p> <p>As always, please don't hesitate to email <a class="reference" href="mailto:support&#64;wingware.com">support&#64;wingware.com</a> if you run into problems or have any questions.</p> </div> https://wingware.com/hints/goto-definition-in-shellsWed, 11 Mar 2020 01:00:00 GMT