12th Feb 2024 9 minutes read Your Perfect Python Setup Alexandre Bruffa get started with python installation guide A good Python setup is the key to efficient and effective Python programming. Find out how to choose and install the right components in this article! A well-configured Python setup is essential for developers at every skill level. Whether you are just starting out with Python or you are a seasoned professional, I highly recommend you invest time learning how to configure and maintain a strong Python environment. The benefits are considerable: it facilitates development workflows, mitigates compatibility issues, enhances performance, and contributes to a collaborative and efficient development process. When you establish a reliable and consistent environment, you can write clean and robust code, collaborate easily, and solve complex development issues with confidence. If you’re completely new to Python, I highly recommend you check the awesome track Learn Programming with Python on LearnPython.com. This track contains 5 of our best-selling courses and tons of coding challenges! Configuring Your Python Setup: A Step-by-Step Guide In this section, I will cover the main aspects of a common Python setup. Fasten your seatbelts and take mental notes! Choosing the Right Python Version Let’s start with the basics of a Python setup: the version of Python you use. Before starting coding, you need to be aware of the requirements and restrictions of the project you are working on. Ensure that the libraries and packages you will use are compatible with the Python version you chose for your project. Furthermore, using a stable Python version (also called bugfix) is preferable for access to new features, bug fixes, and improvements. You can find out the status of Python versions in the official documentation. If you have worked on maintenance projects or if you are a veteran of Python, you may have known Python version 2. After a long period (almost ten years!), the last version of Python 2 reached its end of life on January 1, 2020. Although It is strongly recommended to use Python 3 for all new projects, knowing the main difference between Python 2 and 3 is important: many companies still use Python 2 for maintaining old projects, and having the ability to manage multiple Python versions is necessary. Do you work on Windows and need to know how to install Python? You can find out in Dorota Wdzięczna’s excellent article How to Install Python on Windows. To manage multiple Python versions in the same environment, you can use the powerful pyenv. This tool lets you have multiple Python versions installed on your environment and allows you to switch between them when needed. You can install pyenv by following the instructions on the official GitHub repository. pyenv provides very simple and easy-to-use commands; here are some of them: pyenv install --list – Check available Python versions. pyenv install <version> – Install a specific Python version. pyenv versions – View all installed Python versions. pyenv local <version> – Switch the local Python version for a specific project. pyenv uninstall <version> – Uninstall a specific Python version. Choosing the Right Python IDE An Integrated Development Environment, also known as an IDE, is a software application that provides a comprehensive set of tools and features to facilitate software development. In simple words, an IDE is the software used by developers to write code, debug, test, and deploy software efficiently. IDEs create a productive workspace integrating multiple tools that facilitate the development process. The Boss: PyCharm The first IDE I would recommend for any Python developer is PyCharm. Developed by JetBrains, PyCharm is an IDE specially used for Python development. It has two versions: The Community Edition is free and open-source. It’s ideal for individual developers or small projects. The Professional Edition requires a license. It’s targeted at professional developers and larger projects. Source: JetBrains PyCharm offers a large panel of coding assistance tools for Python developers, including smart code completion, code analysis, and quick fixes to enhance code quality. It can also make intelligent suggestions for variables, methods, and imports. PyCharm also provides a full-featured debugger with breakpoints, watches, and code step-through capabilities for local projects. It also has remote debugging capabilities for debugging applications on remote servers. Furthermore, PyCharm offers dedicated support for various Python frameworks, including Django and Flask. It supports web development with features like HTML, CSS, and JavaScript editing. It also includes database tools for connecting and managing databases within the IDE and SQL and database schema management. Finally, PyCharm provides built-in support for version control systems like Git and the old-school SVN. I would highly recommend using a version control system – regardless of whether you are working on a big project with your team or on a personal project. With version control, you can track all the changes in your project during its lifetime; you can even roll back to a previous version if necessary. It also allows you to create branches so different coders can work on features, bug fixes, or experiments independently. Once the work is completed, branches can be merged back into the main codebase. A Serious Contender: VS Code Another IDE I often use for Python development is VS Code. Published by Microsoft, Visual Studio Code is a versatile IDE with multiple language support that includes JavaScript, TypeScript, Python, and more. VS Code is open-source and totally free. You can check the web version available here. Source: visualstudio.com VS Code offers a large panel of coding assistance tools, such as intelligent code completion, suggestions, and parameter hints. It also provides an integrated debugger for various languages, supporting breakpoints and variable inspection for local applications as well as for applications on remote servers. A great feature I have always appreciated in VS Code is its marketplace, which contains a vast ecosystem of free extensions and plugins contributed by the community. Take a look at it: code formatters, cloud connectors, ML tools, etc. Truly impressive! Xavier Rigoulet wrote an outstanding post on the Best Visual Studio Code Extensions for Python; you should read it to discover more ways to enhance your Python setup! The Little Brother: Sublime Text I will be honest: Sublime Text is not an IDE; it's a very powerful text editor. However, it totally belongs in this article! Its elegance and power make it the favorite coding tool for many Python developers. Sublime Text is extremely clean and minimal: it provides a clean and distraction-free interface, emphasizing simplicity and efficiency. Image from sublimetext.com Sublime Text is known for its exceptional speed and efficiency, providing a responsive and fluid experience even with large projects. As a powerful text editor, one of Sublime Text's standout features is support for multiple selections, allowing users to make changes simultaneously at multiple locations in the code. It also has a powerful search and replace function: you can perform advanced search and replace using regular expressions and case sensitivity. Sublime Text includes syntax highlighting for Python by default. Which IDE Should You Choose? The choice between PyCharm, Visual Studio Code (VS Code), and Sublime Text for Python development depends on various factors, including personal preferences, project requirements, and the features each IDE or text editor offers. PyCharm is excellently suited for larger projects with a high level of complexity. It contains extensive features such as advanced debugging, testing, and integrated profiling, which are essential for professional Python development. Furthermore, PyCharm provides excellent support for Python web frameworks like Django and Flask, including code completion, navigation, and dedicated project templates. VS Code is a lightweight, fast, and versatile code editor that can be easily customized with extensions for various languages – including Python. It is a strong choice if you work on projects involving multiple languages, as it supports a wide range of programming languages. Furthermore, VS Code has an enthusiast community that collaborates with a vast selection of extensions for different languages and tools. Sublime Text is known for its fast performance, making it suitable for quick edits and small- to medium-sized projects. I’ve covered three of the most famous Python IDEs and code editors in this post, but there are more! Luke Hande revealed his favorites in his post 4 Best Python IDE and Code Editors. Using Virtual Environments One of the keys to a great Python setup is undoubtedly using virtual environments. The configuration is rarely identical from one Python project to another: distinct Python versions can be used as different packages and libraries. Working with virtual environments allows you to create a new and clean development environment for each of your projects, avoiding possible library conflicts and ensuring project portability. If you want to read a great example of project portability, I invite you to read this article on my personal blog: thanks to a local virtual environment, I could re-pack the official AWS SDK for Python/Boto3 and upload it to Amazon Lambda. Tools like venv and virtualenv help manage dependencies and keep projects isolated and reproducible. venv is a module in the Python Standard Library introduced in Python 3.3. It provides support for creating lightweight, isolated Python environments. virtualenv is a third-party tool, compatible with both Python 2 and Python 3. It offers more features than venv and has been widely used, especially in earlier Python versions. This is how to create a virtual environment with venv and virtualenv, respectively: python3 -m venv myenv virtualenv myenv And this is how to activate it: source myenv/bin/activate PyCharm even offers the possibility to create virtual environments and switch between them inside the IDE: Python version and virtual environment in PyCharm Using a Package Manager All the Python packages developed and shared by the Python community are available on PyPi, the official repository. A package manager in Python allows you to install and maintain Python packages inside your local environment. The most famous package manager is pip, the standard package manager for Python. It is astonishingly simple: you can install a package into your project in question of seconds. For example, if you want to install the framework Django, you just have to run the following command in the console: pip install Django Simple, right? pip installs, by default, the last version of the package released on PyPi. However, you can install a specific version: pip install Django==4.2.9 If you want to know more about Python packages with pip, I invite you to read my article Python Standard Library Gems: Little-Known But Useful Packages that Come with Python. Another valuable package manager is Conda. Conda is an open-source package management and environment management system mainly for Python and other languages. It’s designed to address challenges related to dependency management, environment isolation, and the distribution of software packages. Conda installs packages from the Conda repository, which includes precompiled binaries for many languages. This package manager is widely used in data science and scientific computing because of its ability to manage complex dependencies. Ready to Build Your Perfect Python Setup? Thanks for reading this post; I really hope it motivated you to start your Python development journey in a good way by configuring your own Python setup! As I leave, I will make another recommendation: the track Python Basics on LearnPython.com. This track will give you the fundamentals of Python, including real-life examples of Python programming. Happy learning! Tags: get started with python installation guide