How to create a Modern Python Development Environment

Although Python celebrated its 30th birthday last year (2021), it has only recently experienced the rapid acceptance, growth, and upgraded development that we’ve come to identify with the language. Many aspects of Python have remained constant since its beginnings, but with each passing year and each Python edition, new ways have come for accomplishing things and new libraries have been introduced to take advantage of those advancements emerge.

Python has both ancient and new ways of doing things. It is all about how you understand this language and what scopes you find in it. Actually, Python app development is the most trending language nowadays as developers are finding it more suitable for their projects.

What is Python?

Python is simple to learn, with few keywords, a straightforward structure, and a well-defined syntax. It is intended to be a very understandable language. Python codes are easy to read and its source code is quite straightforward to maintain. Python includes a vast standard library that is highly portable and compatible across cross platforms.

Python is portable, meaning it can run on a broad range of hardware systems while maintaining the same user interface. Moreover, Low-level modules can be used to extend the Python interpreter. By adding to or changing these modules, programmers can increase the efficiency of their tools.

Read: Web Development Vs. Software Development, Which is the better career

Python virtual environments and package management

Here is the set of Python tools that can be used as per the project requirements. You need to download these tools to proceed further.

Pyenv

If you want to have numerous versions of Python installed to meet the needs of different projects, Pyenv let you quickly switch on different Python versions on a per-project basis. It is the best choice if you are performing a lot of work at the command line and using different Python editions which are outside of the framework of the project virtual environment. Other than this keep this in mind there is no official window support is available but you will get an unofficial windows port.

Read: How To Pick The Right Mobile App Development Framework

It is recommended that you start with a stable version of python for most projects, then you can use older or newer versions of python as required. For Windows, you can use pyenv-win.

This will show a list of Python versions that can be installed with pyenv. The list may differ depending on the operating system.

# List all available python versions

  • >pyenv install – 1
  • :: [Info] :: Mirror: https://www.python.org/ftp/python
  • 2.4-win32
  • 2.4.1-win32
  • 2.4.2-win32
  • 3.9.0a3
  • 3.9.0a4-win32
  • 3.9.0a4
  • # Install a specific python version
  • >pyenv install 3.9.0a4
  • # Rehash your new installables. Needed to update pyenv shims.
  • >pyenv rehash

As you can see that now it is simple to install multiple Python versions, so you can choose any of the versions among the available ones. It gets really easy to switch between multiple versions of Python. Despite the fact that your machine may contain numerous versions of Python, you must designate one as your global version. You can verify your Python version globally by typing,

  • # Set global python version
  • >pyenv global 3.9.0a4
  • # Check global python version
  • >pyenv global
  • 3.9.0a4

Read: Environment Variables in Python

You can establish distinct Python versions according to your projects, unlike the global version. For example, if you use Python 3.8.2 for your project, you have to set up a local Python version for that project after its installation. This takes precedence over the global Python version.

  • # Install other version of python
  • >pyenv install 3.8.2
  • # Change directory to your project
  • >cd DreamProject
  • # Set local python version inside your project
  • DreamProject>pyenv local 3.8.2
  • # Check your local python version
  • DreamProject>pyenv local
  • 3.8.2

Now that you’ve set your Python version, you may test it out in a fresh terminal.

Read: 6 Reasons why you Should Learn Python

Pipx

We can install CLI tools in isolated contexts using Pipx. It installs the CLI tools in an artificial room and opens them for use, rather than adding them to the system interpreters or switching between several virtual environments.Pipx is used to access or download python tools. Linting tools like mypy, and flake8, for matters like black, and dependency management tools like poetry can be installed once globally and reused across projects. This allows you to keep only one version of these tools and avoid different versions that creates conflicts between projects. You can go like this –

  • # Verify global python version is active
  • >pyenv global
  • 3.9.0a4
  • # Install pipx
  • >pip install pipx
  • # Make sure pipx is added to the path
  • >pipx ensurepath
  • # Install black globally
  • >pipx install black
  • # Check if install is successful
  • >black –version
  • black, version 20.8b1

After the deployment, you can use it across projects by setting this path in your IDEs.

Pipenv

It is responsible for managing the virtual environment and all the additional dependencies which developers have and they have to use other tools to complete the project. It makes sure that dependencies are reliable or predictable, meaning you get the exact versions you want and they function together in the way you specify. Pipenv, on the other hand, does not address packaging in any way, making it unsuitable for projects that you intend to post or share with others.

Read: How to Create an executable from a Python program

Poetry

It’s an excellent solution for managing your Python application’s lifecycle. Python’s packaging and dependency management mechanisms are complicated and difficult to grasp for newbies. Even for experienced coders, creating all of the files required in a Python web application development project can be time-consuming. Poetry makes it easy to manage, address and install Python project dependencies, ensuring that you always have the correct stack. It generates isolated environments for each project instantly, preventing changes to dependencies in other projects.

  • > pyenv shell 3.9.0
  • > curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python ->
  • > source ~/.bashrc
  • # Confirm installation was successful:
  • > poetry –version
  • Poetry version 1.1.13 # Your version will likely be newer.

EditorConfig

This is the best tool when it comes to maintaining a consistent coding style for the developers who works with multiple editors and IDEs for their projects. It helps them in managing the work effectively. It operates by reading the. editorconfig configuration file located above the project. Although most IDEs already have built-in support, there are a few that require a plugin. For example –

 

 

Now you are ready to create a Modern Python Project. Most of the companies hire Python experts to complete their Python projects, they also check their working strategies and the code patterns which they use.

Read: How to use the logging module in Python

Conclusion

This blog has covered the most used ways of creating a modern Python development environment. A lot of other tools are also there which can be used, it all depends on you, which one you found suitable as per your skills. Usually, a Python Development Company works with a lot of experienced developers, so if you are a beginner or a seasoned, the best way of putting your hand in this is to work with a firm. You can also work as a freelancer after gaining some experience in it.

 


If you like the content, we would appreciate your support by buying us a coffee. Thank you so much for your visit and support.

 

Leave a Reply