Getting set up to run Python scripts
If you’re just starting out with Python, we recommend that you DON’T start working with it in Muk3D, initially. We’d recommend that you download and install a Python interpreter, a Integrated Development Environment (IDE), and practice with Python in that environment. IDE’s are good to work with when learning as they will guide you with syntax, highlight errors, and make it easier to debug programs. The code is run within the IDE environment, as opposed to running Muk3D scripts which run within Muk3D rather than a separate Python interpreter.
Getting Python
The Python interpreter and Standard Library can be downloaded from the Python Software Federation website.
https://www.python.org/downloads/
The v2023 release of Muk3D is based on Python v2.7.14.
The v2024 release of Muk3D is based on Python 3.10.
Migration to Python v3.12 is slated for 2025 provided supporting libraries are stable under this release.
Differences between Python 2 and 3
Once you understand that basics of Python, its fairly straightforward to write code in either Python 2 or Python 3. The main differences between Python 2 and Python 3 include:
- Syntax Changes: Python 3 introduced several syntax changes and improvements over Python 2. For example, print is a statement in Python 2 but a function in Python 3, Unicode support is more intrinsic in Python 3, and integer division behaviour is different between the two versions.
- Unicode Support: Python 3 treats strings as Unicode by default, while Python 2 treats them as ASCII unless specified otherwise. This difference in handling strings can lead to compatibility issues when porting code from Python 2 to Python 3.
- Division Behaviour: In Python 2, the division operator (/) performs integer division when applied to two integers, whereas in Python 3, it always performs true division, resulting in a float. To perform integer division in Python 3, you can use the // operator.
- Print Statement: As mentioned earlier, the print statement syntax is different between Python 2 and Python 3. In Python 2, print is a statement, while in Python 3, it’s a built-in function.
- Range vs. xrange: Python 2 has both the range() function and the xrange() function for generating sequences of numbers. In Python 3, the xrange() function is removed, and range() behaves like the xrange() function of Python 2, generating sequences lazily.
- Bytes vs. Strings: In Python 2, strings are a sequence of bytes, and Unicode strings are a separate datatype. In Python 3, strings are Unicode by default, and byte arrays are represented using the bytes datatype.
- Exception Handling: The syntax for exception handling has changed slightly between Python 2 and Python 3. Python 3 introduces a more consistent and explicit syntax for handling exceptions.
- Function Annotations: Python 3 supports function annotations, allowing developers to add metadata to function parameters and return values. This feature is not available in Python 2.
- Performance Improvements: Python 3 includes various performance improvements and optimizations over Python 2, such as more efficient memory management and faster Unicode handling.
- Library Compatibility: While many popular libraries and frameworks have been updated to support Python 3, there are still some libraries that are only compatible with Python 2. This difference in library support can influence the choice between Python 2 and Python 3 for specific projects.
Options for IDE
A non-exhaustive list of IDE’s are below.
IDLE
Python IDLE (Integrated Development and Learning Environment) is a user-friendly platform for Python programming. It features a simple GUI with a code editor supporting syntax highlighting and auto-indentation. Its interactive shell allows for immediate code execution and debugging, aided by features like breakpoints and variable inspection. Integrated documentation helps users quickly access Python resources. While primarily focused on individual scripts, it also offers basic project management. With customization options and cross-platform compatibility, Python IDLE caters to developers of all levels, providing an efficient environment for coding, testing, and learning Python.
https://docs.python.org/3/library/idle.html
PyCharm
PyCharm is a powerful integrated development environment (IDE) specifically designed for Python. It offers advanced features such as code analysis, debugging tools, intelligent code completion, and support for web development frameworks like Django and Flask. PyCharm’s user-friendly interface and extensive plugin ecosystem make it a popular choice for Python developers seeking productivity and efficiency in their workflow. PyCharm Community Edition is a simplified version of PyCharm that will work well for new Python learners.
https://www.jetbrains.com/pycharm/
Visual Studio Code
Visual Studio Code (VS Code) is a lightweight yet powerful source code editor developed by Microsoft. It supports multiple programming languages and offers features such as syntax highlighting, code completion, debugging, and version control integration. With a customizable interface, rich extension marketplace, and cross-platform compatibility, VS Code is widely used by developers for various programming tasks, from small scripts to large-scale projects.
https://code.visualstudio.com/
Spyder
Spyder is an open-source integrated development environment (IDE) primarily designed for scientific computing and data analysis with Python. It offers features such as a powerful code editor, interactive console, variable explorer, and integrated support for data visualization libraries like Matplotlib and Pandas. With its focus on scientific computing, Spyder provides an efficient environment for researchers and data scientists to explore, analyze, and visualize data seamlessly within the Python ecosystem.
PyDev
PyDev is an open-source Python Integrated Development Environment (IDE) plugin for Eclipse. It provides features such as code editing, debugging, and project management, all seamlessly integrated within the Eclipse IDE. PyDev offers advanced capabilities for Python development, including syntax highlighting, code completion, and support for various Python libraries and frameworks. With its extensive set of features and flexibility, PyDev is a popular choice among developers for Python development within the Eclipse ecosystem.
https://www.pydev.org/index.html
Code/Text editors
If you don’t need to full feature set of an IDE, there are some more lightweight editors for Python code.
Windows Notepad
Windows Notepad should not be used for editing Python code. One of the features of Python code is consistent indentation of code blocks. Notepad does not make it easy to modify indentation and so it’s a major pain to work with.
Notepad++
A free and open-source text editor for Windows, Notepad++ offers features such as syntax highlighting, code folding, and support for multiple programming languages including Python.