Wing Tips: Python Package Management in Wing Python IDE

Sep 12, 2021


Last time we looked at how to configure and create Python environments from Wing Pro. In this Wing Tip we'll take a look at managing your pip, Poetry, pipenv, or conda Python environment from Wing Pro's Packages tool.

Prerequisites

Wing Pro's Packages tool (in the Tools menu) can work with Python environments that are managed by pip, Poetry, 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 getpip.py to install it.

Before trying Wing's package management features, you will want to set up a new project with a new virtualenv, Poetry, pipenv, or conda environment and save the project to the top level of your source directory. This way you can experiment with the Packages tool without altering one of your Python environments unexpectedly.

Conda package management will only work from Wing if the base Anaconda installation can be found. See Package Management with conda for details.

Viewing Packages

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 requirements.txt file is in use. A summary of the found Python environment is shown in the Packages tool, along with a list of packages installed into that environment:

/images/blog/packages/packages.png

Managing Packages

To install new packages into your environment, use Install New Packages in the Packages tool's Options menu:

/images/blog/packages/install.png

You can remove, update, or set a specific package version by right-clicking on the packages list:

/images/blog/packages/right-click.png

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 Show Console in the Packages tool's Options menu.

Updating requirements.txt

If you are using pip or conda, Wing can automatically update a requirements.txt that is located in the same directory as your project file or in the Project Home Directory configured under the Options tab of Project Properties.

A new requirements.txt file may be created from your current Python environment with Initialize requirements.txt from the Options menu and later updated with Freeze to requirements.txt. If the Auto-Update requirements.txt item is checked in the Options menu, then the file will automatically be updated after all package management operations run from Wing:

/images/blog/packages/auto-update.png

From here you can also set up your Python environment based on an existing requirements.txt file, with Install Missing Packages and Remove Unused Packages. 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.

Poetry

If you are using Poetry, Wing defers to Poetry to keep its package management files up to date as you issue package management commands. You can however refresh the Poetry.lock file from the Packages tool's Options menu and Install Missing Packages can be used to initialize a Poetry environment from Poetry.lock on a new development machine.

Pipenv

Similarly, if you are using pipenv, Pipfile and Pipfile.lock are used instead of requirements.txt. Wing defers to pipenv to keep the Pipfile up to date as you issue package management commands. You can however refresh the Pipfile.lock file from the Packages tool's Options menu and Install Missing Packages can be used to initialize a pipenv environment from Pipfile.lock on a new development machine.

Conclusion

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.

See the Package Manager 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.



That's it for now! We'll be back soon with more Wing Tips for Wing Python IDE.

As always, please don't hesitate to email support@wingware.com if you run into problems or have any questions.



Share this article: