Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Activity for Karl Knechtelâ€
Type | On... | Excerpt | Status | Date |
---|---|---|---|---|
Answer | — |
A: Why does `tkinter` (or `turtle`, or IDLE) seem to be missing or broken? Isn't it part of the standard library? General This question and answer are adapted from my original write-up on Stack Overflow, which you may consult for more details. This version is crafted as to be a clear overview, without referring to a huge pile of previous Q&A about specific special circumstances. You may also be interested in ... (more) |
— | 10 months ago |
Edit | Post #291791 | Initial revision | — | 10 months ago |
Question | — |
Why does `tkinter` (or `turtle`, or IDLE) seem to be missing or broken? Isn't it part of the standard library? I had understood that Python is supposed to come "batteries included", and that the "batteries" specifically include: the `tkinter` standard library, a simple GUI framework a simple IDE called IDLE, implemented using `tkinter` the `turtle` standard library, which uses `tkinter` to impleme... (more) |
— | 10 months ago |
Edit | Post #291790 | Initial revision | — | 10 months ago |
Answer | — |
A: Why does `venv` seem to be missing or broken? Isn't it part of the standard library? `venv` is indeed part of the standard library. However, some Linux distros modify Python to exclude some parts for various reasons, and `venv` might be among them. On Debian-based Linux distros you can generally install `venv` for the system Python with something like `apt install python3.x-ve... (more) |
— | 10 months ago |
Edit | Post #291789 | Initial revision | — | 10 months ago |
Question | — |
Why does `venv` seem to be missing or broken? Isn't it part of the standard library? I understand the benefits of virtual environments in general, and specifically I want to use a virtual environment so that I'll have access to Pip without exposing the system Python (i.e., included with my Linux distribution) to additional risk. However, `python -m venv` isn't working for me either. ... (more) |
— | 10 months ago |
Edit | Post #291788 |
Post edited: |
— | 10 months ago |
Edit | Post #291788 | Initial revision | — | 10 months ago |
Answer | — |
A: Why does `pip` seem to be missing or broken? Isn't it part of the standard library? Contrary to popular belief, Pip is not part of the Python standard library - although it comes as part of a standard distribution of Python. Pip is developed and maintained by the arms-length Python Packaging Authority, which allows it to be versioned independently of Python (developed by the core Py... (more) |
— | 10 months ago |
Edit | Post #291787 | Initial revision | — | 10 months ago |
Question | — |
Why does `pip` seem to be missing or broken? Isn't it part of the standard library? I already know that the `pip` command might not correspond to the same Python that `python` runs. But in my case, it seems not to exist at all. I can't even run it as a Python module: ```python $ python -m pip /usr/bin/python: No module named pip ``` What gives? I thought each copy of Python... (more) |
— | 10 months ago |
Comment | Post #291768 |
I never ended up writing a specific Q&A for this on Stack Overflow - nor did I add an answer to [the existing canonical there](https://stackoverflow.com/questions/14295680). I should probably update the package, especially so that the README refers to this question instead of vaguely pointing at Stac... (more) |
— | 10 months ago |
Edit | Post #291768 |
Post edited: hide examples because they aren't strictly necessary to describe the problem; add some colour |
— | 10 months ago |
Edit | Post #291769 |
Post edited: |
— | 10 months ago |
Edit | Post #291769 | Initial revision | — | 10 months ago |
Answer | — |
A: Why can't I use a library I just installed with Pip? Problems like this occur, fundamentally, because there is more than one Python installation on the system, and the system is configured in a way that `pip` installs for a different Python than the one that `python` runs. This problem can be addressed by either: using a virtual environment ru... (more) |
— | 10 months ago |
Edit | Post #291768 | Initial revision | — | 10 months ago |
Question | — |
Why can't I use a library I just installed with Pip? I tried installing `package-installation-test`[^1] using Pip, and it appeared to be successful. But I can't use it as advertised, either by itself or by importing it from my code: Failed attempts ```bash $ pip install package-installation-test Collecting package-installation-test Using c... (more) |
— | 10 months ago |
Edit | Post #291757 | Initial revision | — | 10 months ago |
Question | — |
Is my question a duplicate? What now? As part of a general effort to produce basic Q&As for Python, recently I've been focused on issues related to starting up an interpreter and running the code - so, questions about setting up an environment with third-party libraries, figuring out an entry point for the code, and so forth. In parti... (more) |
— | 10 months ago |
Comment | Post #291752 |
Oh, I was so busy making inter-related Q&As in my own style that I forgot about that one. I feel like this one should be considered a duplicate.... (more) |
— | 10 months ago |
Edit | Post #291756 |
Post edited: |
— | 10 months ago |
Edit | Post #291756 |
Post edited: |
— | 10 months ago |
Edit | Post #291756 |
Post edited: |
— | 10 months ago |
Edit | Post #291756 | Initial revision | — | 10 months ago |
Answer | — |
A: Reinstall old Python libraries after update > Every time I run a program I'm used to, I get a bunch of import errors, and have to reinstall the dependencies. As you're presumably aware, the fundamental problem is that each Python installation is treated as its own separate environment, with its own suite of third-party libraries. Since ther... (more) |
— | 10 months ago |
Comment | Post #291323 |
I guess you're aware, but I've split away content from this answer according to my plan now. If the downvote was yours, please feel free to re-evaluate. (more) |
— | 10 months ago |
Edit | Post #291755 | Initial revision | — | 10 months ago |
Answer | — |
A: How can I access and use command-line arguments in Python? At startup, Python loads the `sys` standard library module (without waiting for any code to `import` it) and sets up several useful values. Among these is sys.argv, which stores command-line arguments for the script. This is a plain list of strings, one per token on the command line (as in other prog... (more) |
— | 10 months ago |
Comment | Post #291753 |
Thanks for the heads-up. I may come back and edit in some references to that. I do plan on having a separate Q&A later to cover the use of `__main__.py` as a module filename. (more) |
— | 10 months ago |
Edit | Post #291753 |
Post edited: add link now that related question exists |
— | 10 months ago |
Edit | Post #291754 | Initial revision | — | 10 months ago |
Question | — |
How can I access and use command-line arguments in Python? In many other programming languages, the execution of code starts in a specifically named function (such as `main`) which is expected to have a specific signature, which allows that function to receive arguments from the command line. For example, we may write `int main(int argc, char argv)` in C ... (more) |
— | 10 months ago |
Edit | Post #291753 | Initial revision | — | 10 months ago |
Answer | — |
A: Understanding the `if __name__ == '__main__':` idiom Whenever Python loads code from a `.py` file, that code gets its own namespace for global variables - so they're not truly global, but per-file values. (When you look at an `import`ed module "from outside", those global variables are the attributes of the `module` object. Thus, when `module.py` has `... (more) |
— | 10 months ago |
Edit | Post #291323 |
Post edited: move content about `if __name__ == '__main__':` to a new Q&A |
— | 10 months ago |
Edit | Post #291752 | Initial revision | — | 10 months ago |
Question | — |
Understanding the `if __name__ == '__main__':` idiom I've seen many examples of Python scripts that include a line that says: ```python if name == 'main': ``` Sometimes the following block contains a bunch of code, but other times it just makes a single function call (like `main()`), or some variant along the lines of ```python import sys ... (more) |
— | 10 months ago |
Edit | Post #291748 | Initial revision | — | 10 months ago |
Answer | — |
A: Regex to get text outside brackets First, we need to define some semantics. While it may not matter for your actual inputs, I propose that it should be valid for the output elements - the parts of the text found outside of brackets - to be empty strings. For example, if two bracketed parts are adjacent, like `onetwofour`, then a resul... (more) |
— | 10 months ago |
Edit | Post #291676 |
Post edited: Shorten slightly by referring to newly created Q&A. (There is probably more redundancy that can be eliminated here.) |
— | 10 months ago |
Edit | Post #291743 | Initial revision | — | 10 months ago |
Answer | — |
A: Understanding Virtual Environments for Python Why The most important ideas behind virtual environments are: 1. Since there is a separate `site-packages`, you can isolate the dependencies of your project. This is especially important for testing and development, since you can more easily verify what your project's dependencies actually are.... (more) |
— | 10 months ago |
Edit | Post #291616 |
Post edited: add tag |
— | 10 months ago |
Edit | Post #291740 | Initial revision | — | 10 months ago |
Question | — |
Understanding Virtual Environments for Python Several times now, I've seen advice in tutorials, setup/install instructions for Python-based projects, etc. to use a virtual environment to keep things organized and make it simpler to manage the code. It sounds like this means having yet another installation of Python on my computer. Does it rea... (more) |
— | 10 months ago |
Comment | Post #291738 |
Of course it's entirely possible to set up an installer that installs both Python itself and your own Python code. There are even [tools to help with that](https://pynsist.readthedocs.io/en/latest/). But I wanted to focus this Q&A on approaches that involve a seamless user experience, where users don... (more) |
— | 10 months ago |
Edit | Post #291739 |
Post edited: |
— | 10 months ago |
Edit | Post #291739 |
Post edited: |
— | 10 months ago |