Re: Assistance Request - Issue with Installing 'pip' despite Python 3.10 Installation
On 6/7/23 10:08, MRAB via Python-list wrote: On 2023-06-07 15:54, Florian Guilbault via Python-list wrote: Dear Python Technical Team, I hope this email finds you well. I am reaching out to you today to seek assistance with an issue I am facing regarding the installation of 'pip' despite my numerous attempts to resolve the problem. Recently, I performed installation, uninstallation, and even repair operations on Python 3.10 on my computer. However, I have noticed that 'pip' has never been installed successfully. When I check via the command prompt, I receive the following error: "'pip' is not recognized as an internal or external command, operable program, or batch file." I have tried several approaches to resolve this issue. I have verified that the PATH environment variable is correctly configured to include the path to the Python Scripts directory. I'm assuming you checked - say, with Explorer - that pip.exe really is where you think it is? Anyway, if you ask a Windows shell (cmd) to locate it, and it doesn't, then your PATH is not set up correctly after all. where pip should give you back a path that ends witn ...\Scripts\pip.exe That said, the suggestions already given are on point. Running pip as a module (rather than as a standalone command) assures that it's associated with the Python you want it associated with. In today's world, a lot of developer systems end up with multiple Python installations (*), and you don't want to use a pip that is bound to the wrong one, or the next email will be "I installed foo module but my Python fails to import it". (*) You can have different Python versions for compat checking, you can have project-specific virtualenvs, you can have Pythons that come bundled with a subsystem like Conda, etc. On Windows, it's recommended to use the Python Launcher and the pip module: py -m pip install whatever -- https://mail.python.org/mailman/listinfo/python-list
Re: Compiling python on windows with vs
On 6/13/23 12:12, Thomas Schweikle via Python-list wrote: Am Di., 13.Juni.2023 um 19:20:38 schrieb Jim Schwartz: What version of visual studio are you using? Visual Studio 2022, aka 17.6.2. What version of python? python 3.10.11 or 3.11.4 I’ve had success with using the cython package in python and cl from visual studio, but I haven’t tried visual studio alone. Same problem at the same place: directory "../modules/..." not found, Renaming it from "Modules" to "modules" it is found, but then fails to find "Modules". Looks like it awaits, compiling in Windows an filesystem only case aware, not case sensitive -- I'm assuming this a bug now. Building within cygwin (or MSYS, Ubuntu) this works as expected. But there it does not search for "modules" once and "Modules" at an other place. I just did this build the other day for the first time even from a git checkout (so VS22, and not a versioned release but top of main branch), and there was no such problem - did you follow the instructions at https://devguide.python.org/getting-started/setup-building/index.html? -- https://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance and a broken super() chain
On 7/3/23 12:01, Richard Damon via Python-list wrote:
On 7/3/23 1:38 PM, Peter Slížik via Python-list wrote:
Hello.
The legacy code I'm working with uses a classic diamond inheritance.
Let me
call the classes *Top*, *Left*, *Right*, and *Bottom*.
This is a trivial textbook example. The classes were written in the
pre-super() era, so all of them initialized their parents and Bottom
initialized both Left and Right in this order.
The result was expected: *Top* was initialized twice:
Top.__init__() Left.__init__() Top.__init__() Right.__init__()
Bottom.__init__()
Now I replaced all parent init calls with *super()*. After this, Top was
initialized only once.
Top.__init__() Right.__init__() Left.__init__() Bottom.__init__()
But at this point, I freaked out. The code is complex and I don't have
the
time to examine its inner workings. And before, everything worked
correctly
even though Top was initialized twice. So I decided to break the
superclass
chain and use super() only in classes inheriting from a single parent. My
intent was to keep the original behavior but use super() where
possible to
make the code more readable.
class Top:
def __init__(self):
print("Top.__init__()")
class Left(Top):
def __init__(self):
super().__init__()
print("Left.__init__()")
class Right(Top):
def __init__(self):
super().__init__()
print("Right.__init__()")
class Bottom(Left, Right):
def __init__(self):
Left.__init__(self) # Here I'm calling both parents manually
Right.__init__(self)
print("Bottom.__init__()")
b = Bottom()
The result has surprised me:
Top.__init__() Right.__init__() Left.__init__() Top.__init__()
Right.__init__() Bottom.__init__()
Now, as I see it, from the super()'s point of view, there are two
inheritance chains, one starting at Left and the other at Right. But
*Right.__init__()* is called twice. What's going on here?
Thanks,
Peter
Because the MRO from Bottom is [Bottom, Left, Right, Top] so super() in
Left is Right. It doesn't go to Top as the MRO knows that Right should
go to Top, so Left needs to go to Right to init everything, and then
Bottom messes things up by calling Right again.
And you can see this a little better in your toy example by using begin
*and* end prints in your initializers.
Also, you might find that because of the MRO, super() in your Bottom
class would actually give you what you want.
And if not sure, print out Bottom.__mro__
--
https://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance and a broken super() chain
On 7/3/23 12:13, Mats Wichmann via Python-list wrote: To natter on a bit, and possibly muddy the waters even further... Now, as I see it, from the super()'s point of view, there are two inheritance chains, one starting at Left and the other at Right. But *Right.__init__()* is called twice. No: each class has just a single inheritance chain, built up when the class object is constructed, to avoid going insane. Yes, the chain for Left and for Right are different, but you're not instantiating *either* of those classes when you make a Bottom, so they don't matter here. You're just filling out a Bottom: it looks for init, finds it, and so would stop hunting - but then the super() call there sends it to the next class object in the chain to look for the method you told it to (also init), where it would stop since it found it, except you sent it on with another super(), and so on. Python is a bit... different :) (compared to other languages with class definitions) -- https://mail.python.org/mailman/listinfo/python-list
Re: Setup-tools
On 7/15/23 12:56, MRAB via Python-list wrote: On 2023-07-15 07:12, YOUSEF EZZAT via Python-list wrote: Hey!. i face a problem when i get setup packages by pip when i code this : "pip install numpy" in my command line it gives me error "ModuleNotFoundError: No module named 'distutils'" please, i need help for solving this problem. i have python 3.12.0b4 What do you normally do when it can't find a module? Install it via pip! pip install distutils By the way, do you really need Python 3.12? It's still in beta, so unless you're specifically checking whether it works, ready for its final release, you'd be better off with Python 3.11. To add to this: For modules which have *binary* compiled wheels (of which numpy is one), they are quite likely to be version-specific, and for many projects, are not made available for pre-release Pythons. You can check numpy here: https://pypi.org/project/numpy/#files (note: pre-release versions targeting pre-release Pythons *may* be elsewhere too, you might check with the numpy project). What pip does if it doesn't find an appropriate wheel version matching your Python version is try to build it from the source distribution - this is why it thinks it needs distutils. If you're on Windows, this will almost certainly fail, although you can often find blogs written by people who have gone through the same adventure who describe how they got there in the end. If numpy is the thing that's important to your work, the advice would be to stick to a released Python with a matching released numpy. If you specifically need to test that something is going to work with 3.12, then by all means go ahead, but be prepared to do some legwork. -- https://mail.python.org/mailman/listinfo/python-list
Re: Imports and dot-notation
On 8/9/23 17:28, dn via Python-list wrote: Side note: Using "...import identifier, ..." does not save storage-space over "import module" (the whole module is imported regardless, IIRC), however it does form an "interface" and thus recommend leaning into the "Interface Segregation Principle", or as our InfoSec brethren would say 'the principle of least privilege'. Accordingly, prefer "from ... import ... as ...". Attribute lookup has *some* cost. That is, finding "c" in the local namespace is going to be a little quicker than "b.c", where Python finds "b" in the local namespace and then finds its "c" attribute; that's then a little quicker than "a.b.c", etc. See all relevant commentary about premature optimisation, spending time optimising the wrong things, etc. but there *are* cases where it matters (c.f. a tight loop that will be run many many times) -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP668 / pipx and "--editable" installs
On 9/18/23 02:16, Peter J. Holzer via Python-list wrote: On 2023-09-15 14:15:23 +, c.buhtz--- via Python-list wrote: I tried to install it via "pipx install -e .[develop]". It's pyproject.toml has a bug: A missing dependency "dateutil". But "dateutil" is not available from PyPi for Python 3.11 (the default in Debian 12). But thanks to great Debian they have a "python3-dateutil" package. I installed it. Sidenote: PyPI does have several packages with "dateutil" in their name. From the version number (2.8.2) I guess that "python-dateutil" is the one packaged in Debian 12. This can be installed via pip: It *is* the case that package name is not always equal to importable name. That certainly occurs in the universe of Python packages on PyPI; it's if anything much more likely on Linux distributions which have to share the package name namespace with a lot more than just Python packages (just for starters, what seems like billions of Perl packages), so you're even more likely to see names like python-foo or python3-foo when the thing you import is foo. That has nothing to do virtualenvs, of course. The use of a virtualenv for a project actually makes it more likely that you discover unstated dependencies, which is generally a good thing. -- https://mail.python.org/mailman/listinfo/python-list
Re: PEP668 / pipx and "--editable" installs
On 9/18/23 12:56, c.buhtz--- via Python-list wrote: On 2023-09-18 10:16 "Peter J. Holzer via Python-list" wrote: On 2023-09-15 14:15:23 +, c.buhtz--- via Python-list wrote: I tried to install it via "pipx install -e .[develop]". It's pyproject.toml has a bug: A missing dependency "dateutil". But "dateutil" is not available from PyPi for Python 3.11 (the default in Debian 12). But thanks to great Debian they have a "python3-dateutil" package. I installed it. This can be installed via pip: I'm aware of this. But this is not the question. I would like to know and understand why my via "pipx" installed package "hyperorg" is not able to see the systems packages installed via "apt install python3-dateutils"? Is this the usual behavior? Is this correct? Yes. By default, the virtualenv contains just what you've installed. It's designed to give you tight control over what's installed, so you can track dependencies, avoid accidental inclusions, etc. As usual, you don't have to accept the default. For example, for the venv module: usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] [--upgrade-deps] ENV_DIR [ENV_DIR ...] Creates virtual Python environments in one or more target directories. positional arguments: ENV_DIR A directory to create the environment in. options: -h, --helpshow this help message and exit --system-site-packages Give the virtual environment access to the system site-packages dir. ... -- https://mail.python.org/mailman/listinfo/python-list
Re: Unable to uninstall 3.10.9
On 9/25/23 12:10, Pau Vilchez via Python-list wrote: Hello Python Team, I am somehow unable to completely remove Python 3.10.9 (64 Bit) from my computer. I have tried deleting the Appdata folder then repairing and then uninstalling but it still persists in the remove/add program function in windows 10. I am just trying to reinstall it because I didn’t add it to the path correctly, any help is greatly appreciated. Rerunning the installer and telling it uninstall should normally work (if you can't get to that from the Programs applet, then you can start from the installer itself). You can also fix the path addition from the Modify screen in the installer, you don't need to uninstall for that. If it's really stuck, the Windows installer subsystem could have gotten confused, usually this tool works for folks: https://support.microsoft.com/en-us/topic/fix-problems-that-block-programs-from-being-installed-or-removed-cca7d1b6-65a9-3d98-426b-e9f927e1eb4d -- https://mail.python.org/mailman/listinfo/python-list
Re: upgrade of pip on my python 2.7 version
On 9/27/23 05:17, Zuri Shaddai Kuchipudi via Python-list wrote: hello everyone this the error that im getting while trying to install and upgrade pip on what is the solution for it? C:\repository\pst-utils-pc-davinci-simulator>pip install You are using pip version 7.0.1, however version 23.2.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. You must give at least one requirement to install (see "pip help install") C:\repository\pst-utils-pc-davinci-simulator>pip install --upgrade pip You are using pip version 7.0.1, however version 23.2.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. Collecting pip Using cached https://files.pythonhosted.org/packages/ba/19/e63fb4e0d20e48bd2167bb7e857abc0e21679e24805ba921a224df8977c0/pip-23.2.1.tar.gz Complete output from command python setup.py egg_info: Traceback (most recent call last): File "", line 20, in File "c:\users\kuchipz\appdata\local\temp\pip-build-gc4ekm\pip\setup.py", line 7 def read(rel_path: str) -> str: ^ SyntaxError: invalid syntax PyPI *should* be returning a compatible version of pip to upgrade to. pip itself has long since dropped support for 2.7, and the version you're trying to force is pretty clear: pip 23.2.1 Meta License: MIT License (MIT) Author: The pip developers Requires: Python >=3.7 ... Classifiers Development Status 5 - Production/Stable Intended Audience Developers License OSI Approved :: MIT License Programming Language Python Python :: 3 Python :: 3 :: Only ... So "don't do that". Why it's trying to select an incompatible version when you ask to upgrade is not something I'd like to speculate on, for me personally that's a surprise. Maybe something else you did before? Also make sure you're using a pip that matches your Python. It's usually safer if you invoke it as: python -m pip install --upgrade pip (or whatever the precise name of your Python 2 interpreter actually is) -- https://mail.python.org/mailman/listinfo/python-list
Re: path to python in venv
On 9/27/23 13:46, Larry Martell via Python-list wrote: On Wed, Sep 27, 2023 at 12:42 PM Jon Ribbens via Python-list wrote: On 2023-09-27, Larry Martell wrote: I was under the impression that in a venv the python used would be in the venv's bin dir. But in my venvs I see this in the bin dirs: lrwxrwxrwx 1 larrymartell larrymartell7 Sep 27 11:21 python -> python3 lrwxrwxrwx 1 larrymartell larrymartell 16 Sep 27 11:21 python3 -> /usr/bin/python3 ... Not sure what this really means, nor how to get python to be in my venv. WHy do you want python to be "in your venv"? Isn't that the entire point of a venv? To have a completely self contained env? So if someone messes with the system python it will not break code running in the venv. It can do that, it just turns out the defaults are to not make a dedicated Python instance, and to not give access to the system site packages. The venv and virtualenv modules, at least, will let you override either of those defaults via command-line options at creation time. Once a year I have virtualenvs break when the new Python version appears in Fedora, which is irritating, but I take the attitude that virtualenvs are disposable and (try to) not let it bother me that I forgot to deal with that ahead of time. It helps if you make sure that a virtualenv has a record of its dependencies - perhaps a requirements.txt file in the project it's being used to build, so it's easy to recreate them. -- https://mail.python.org/mailman/listinfo/python-list
Re: upgrade of pip on my python 2.7 version
On 9/27/23 14:02, Zuri Shaddai Kuchipudi via Python-list wrote: Why it's trying to select an incompatible version when you ask to upgrade is not something I'd like to speculate on, for me personally that's a surprise. Maybe something else you did before? Also make sure you're using a pip that matches your Python. It's usually safer if you invoke it as: python -m pip install --upgrade pip (or whatever the precise name of your Python 2 interpreter actually is) the code that i want to run and all the libraries are written for python 2 but i have seen a video where the person showed the 2to3 pip method in which it rewrites the code in python 3 and shows all the necessary changes. Upgrading to Python 3 is the best answer... except when it isn't. If you want to convert a small project it's usually not too hard; and using a conversion tool can work well. If you have libraries "not under your control" expect a lot more work. You can upgrade pip to the latest available version for Python 2.7 - will take some research, I don't know what that version might be. Or you could try this: https://bootstrap.pypa.io/pip/2.7/get-pip.py If you were using a Linux distro, you probably don't want to mess with the "system pip" which is usually set up to understand details of how that distro's Python is packaged. It looks like you're on Windows by the paths in your original message, so that should be okay. Or... you could just ignore the message suggesting you upgrade pip, and proceed, hoping things will stay working as they are. -- https://mail.python.org/mailman/listinfo/python-list
Re: type annotation vs working code
On 9/30/23 13:00, Karsten Hilbert via Python-list wrote:
A type annotation isn't supposed to change what code does,
or so I thought:
#
class Borg:
_instances:dict = {}
def __new__(cls, *args, **kargs):
# look up subclass instance cache
if Borg._instances.get(cls) is None:
Borg._instances[cls] = object.__new__(cls)
return Borg._instances[cls]
class WorkingSingleton(Borg):
def __init__(self):
print(self.__class__.__name__, ':')
try:
self.already_initialized
print('already initialized')
return
except AttributeError:
print('initializing')
self.already_initialized = True
self.special_value = 42
class FailingSingleton(Borg):
def __init__(self):
print(self.__class__.__name__, ':')
try:
self.already_initialized:bool
print('already initialized')
return
except AttributeError:
print('initializing')
self.already_initialized = True
self.special_value = 42
s = WorkingSingleton()
print(s.special_value)
s = FailingSingleton()
print(s.special_value)
#
Notice how Working* and Failing differ in the type annotation
of self.already_initialized only.
What happens here is in the second case, the line is just recorded as a
variable annotation, and is not evaluated as a reference, as you're
expecting to happen, so it just goes right to the print call without
raising the exception. You could change your initializer like this:
def __init__(self):
print(self.__class__.__name__, ':')
self.already_initialized: bool
try:
self.already_initialized
print('already initialized')
return
The syntax description is here:
https://peps.python.org/pep-0526/#global-and-local-variable-annotations
--
https://mail.python.org/mailman/listinfo/python-list
Re: Unable to completely remove Python 3.10.9 (64 bit) from Computer
On 10/4/23 13:08, Roland Müller via Python-list wrote: On 25.9.2023 19.58, Pau Vilchez via Python-list wrote: Hello Python Team, I am somehow unable to completely remove Python 3.10.9 (64 Bit) from my computer. I have tried deleting the Appdata folder then repairing and then uninstalling but it still persists in the remove/add program function in windows 10. I am just trying to reinstall it because I didn’t add it to the path correctly, any help is greatly appreciated. This is a Windows issue and not actually Python -specific. It may happen to every program you install. If something is installed by the normal way using the W10 installer it should be removable too. If not there should be some error. Python seems somewhat prone to this on Windows, I recently had a case where the original version of two upgraded Pythons were still stuck sitting in the Programs (which I didn't notice originally), so it looked like 3.11.1 and 3.11.4 were *both* installed, as well as two 3.10 versions - this was an otherwise well-behaving system, so it was quite mystifying. You can run uninstall directly from the installer file (download it again if you need to). This may work better than selecting "modify" from the Programs applet - a "stuck" installation may still be missing some piece of information even if you tried to repair it. If things are *really* stuck Microsoft provide a tool which I've used with success on really messed up installation info. https://support.microsoft.com/en-us/topic/fix-problems-that-block-programs-from-being-installed-or-removed-cca7d1b6-65a9-3d98-426b-e9f927e1eb4d -- https://mail.python.org/mailman/listinfo/python-list
Re: Running a subprocess in a venv
On 10/21/23 07:01, Larry Martell via Python-list wrote: I have a python script, and from that I want to run another script in a subprocess in a venv. What is the best way to do that? I could write a file that activates the venv then runs the script, then run that file, but that seems messy. Is there a better way? You don't need to "activate" a virtualenv. The activation script does some helpful things along the way (setup and cleanup) but none of them are required. The most important thing it does is basically: VIRTUAL_ENV='path-where-you-put-the-virtualenv' export VIRTUAL_ENV _OLD_VIRTUAL_PATH="$PATH" PATH="$VIRTUAL_ENV/bin:$PATH" export PATH and that's really only so that commands that belong to that virtualenv (python, pip, and things where you installed a package in the venv wich creates an "executable" in bin/) are in a directory first in your search path. As long as you deal with necessary paths yourself, you're fine without activating. So as mentioned elsewhere, just use the path to the virtualenv's Python and you're good to go. -- https://mail.python.org/mailman/listinfo/python-list
Re: Too Broad of an exception
On 10/26/23 03:04, Rene Kita via Python-list wrote:
Rene Kita wrote:
rsutton wrote:
Hi all,
I am fairly new to python (ie < 2 years). I have a question about
pylint. I am running on windows 10/11, python 3.10.11.
[...]
if p.returncode >= 8:
raise Exception(f'Invalid result: {p.returncode}')
It actually runs fine. But pylint is not having it. I get:
win_get_put_tb_filters.py:61:12: W0719: Raising too general exception:
Exception (broad-exception-raised)
pylint is just a linter, ignore it if the code works and you like it the
way it is.
pylint complains because you use Exception. Use e.g. RuntimeException to
silence it.
Ingrid says it's a RuntimeError, not RuntimeException.
Meanwhile, the purpose of this complaint from pylint (and notice it's a
"warning", not an "error", so take that for what it's worth), is that
you usually want to convey some information when you raise an exception.
Of course, you can put that into the message you pass to the class
instance you raise, but the type of exception is informational too.
Raising just "Exception" is equivalent to saying "my car is broken",
without specifying that the starter turns but won't "catch", or starts
but the transmission won't engage, or the battery is dead, or so
it's *advising* (not forcing) you to be more informative.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 11/1/23 05:35, Simon Connah via Python-list wrote: OK. I've been doing some reading and that you should avoid regex to check email addresses. So what I was thinking was something like this: To be a little more specific, Avoid Rolling Your Own RegEx. It's very tricky, and you will get it subtly wrong. All depending, as others have said, on what level of "validation" you're after. -- https://mail.python.org/mailman/listinfo/python-list
Re: pip/pip3 confusion and keeping up to date
On 11/2/23 04:58, Chris Green via Python-list wrote: I have a couple of systems which used to have python2 as well as python3 but as Ubuntu and Debian verions have moved on they have finally eliminated all dependencies on python2. So they now have only python3 and there is no python executable in PATH. FWIW, for this you install the little stub package python-is-python3. Especially if you want to keep a python2 installation around - "python" will still be python3 in this case. So, going on from this, how do I do the equivalent of "apt update; apt upgrade" for my globally installed pip packages Odds are you don't want to. The internet is full of surprises about dependency problems when stuff is blindly updated; the set of Python packages in the apt repositories is carefully curated to avoid these problems - and this is part of the reason why sometimes certain such packages are irritatingly down-rev. -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 11/5/23 10:34, Grant Edwards via Python-list wrote:
Indeed. There is a tiny but brightly burning kernel of hate in my
heart for web sites (and their developers) that refuse to accept
credit card numbers entered with spaces _as_they_are_shown_on_the_card_!
I've concluded that using PHP causes debilitating and irreversible
brain damage.
I think it's the attitude that speed of deployment is more important
than any other factor, rather than just PHP :-) Plus a bunch of that
stuff is also coded in the front end (aka Javascript).
Phone numbers.
Credit card numbers.
Names (in my case - my wife has a hypenated surname which is almost as
deadly as non-alpha characters in a name which was already mentioned in
this diverging thread)
and addresses. living rurally we have two addresses: a post office
rural route box for USPS and a "street address" for anyone else. The
former looks like "{locationID} Box {number}". The single word "Box"
often triggers "we don't deliver to P.O. Boxes" - it's not a PO Box, and
it's the only address USPS will deliver to, so get over yourself. Or
triggers fraud detection alerts, because "billing address" != "shipping
address".
it's astonishing how bad so many websites are at what should be a
fundamental function: taking in user-supplied data in order to do
something valuable with it.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 11/6/23 01:57, Simon Connah via Python-list wrote: The thing I truly hate is when you have two telephone number fields. One for landline and one for mobile. I mean who in hell has a landline these days? People who live in places with spotty, or no, mobile coverage. We do exist. -- https://mail.python.org/mailman/listinfo/python-list
Re: Checking if email is valid
On 11/6/23 08:23, Jon Ribbens via Python-list wrote: On 2023-11-06, Mats Wichmann wrote: On 11/6/23 01:57, Simon Connah via Python-list wrote: The thing I truly hate is when you have two telephone number fields. One for landline and one for mobile. I mean who in hell has a landline these days? People who live in places with spotty, or no, mobile coverage. We do exist. Catering for people in minority situations is, of course, important. Catering for people in the majority situation is probably important too. A good experience would do both, in a comfortable way for either. Continuing with the example, if you have a single phone number field, or let a mobile number be entered in a field marked for landline, you will probably assume you can text to that number. I see this all the time on signups that are attempting to provide some sort of 2FA - I enter the landline number and the website tries to text a verification code to it (rather have an authenticator app for 2FA anyway, but that's a different argument) Suggests maybe labeling should be something like: * Number you want to be called on * Number for texted security messages, if different Never seen that, though :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: pip/pip3 confusion and keeping up to date
On 11/6/23 14:28, Karsten Hilbert via Python-list wrote: I had just hoped someone here might have a handy pointer for how to deal with modules having to be installed from pip for use with an apt-installed python-based application. That just shouldn't happen - such packages are supposed to be dependency-complete within the packaging universe in question. -- https://mail.python.org/mailman/listinfo/python-list
Re: xor operator
On 11/13/23 16:24, Dom Grigonis via Python-list wrote: I am not arguing that it is a generalised xor. I don’t want anything, I am just gauging if it is specialised or if there is a need for it. So just thought could suggest it as I have encountered such need several times already. It is fairly clear by now that it is not a common one given it took some time to even convey what I mean. Bad naming didn’t help ofc, but if it was something that is needed I think it would have clicked much faster. There are things that If You Need Them You Know, and If You Do Not You Do Not Understand - and you seem to have found one. The problem is that forums like this are not a statistically great sampling mechanism - a few dozen people, perhaps, chime in on many topics; there are millions of people using Python. Still, the folks here like to think they're at least somewhat representative :) Hardware and software people may have somewhat different views of xor, so *maybe* the topic title added a bit to the muddle. To me (one of those millions), any/all falsy, any/all truthy have some interest, and Python does provide those. Once you get into How Many True question - whether that's the odd-is-true, even-is-false model, or the bail-after-X-truthy-values model, it's not terribly interesting to me: once it gets more complex than an all/any decision, I need to check for particular combinations specifically. Two-of-six means nothing to me until I know which combination of two it is. -- https://mail.python.org/mailman/listinfo/python-list
Re: Silly/crazy problem with sqlite
On 11/24/23 14:10, Chris Green via Python-list wrote:
Chris Green wrote:
This is driving me crazy, I'm running this code:-
OK, I've found what's wrong:-
cr.execute(sql, ('%' + "2023-11" + '%'))
should be:-
cr.execute(sql, ('%' + x + '%',) )
I have to say this seems very non-pythonesque to me, the 'obvious'
default simply doesn't work right, and I really can't think of a case
where the missing comma would make any sense at all.
as noted, the comma makes it a tuple.
this might be a case where rewriting as an f-string makes it just a
little more readable, since the syntax will make it look like there's a
single string followed by a comma - the addition just makes it look less
clear to my eyes:
cr.execute(sql, (f'%2023-11%', ))
cr.execute(sql, (f'%{x}%', ))
--
https://mail.python.org/mailman/listinfo/python-list
Re: argparse argument post-processing
On 11/27/23 04:29, Dom Grigonis via Python-list wrote:
Hi all,
I have a situation, maybe someone can give some insight.
Say I want to have input which is comma separated array (e.g.
paths='path1,path2,path3') and convert it to the desired output - list:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('paths', type=lambda x: list(filter(str.strip,
x.split(','
So far so good. But this is just an example of what sort of solution I am after.
Maybe use "action" rather than "type" here? the conversion of a csv
argument into words seems more like an action.
Now the second case. I want input to be space separated array - bash array. And
I want space-separated string returned. My current approach is:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('paths', nargs='+')
args = parser.parse_args()
paths = ' '.join(args.paths)
But what I am looking for is a way to do this, which is intrinsic to `argparse`
module. Reason being I have a fair amount of such cases and I don’t want to do
post-processing, where post-post-processing happens (after
`parser.parse_args()`).
I have tried overloading `parse_args` with post-processor arguments, and that
seemed fine, but it stopped working when I had sub-parsers, which are defined
in different modules and do not call `parse_args` themselves.
Depending on what *else* you need to handle it may or not may work here
to just collect these from the remainders, and then use an action to
join them, like:
import argparse
class JoinAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, ' '.join(values))
parser = argparse.ArgumentParser()
parser.add_argument('paths', nargs=argparse.REMAINDER,
action=JoinAction)
args = parser.parse_args()
print(f"{args.paths!r}")
--
https://mail.python.org/mailman/listinfo/python-list
Re: argparse argument post-processing
On 11/27/23 13:21, Dom Grigonis wrote: Thank you, exactly what I was looking for! One more question following this. Is there a way to have a customisable action? I.e. What if I want to join with space in one case and with coma in another. Is there a way to reuse the same action class? I've worked more with optparse (the project I work on that uses it has reasons why it's not feasible to convert to argparse); in optparse you use a callback function, rather than an action class, and the change to a callable class is somewhat significant :-; so I'm not really an expert. The question is how you determine which you want to do - then there's no problem for the action class's call method to implement it. I presume you can write an initializer class that takes an extra argument, collect that and stuff it into an instance variable, then use super to call the base Action class's initializer with the rest of the args super().__init__(option_strings=option_strings, *args, **kwargs) Hopefully someone else has done this kind of thing because now I'm just guessing! -- https://mail.python.org/mailman/listinfo/python-list
Re: How/where to store calibration values - written by program A, read by program B
On 12/5/23 07:37, Chris Green via Python-list wrote: Is there a neat, pythonic way to store values which are 'sometimes' changed? My particular case at the moment is calibration values for ADC inputs which are set by running a calibration program and used by lots of programs which display the values or do calculations with them. From the program readability point of view it would be good to have a Python module with the values in it but using a Python program to write/update a Python module sounds a bit odd somehow. I could simply write the values to a file (or a database) and I suspect that this may be the best answer but it does make retrieving the values different from getting all other (nearly) constant values. Are there any Python modules aimed specifically at this sort of requirement? A search term to look for is "data persistence" there is lots of support at various levels - you can do simpler things with plain text (or binary), json data, or csv data, or configparser, or use pickles; if there's not a lot of values a dbapi database may, as already mentioned, be overkill. -- https://mail.python.org/mailman/listinfo/python-list
Re: IDLE editor suggestion.
On 12/12/23 13:50, Thomas Passin via Python-list wrote: On 2023-12-12 08:22, Steve GS via Python-list wrote: > Maybe this already exists but > I have never seen it in any > editor that I have used. > > It would be nice to have a > pull-down text box that lists > all of the searches I have > used during this session. It > would make editing a lot > easier if I could select the > previous searches rather than > having to enter it every time. > > If this is inappropriate to > post this here, please tell me > where to go. > Life should be so > complicated. > EditPad has this. So do Notepad++, EditPlus (not free but low cost, Windows only, and very good), and I'm sure many others that are much simpler than Visual Studio Code, for example. Every now and then I pop up and suggest people look at Eric. Odd name for an editor? Well, it continues the long pun history in the Python world (Eric Idle... get it?). It has search history, among many other things, I think once it was considered to be sort of IDLE++, but it's grown to a lot more than that. Not saying Eric is better-than-XYZ-IDE, but it is a cool project... -- https://mail.python.org/mailman/listinfo/python-list
Re: Type hints - am I doing it right?
On 12/13/23 00:19, Frank Millman via Python-list wrote: I have to add 'import configparser' at the top of each of these modules in order to type hint the method. This seems verbose. If it is the correct way of doing it I can live with it, but I wondered if there was an easier way. Think of import as meaning "make this available in my current (module) namespace". The actual import machinery only runs the first time, that is, if it's not already present in the sys.modules dict. -- https://mail.python.org/mailman/listinfo/python-list
Re: mypy question
On 12/29/23 05:15, Karsten Hilbert via Python-list wrote: Hi all, I am not sure why mypy thinks this gmPG2.py:554: error: Argument "queries" to "run_rw_queries" has incompatible type "List[Dict[str, str]]"; expected "List[Dict[str, Union[str, List[Any], Dict[str, Any" [arg-type] rows, idx = run_rw_queries(link_obj = conn, queries = queries, return_data = True) ^~~ should be flagged. The intent is for "queries" to be a list of dicts with keys of str and values of str OR list of anything OR dict with keys of str and values of anything I'd have thunk list[dict[str,str]] matches that ? Dict[str, str] means the key type and value type should both be strings, but in your retelling above you indicate lots of possible value types... actually the mypy guess seems to be a pretty good recreation of your psuedo-code description. -- https://mail.python.org/mailman/listinfo/python-list
Re: Are there any easy-to-use Visual Studio C# WinForms-like GUI designers in the Python world for Tk?
On 12/28/23 18:05, Félix An via Python-list wrote: I'm used to C# WinForms, which has an easy-to-use drag-and-drop GUI designer in Visual Studio. Is there anything similar for Tk? How about Qt? What do you recommend as the easiest way to create GUI programs in Python, similar to the ease of use of C# WinForms? Qt has a long-standing Designer tool. I was pretty sure there was nothing for tkinter, but it seems at least someone tried: https://pypi.org/project/tkdesigner/ and someone has tried a web-based one (looks like it may help to read Chinese for that one) https://visualtk.com/ -- https://mail.python.org/mailman/listinfo/python-list
Re: mypy question
On 12/29/23 08:02, Karsten Hilbert via Python-list wrote: Dict[str, str] means the key type and value type should both be strings, Indeed, I know that much, list[dict[str, str]] is what is getting passed in in this particular invocation of run_rw_queries(). For what it's worth here's the signature of that function: def run_rw_queries ( link_obj:_TLnkObj=None, queries:list[dict[str, str | list | dict[str, Any]]]=None, end_tx:bool=False, return_data:bool=None, get_col_idx:bool=False, verbose:bool=False ) -> tuple[list[dbapi.extras.DictRow], dict[str, int] | None]: Given that I would have thought that passing in list[dict[str, str]] for "queries" ought to be type safe. Mypy indicates otherwise which I am not grokking as to why. ah... didn't grok what you were asking, sorry - ignore my attempt then. So you are passing something that has been typed more narrowly than the function parameter. Can you use a TypeGuard here? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
On 1/1/24 04:02, Sibylle Koczian via Python-list wrote: Am 30.12.2023 um 04:04 schrieb Mike Dewhirst via Python-list: I had assumed the OP had installed Python from the Microsoft shop and that's where py.exe must have come from. In fact I didn't say in my post that I always get Python from python.org. When I started to use the language there was no Python from any Microsoft shop (I'm not sure there was a Microsoft shop, it was in the last millenium, Python 1.5 or 1.6). So I tend to forget that possible download source. But in all this thread I didn't see a single explanation for my current situation: one and the same shebang line works on Windows 10 / Python 3.11 and doesn't work on Windows 11 / Python 3.12. I suspect Windows, because a change in the way Python 3.12 uses shebang lines should be visible in the documentation. The shebang support in the Python Launcher is documented here: https://docs.python.org/3/using/windows.html#shebang-lines That says the line you list originally: > My shebang line is usually "#!/usr/bin/env python3" means look for python3 in PATH. Do you have one? If you don't have one, you'll get one you don't want: the stupid Microsoft shim that, which if run interactively, encourages you to install from the Microsoft store. You should be able to disable this. File suffix associations are a different thing - they give me no end of headaches on Windows. They start out bound to the shim, and should rebind to the launcher when you install, but then things can steal it. If you install Visual Studio Code with Python extensions, then it takes over the running of .py files - if you click in the explorer, you'll get it open in the editor, not run. I've argued about this, to no avail (plays havoc with my testsuite, which in some places tries to execute Python scripts as a cli command). And then I've got this: C:\Users\mats\SOMEWHERE>py -0 -V:3.13 Python 3.13 (64-bit) -V:3.12 *Python 3.12 (64-bit) -V:3.11 Python 3.11 (64-bit) -V:3.10 Python 3.10 (64-bit) -V:3.9 Python 3.9 (64-bit) -V:3.8 Python 3.8 (64-bit) -V:3.7 Python 3.7 (64-bit) -V:3.6 Python 3.6 (64-bit) # Okay, it knows about lots of Python versions, and shows a default of 3.12 C:\Users\mats\SOMEWHERE>py Python 3.12.1 (tags/v3.12.1:2305ca5, Dec 7 2023, 22:03:25) [MSC v.1937 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> ^Z # Great, that works just as expected C:\Users\mats\SOMEWHERE>py test.py Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases. # wait, what? if "py" worked, why doesn't "py test.py"? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
On 1/1/24 07:11, Thomas Passin via Python-list wrote: Here's how to find out what program Windows thinks it should use to run a ".py" file. In a console: C:\Users\tom>assoc .py .py=Python.File C:\Users\tom>ftype Python.file Python.file="C:\Windows\py.exe" "%L" %* That's not enough. There is now (has been for a while) a layered system, and this gives you just one layer, there may be other associations that win out. Per somebody who actually knows: > The only way to determine the association without reimplmenting the shell's search is to simply ask the shell via AssocQueryString. Possibly PowerShell can provide this information. – Eryk Sun -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
On 1/1/24 12:53, Thomas Passin via Python-list wrote: On Windows 10, a shebang line gets ignored in favor of Python 3.9.9 (if invoked by the script name alone) or Python 3.12.1 (if invoked by the "py" launcher). fwiw, you can also create an ini file to define to the launcher py which version should be the default, if no version is specified. -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 1/11/24 11:27, MRAB via Python-list wrote: On 2024-01-11 18:08, Rich Shepard via Python-list wrote: It's been several years since I've needed to write a python script so I'm asking for advice to get me started with a brief script to separate names and email addresses in one file into two separate files: salutation.txt and emails.txt. An example of the input file: Calvin [email protected] Hobbs [email protected] Nancy [email protected] Sluggo [email protected] Having extracted salutations and addresses I'll write a bash script using sed and mailx to associate a message file with each name and email address. I'm unsure where to start given my lack of recent experience. From the look of it: 1. If the line is empty, ignore it. 2. If the line contains "@", it's an email address. 3. Otherwise, it's a name. 4. Don't assume it's going to be "plain text" if the email info is harvested from external sources (like incoming emails) - you'll end up stumbling over a 誰かのユーザー from somewhere. Process as bytes, or be really careful about which encodings you allow - which for email "names" is something you can't actually control. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
On 1/15/24 09:44, Sibylle Koczian via Python-list wrote: First and foremost I want to understand why I'm seeing this: - Python scripts with "/usr/bin/env python3" as shebang line work as expected on a computer with Windows 10 and Python 3.11.5. They have worked for years on this machine, using either the latest Python or one version before (depending on availability of some packages). There is a virtual machine with ArchLinux on the same machine and some of the scripts are copies from that. - I've got a second computer with Windows 11 and I installed Python 3.12.1 on it. After copying some scripts from my first computer I found that I couldn't start them: not by entering the script name in a console, not using py.exe, not double clicking in the explorer. Entering \python probably worked - I think I tried that too, but I'm not really sure, because that's really not practical. In the Python documentation for versions 3.11 and 3.12 I found no differences regarding py.exe and shebang lines. Then I removed the "/env" from the shebang lines and could start the scripts from the second computer. That certainly is a solution, but why??? It's because of Windows itself. The default nowadays is that irritating little stub that prompts you to go install Python from the WIndows store. When you use the "env" form, it looks for python (or python3 in your case) in the PATH *first* and you'll get a hit. Mine looks like: C:\Users\mats\AppData\Local\Microsoft\WindwsApps\python.exe and python3.exe you can check what it's doing for you by using the "where" command in a windows shell. On your older Windows 10 machine you either never had that stub - I don't know when it was added, maybe someone from Microsoft listening here knows - or it's been superseded by changes to the PATH, or something. On my fairly new Win 11 box the base of that path is early in the user portion of PATH, so that must be a default. py.exe without the "/usr/bin/env" magic doesn't put PATH searching first, according to that snip from the docs that's been posted here several times., so you shouldn't fall down that particular rathole. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
On 1/15/24 09:44, Sibylle Koczian via Python-list wrote: In the Python documentation for versions 3.11 and 3.12 I found no differences regarding py.exe and shebang lines. Then I removed the "/env" from the shebang lines and could start the scripts from the second computer. That certainly is a solution, but why??? Sibylle also, it looks like you can disable the PATH-searching behavior of the /usr/bin/env virtual path: > The environment variable PYLAUNCHER_NO_SEARCH_PATH may be set (to any value) to skip this search of PATH. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
On 1/15/24 12:01, Thomas Passin via Python-list wrote: On 1/15/2024 1:26 PM, Mats Wichmann via Python-list wrote: On 1/15/24 09:44, Sibylle Koczian via Python-list wrote: First and foremost I want to understand why I'm seeing this: - Python scripts with "/usr/bin/env python3" as shebang line work as expected on a computer with Windows 10 and Python 3.11.5. They have worked for years on this machine, using either the latest Python or one version before (depending on availability of some packages). There is a virtual machine with ArchLinux on the same machine and some of the scripts are copies from that. - I've got a second computer with Windows 11 and I installed Python 3.12.1 on it. After copying some scripts from my first computer I found that I couldn't start them: not by entering the script name in a console, not using py.exe, not double clicking in the explorer. Entering \python probably worked - I think I tried that too, but I'm not really sure, because that's really not practical. In the Python documentation for versions 3.11 and 3.12 I found no differences regarding py.exe and shebang lines. Then I removed the "/env" from the shebang lines and could start the scripts from the second computer. That certainly is a solution, but why??? It's because of Windows itself. The default nowadays is that irritating little stub that prompts you to go install Python from the WIndows store. When you use the "env" form, it looks for python (or python3 in your case) in the PATH *first* and you'll get a hit. Mine looks like: C:\Users\mats\AppData\Local\Microsoft\WindwsApps\python.exe and python3.exe you can check what it's doing for you by using the "where" command in a windows shell. On your older Windows 10 machine you either never had that stub - I don't know when it was added, maybe someone from Microsoft listening here knows - or it's been superseded by changes to the PATH, or something. On my fairly new Win 11 box the base of that path is early in the user portion of PATH, so that must be a default. py.exe without the "/usr/bin/env" magic doesn't put PATH searching first, according to that snip from the docs that's been posted here several times., so you shouldn't fall down that particular rathole. Python from the App Store is not the same as Python from python.org: yes. this question is about the python.org distribution. but, Windows natively has something called python.exe and python3.exe which is interfering here, IF the python.org install isn't directed to put itself into the path, AND if the "#!/usr/bin/env python3" form is used, causing a search in PATH, which is the setup Sibylle has described, unless I've misunderstood details. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.12.1, Windows 11: shebang line #!/usr/bin/env python3 doesn't work any more
On 1/16/24 10:00, Sibylle Koczian via Python-list wrote: Am 15.01.2024 um 23:55 schrieb Mats Wichmann via Python-list: On 1/15/24 12:01, Thomas Passin via Python-list wrote: On 1/15/2024 1:26 PM, Mats Wichmann via Python-list wrote: Python from the App Store is not the same as Python from python.org: yes. this question is about the python.org distribution. but, Windows natively has something called python.exe and python3.exe which is interfering here, IF the python.org install isn't directed to put itself into the path, AND if the "#!/usr/bin/env python3" form is used, causing a search in PATH, which is the setup Sibylle has described, unless I've misunderstood details. No, you didn't misunderstand any detail. It's exactly right. My Windows 10 box doesn't find anything for "where python", "where python3", Be interesting to know if your WIndows 10 has those files in place, and it's just a missing path entry (a good thing, perhaps) that's causing it not to be found there. while the new Windows 11 machine finds the Microsoft stub. "Irritating" is a very friendly attribute for that thing. Why must it be called "python.exe" and not something else like the installation files from python.org? it will be replaced by the real "python.exe" from the Microsoft Store install, if you go ahead and install that - I guess that's why that name was chosen. I'll stop using "/env" - hopefully that won't create problems with the scripts I use in the Linux VM. But in that case I'll know what's up. Thank you very much! Sibylle -- https://mail.python.org/mailman/listinfo/python-list
Re: PyTorch
On 1/17/24 09:48, Alan Zaharia via Python-list wrote: Hello Python I Need help. it could not be found for PyTorch. It said in the Command Prompt ERROR: Could not find a version that satisfies the requirement torch (from versions: none) ERROR: No matching distribution found for torch, Can you help me? Use Python 3.11. Or follow here: https://github.com/pytorch/pytorch/issues/110436 -- https://mail.python.org/mailman/listinfo/python-list
Re: Assistance Needed: Corrupted Python Installation Uninstallation Issue
On 1/29/24 05:19, Syed Hamood via Python-list wrote: Dear Python.org Support Team, I hope this email finds you well. I am writing to seek assistance with an issue I'm encountering while attempting to uninstall a corrupted Python installation on my system. Details of my system: - Operating System: Windows 10 - Python Version: 3.11.3(64-bit) - Installation Method: installer from Python.org Description of the issue: [Provide a brief description of the problem you're facing, any error messages received, or specific steps you've taken so far.] I have already tried the following: - Deleting python. removing corrupted files from command prompt with administrative privileges. However, despite my efforts, I have been unable to successfully uninstall the corrupted Python installation. The more stuff you remove by hand the harder it is for the Windows installer to act to do an uninstall. This tool usually helps if things are badly messed up: https://support.microsoft.com/en-us/topic/fix-problems-that-block-programs-from-being-installed-or-removed-cca7d1b6-65a9-3d98-426b-e9f927e1eb4d Haven't used it for a while, but after it tries basic overall repairs to the installation subsystem (which is probably okay), there are prompts you can follow to point to a specific program that doesn't want to uninstall. -- https://mail.python.org/mailman/listinfo/python-list
Re: Aw: Re: Extract lines from file, add to new files
On 1/30/24 14:46, AVI GROSS via Python-list wrote: Rich, You may want to broaden your perspective a bit when people make suggestions. Karsten did not spell out a full design and should not need to. But consider this as a scenario. You want to send (almost) the same message to one or more recipients. So call a program, perhaps some variant on a shell script, that does some prep work such as maybe creating a temporary or working directory/folder. Had one copy of your message ready in a file somewhere, Have a way to get a list of recipients intended and the file or files containing enough info to link email addresses to human names and anything else such as their preferred pronoun or address. I'd say based on the bits of the problem description I *have* absorbed, which almost certainly isn't all of them, there's a fairly basic capability, not terribly often used in my experience, that might be of some use: https://docs.python.org/3/library/string.html#template-strings -- https://mail.python.org/mailman/listinfo/python-list
Re: Extract lines from file, add to new files
On 2/3/24 10:58, Thomas Passin via Python-list wrote: In my view this whole thread became murky and complicated because the OP did not write down the requirements for the program. Requirements are needed to communicate with other people. An individual may not need to actually write down the requirements - depending on their complexity - but they always exist even if only vaguely in a person's mind. The requirements may include what tools or languages the person wants to use and why. If you are asking for help, you need to communicate the requirements to the people you are asking for help from. The OP may have thought the original post(s) contained enough of the requirements but as we know by now, they didn't. The person asking for help may not realize they don't know enough to write down all the requirements; an effort to do so may bring that lack to visibility. Mailing lists like these have a drawback that it's hard to impossible for someone not involved in a thread to learn anything general from it. We can write over and over again to please state clearly what you want to do and where the sticking points are, but newcomers post new questions without ever reading these pleas. Then good-hearted people who want to be helpful end up spending a lot of time trying to guess what is actually being asked for, and maybe never find out with enough clarity. Others take a guess and then spend time working up a solution that may or may not be on target. So please! before posting a request for help, write down the requirements as best you can figure them out, and then make sure that they are expressed such that the readers can understand. Indeed. I've occasionally practised the following technique (in some form) over the years without knowing it had grown a name, and wikipedia page to go with it. It may be handy to use to help come up with a clearer explanation before sending off a post to a mailing list or other static medium, because of the inevitable delays in going back and forth. Interactive formus like the Python Discord have a bit of an advantage in that you can try to tease out the intent more quickly. But as you say... a newcomer won't know this. https://en.wikipedia.org/wiki/Rubber_duck_debugging -- https://mail.python.org/mailman/listinfo/python-list
Re: Using __new__
On 2/17/24 19:24, dn via Python-list wrote: On 18/02/24 13:21, Jonathan Gossage wrote: - perhaps someone knows a better/proper way to do this? Suggested research: custom classes, ABCs, and meta-classes... Cure the old "what do you want to accomplish" question. If it's to channel access to a resource to a single place, many folks seem to advocate just putting that code in a module, and not trying to use a class for that - Python already treats modules as a form of singleton (if you squint a bit). It's not Java, after all, everything doesn't _have_ to be a class. I'd also second the idea of looking at metaclasses for an implementation. Most simpler class-based singleton approaches turn out not to be thread-safe... you can get closer to solving that with a metaclass with a lock taken in the dunder-call method. -- https://mail.python.org/mailman/listinfo/python-list
Re: Can u help me?
On 3/5/24 18:44, Ethan Furman via Python-list wrote: On 3/5/24 16:49, MRAB via Python-list wrote: > On 2024-03-06 00:24, Ethan Furman via Python-list wrote: >> On 3/5/24 16:06, Chano Fucks via Python-list wrote: >> >>> [image: image.png] >> >> The image is of MS-Windows with the python installation window of "Repair Successful". Hopefully somebody better at >> explaining that problem can take it from here... >> > If the repair was successful, what's the problem? I imagine the issue is trying get Python to run (as I recall, the python icon on the MS-Windows desktop is the installer, not Python itself). that's often it, yes - you keep getting the installer when you think you should get a snazzy Python window. Of course, you don't - Python is a command-line/terminal program, not a windows app. Now if you tried to launch IDLE instead, you'd get at least a window. But we're just guessing here. Perhaps Chano will come back with an updated question with some details. -- https://mail.python.org/mailman/listinfo/python-list
Re: Variable scope inside and outside functions - global statement being overridden by assignation unless preceded by reference
On 3/6/24 05:55, Jacob Kruger via Python-list wrote: Ok, simpler version - all the code in a simpler test file, and working with two separate variables to explain exactly what am talking about: If you import the contents of that file into the python interpreter, dt_expiry will start off as "1970-01-01 00:00", and, if you execute do_it function, it will print out the new value assigned to the dt_expiry variable inside that function, but if you then again check the value of the dt_expiry variable afterwards, it's reverted to the 1970... value? If I take out the line that removes values from l_test # l_test.clear() # before appending new value to it, then it will also not retain it's new/additional child items after the function exits, and will just revert back to [1, 2, 3] each and every time. In other words, with some of the variable/object types, if you use a function that manipulates the contents of a variable, before then re-assigning it a new value, it seems like it might then actually update/manipulate the global variable, but, either just calling purely content retrieval functions against said objects, or assigning them new values from scratch seems to then ignore the global scope specified in the first line inside the function? Hope this makes more sense No, it doesn't. Your code is working as one would expect. For example, adding prints for the l_test variable, and removing the .clear() which you claim makes it not work, shows me: before: l_test=[1, 2, 3], id(l_test)=140153285385856 leaving do_it: l_test=[1, 2, 3, 1, 2, 3, 99], id(l_test)=140153285385856 after: l_test=[1, 2, 3, 1, 2, 3, 99], id(l_test)=140153285385856 It's the same list object, as you can see by the id values. And the list is updating as expected. And... you don't need the global statement for l_test. As it's mutable, you can mutate it in the function; the global only acts on assignment. Using "global" for that may make your intent more clear to readers though, although static checkers will grumble at you. You must be doing something additional that you're not telling us about. -- https://mail.python.org/mailman/listinfo/python-list
Re: If a dictionary key has a Python list as its value!
On 3/7/24 07:11, Varuna Seneviratna via Python-list wrote:
If a dictionary key has a Python list as its value, you can read the values
one by one in the list using a for-loop like in the following.
d = {k: [1,2,3]}
for v in d[k]:
print(v)
No tutorial describes this, why?
What is the Python explanation for this behaviour?
Sorry... why is this a surprise? If an object is iterable, you can
iterate over it.
>>> d = {'key': [1, 2, 3]}
>>> type(d['key'])
>>> val = d['key']
>>> type(val)
>>> for v in val:
... print(v)
...
...
1
2
3
>>>
--
https://mail.python.org/mailman/listinfo/python-list
Re: Configuring an object via a dictionary
On 3/15/24 03:30, Loris Bennett via Python-list wrote:
Hi,
I am initialising an object via the following:
self.source_name = config['source_name']
config.get('source_name', default_if_not_defined) is a common technique...
--
https://mail.python.org/mailman/listinfo/python-list
Re: the name ``wheel''
On 3/22/24 11:45, Barry via Python-list wrote: On 22 Mar 2024, at 15:25, Gilmeh Serda via Python-list wrote: Many if not most Linux distributions do not include pip by default. Really? It came with Manjaro. Debian and Ubuntu require you to install pip as a separate package. Also puts venv in its own package. Fedora leaves all the batteries intact and rhel I assume. pip is still a separate package in the .rpm world. which makes sense on a couple of levels: * pip releases on its own cycle, you wouldn't want to have to *force* a new release of python + python-libs + python-devel + maybe others, if you happened want to rev pip forward independently. * in a distro-packaged world, that's the primary place you get your Python packages from, and pip isn't seen as being as necessary, and potentially even as destructive. How many times have you seen an article that suggests you "sudo pip install randompackage"? Many distro setups now disallow installing like that. If you know what you're doing, and particularly if you're happy to control a specific environment by setting up a virtualenv, then fine, you'll still have access to everything you need. anyway, I seem to recall the original message (which I've since deleted) was asking about Windows anyway. There it's quite unusual to end up without pip, but not so unusual to end up without the *command* named pip - search path things, and all that. Usually if you "py -m pip --version" you'll see it's actually installed, just not accessible using the current search path. -- https://mail.python.org/mailman/listinfo/python-list
Re: xkcd.com/353 ( Flying with Python )
On 3/30/24 10:31, MRAB via Python-list wrote: On 2024-03-30 11:25, Skip Montanaro via Python-list wrote: > https://xkcd.com/1306/ > what does SIGIL mean? I think its' a Perl term, referring to the $/@/# symbols in front of identifiers. I wouldn't consider '@' to be a sigil any more than I would a unary minus. Nonetheless, Perl folk do use that term, specifically. "One thing that distinguishes Perl from other languages is its use of sigils; the funny looking symbols placed in front of variable names. " $ Scalar $foo @ Array @foo % Hash%foo & Subroutine &foo * Typeglob*foo >Sigils have many benefits, not least of which is that variables can be interpolated into strings with no additional syntax. Perl scripts are also easy to read (for people who have bothered to learn Perl!) because the nouns stand out from verbs. And new verbs can be added to the language without breaking old scripts. >Programming Perl, Chapter 1, 4th Edition etc. -- https://mail.python.org/mailman/listinfo/python-list
Re: Running issues
On 4/5/24 15:32, shannon makasale via Python-list wrote: Hi there, My name is Shannon. I installed Python 3.12 on my laptop a couple months ago, but realised my school requires me to use 3.11.1. they can suggest 3.11 and there might be a good reason for that, but you should not worry about something as specific as "3.11.1" - use the latest release in the 3.11 series. I uninstalled 3.12 and installed 3.11.1. Unfortunately, I am unable to run python now. It keeps asking to be modified, repaired or uninstalled. Do you have any suggestions on how to fix this? I think it's been covered in previous replies, but to be even more explicit: *Don't* re-run the Python Installer. Windows will sort of "remember" it and may present it to you when you try to launch, and for some reason the core team appears unwilling to name it something less ambiguous, like python_setup, despite that having been requested several times over the years. You would probably do well to just remove that file (for the case you've described, python-3.11.1-amd64.exe). Python itself is a command-line tool. You can launch python from inside a command shell (Windows Terminal is actually a good choice, even though it's not installed by default), usually by typing "py" (unless you somehow declined to install the Python launcher), or you can navigate to it through the start menu. You will, however, probably want to use some sort of editor to work inside or it gets quite tedious. You can use the included IDLE also via the start menu, or install one of the many free choices available. Your school's curriculum may well guide you here, if you want to be able to follow along exactly with classroom presentation, screenshots, etc. -- https://mail.python.org/mailman/listinfo/python-list
Re: ModuleNotFoundError: No module named 'Paramiko'
On 4/7/24 19:31, Wenyong Wei via Python-list wrote:
Dear Sir/Madam,
Recently I encounter a problem that I can't import paramiko in my computer. My
PC running on window 10 64 bits. I have investigate this issue via internet,
there are a lot of solutions for this issue, after trying most of the steps, I
still can't run this module, the major steps I have try are:
1.
Install python ver 3.7.1 or 3.11.8 by itself or customer installation (changing
the installation folder) and check add python to the path.
2.
pip install paramiko, if ver 3.7.1 installed, need to upgrade the pip version.
3.
Checking the environment path, there are two path related to the python, one
for python.exe, the other for \Lib\site-packages\paramiko
can you please provide advice on this issue?
Going to be more explicit than the other answers:
===
If an attempted import gives you ModuleNotFound, that *always* means the
package is not installed... not at all, or just not in the paths that
copy of Python is looking in.
===
The problem arises in part because most package installation
instructions take the simplest approach and just tell you to (for example)
pip install paramiko
So it's installed. But where did it go? You can check where it went:
pip show paramiko
That path ("location") needs to be one where your Python interpreter is
looking.
If all goes well, "pip" and "python" are perfectly matched, but in the
current world, there are often several Python interpreters installed
(projects may require a specific version, an IDE may grab its own
version, something may create and setup a virtualenv, alternate worlds
like Conda may set up a Python, the list goes on), and for any given
installation on Windows, python.exe and the pip excutable pip.exe go in
different directories anyway, and the Windows PATH doesn't always
include both, and you easily get mismatches.
As others have said, the way to avoid mismatches is to use pip As A
Module, specifically a module of the Python you want to use. So if
you're using the Python Launcher, that looks like:
py -m pip install paramiko
Hope this helps.
--
https://mail.python.org/mailman/listinfo/python-list
Re: help: pandas and 2d table
On 4/13/24 07:00, jak via Python-list wrote:
Stefan Ram ha scritto:
jak wrote or quoted:
Would you show me the path, please?
I was not able to read xls here, so I used csv instead; Warning:
the script will overwrite file "file_20240412201813_tmp_DML.csv"!
import pandas as pd
with open( 'file_20240412201813_tmp_DML.csv', 'w' )as out:
print( '''obj,foo1,foo2,foo3,foo4,foo5,foo6
foo1,aa,ab,zz,ad,ae,af
foo2,ba,bb,bc,bd,zz,bf
foo3,ca,zz,cc,cd,ce,zz
foo4,da,db,dc,dd,de,df
foo5,ea,eb,ec,zz,ee,ef
foo6,fa,fb,fc,fd,fe,ff''', file=out )
df = pd.read_csv( 'file_20240412201813_tmp_DML.csv' )
result = {}
for rownum, row in df.iterrows():
iterator = row.items()
_, rowname = next( iterator )
for colname, value in iterator:
if value not in result: result[ value ]= []
result[ value ].append( ( rowname, colname ))
print( result )
In reality what I wanted to achieve was this:
what = 'zz'
result = {what: []}
for rownum, row in df.iterrows():
iterator = row.items()
_, rowname = next(iterator)
for colname, value in iterator:
if value == what:
result[what] += [(rowname, colname)]
print(result)
In any case, thank you again for pointing me in the right direction. I
had lost myself looking for a pandas method that would do this in a
single shot or almost.
doesn't Pandas have a "where" method that can do this kind of thing? Or
doesn't it match what you are looking for? Pretty sure numpy does, but
that's a lot to bring in if you don't need the rest of numpy.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Issues with uninstalling python versions on windows server
On 5/3/24 05:55, Tripura Seersha via Python-list wrote: Hi Team, I am working on an automation related to uninstalling and installing python versions on different windows servers. I have observed that uninstallation is working only with the account/login using which the python version is installed. But for automation, we are not aware which account is being used for installation on different machines. If you want to automate things properly, you need to control installation as well as uninstallation - if things are just installed via some random user account it's hard to see how you can expect later steps without that knowledge to work out. There's a fair bit of control available; if you haven't already, take a look here: https://docs.python.org/3/using/windows.html#installing-without-ui -- https://mail.python.org/mailman/listinfo/python-list
Re: Issues with uninstalling python versions on windows server
On 5/10/24 03:39, Tripura Seersha via Python-list wrote: Hi Barry, Automation is using the system account using which the installation is failing with exit code 3. This account has the administrative privileges. Please help me with this issue. Thanks, Seersha You probably have a better chance of finding the attention of people who know about the details either on the Python Discuss board (discuss.python.org), or by filing an issue - after first checking someone else isn't wrestling with the same problem you are - there are a number of uninstall-related issues open (https://github.com/python/cpython/issues) In particular, I see that this part of your issue: > I have observed that uninstallation is working only with the account/login using which the python version is installed seems to be a known problem, where the user who initiated the install has the uninstall registered to their account - see https://github.com/python/cpython/issues/69353 -- https://mail.python.org/mailman/listinfo/python-list
Re: Terminal Emulator (Posting On Python-List Prohibited)
On 5/18/24 10:48, Grant Edwards via Python-list wrote: On 2024-05-18, Peter J. Holzer via Python-list wrote: On 2024-05-16 19:46:07 +0100, Gordinator via Python-list wrote: To be fair, the problem is the fact that they use Windows (but I guess Linux users have to deal with venvs, so we're even. I don't think Linux users have to deal with venvs any more than Windows users. Maybe even less because many distributions come with a decent set of Python packages. I've been using Python on Linux almost daily for 25 years, same here, but: and I've yet to use a venv... Distros have do offer a good selection of packaged Python bits, yes, but only for the version of Python that's "native" to that distro release. If you need to test other versions of Python, you're mostly on your own. Just as an example, for a particular project I had one test machine running Fedora 38 until just a couple weeks ago, with Python 3.11 as "native" with a full suite of packages, but I needed to test 3.12 and then the 3.13 pre-releases, as well as occasionally sanity-check the "oldest supported Python for this project", which turned out to be 3.6. I could build all those Pythons myself and install them to a location I can "python3.xx -m pip install" to, but Fedora is nice enough to package up a whole bunch of past and future Python versions, so why? And Fedora really discourages doing installs via pip to a system-packaged Python. So venvs make managing all that pretty convenient. Dunno why everybody's so down on venvs... -- https://mail.python.org/mailman/listinfo/python-list
Re: Flubbed it in the second interation through the string: range error... HOW?
On 5/29/24 08:02, Grant Edwards via Python-list wrote:
On 2024-05-29, Chris Angelico via Python-list wrote:
print(f"if block {name[index]=} {index=}")
Holy cow! How did I not know about the f-string {=} thing?
It's more recent than f-strings in general, so it's not that hard to miss.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Serializing pydantic enums
On 5/29/24 13:27, Larry Martell via Python-list wrote: On Tue, May 28, 2024 at 11:46 AM Left Right via Python-list wrote: Most Python objects aren't serializable into JSON. Pydantic isn't special in this sense. What can you do about this? -- Well, if this is a one-of situation, then, maybe just do it by hand? If this is a recurring problem: json.dumps() takes a cls argument that will be used to do the serialization. Extend json.JSONEncoder and implement the encode() method for the encoder class you are passing. I believe that the official docs have some information about this too. Yeah, I know I can do this, but I seem to recall reading that pydantic handled serialization. Guess not. Pydantic devotes some of its documentation to serialization. https://docs.pydantic.dev/latest/concepts/serialization/ As noted elsewhere, some Python objects are easy to serialize, some you need to provide some help. Consider pickling: if you write a class that isn't obviously pickleable, the getstate dunder method can be defined to help out. For Pydantic, there's a couple of ways... aliases in particular seem designed to help: there's a serialization_alias argument to the Field function. -- https://mail.python.org/mailman/listinfo/python-list
Re: From JoyceUlysses.txt -- words occurring exactly once
On 5/31/24 11:59, Dieter Maurer via Python-list wrote:
hmmm, I "sent" this but there was some problem and it remained unsent.
Just in case it hasn't All Been Said Already, here's the retry:
HenHanna wrote at 2024-5-30 13:03 -0700:
Given a text file of a novel (JoyceUlysses.txt) ...
could someone give me a pretty fast (and simple) Python program that'd
give me a list of all words occurring exactly once?
Your task can be split into several subtasks:
* parse the text into words
This depends on your notion of "word".
In the simplest case, a word is any maximal sequence of non-whitespace
characters. In this case, you can use `split` for this task
This piece is by far "the hard part", because of the ambiguity. For
example, if I just say non-whitespace, then I get as distinct words
followed by punctuation. What about hyphenation - of which there's both
the compound word forms and the ones at the end of lines if the source
text has been formatted that way. Are all-lowercase words different
than the same word starting with a capital? What about non-initial
capitals, as happens a fair bit in modern usage with acronyms,
trademarks (perhaps not in Ulysses? :-) ), etc. What about accented letters?
If you want what's at least a quick starting point to play with, you
could use a very simple regex - a fair amount of thought has gone into
what a "word character" is (\w), so it deals with excluding both
punctuation and whitespace.
import re
from collections import Counter
with open("JoyceUlysses/txt", "r") as f:
wordcount = Counter(re.findall(r'\w+', f.read().lower()))
Now you have a Counter object counting all the "words" with their
occurrence counts (by this definition) in the document. You can fish
through that to answer the questions asked (find entries with a count of
1, 2, 3, etc.)
Some people Go Big and use something that actually tries to recognize
the language, and opposed to making assumptions from ranges of
characters. nltk is a choice there. But at this point it's not really
"simple" any longer (though nltk experts might end up disagreeing with
that).
--
https://mail.python.org/mailman/listinfo/python-list
Re: From JoyceUlysses.txt -- words occurring exactly once
On 6/5/24 05:10, Thomas Passin via Python-list wrote: Of course, we see this lack of clarity all the time in questions to the list. I often wonder how these askers can possibly come up with acceptable code if they don't realize they don't truly know what it's supposed to do. Fortunately, having to explain to someone else why something is giving you trouble can help shed light on the fact the problem statement isn't clear, or isn't clearly understood. Sometimes (sadly, many times it doesn't). -- https://mail.python.org/mailman/listinfo/python-list
Re: Anonymous email users
On 6/17/24 17:51, dn via Python-list wrote: +1 The "public" part is not to embarrass posters, but recognition that there are likely other people 'out there' (or arriving in-future if they care to read the archives) experiencing a similar problem. (hence need for descriptive Subject lines - isn't the most difficult task in programming 'choosing names'?) well, one of two, along with cache invalidation and off-by-one errors (according to the wags). I do agree with this, but mailman (2) archives aren't particularly useful for searching, as they're organized in monthly chunks and you have to keep clicking around - this list doesn't have a search engine as it's not converted to be one of the mailman 3 lists. There are supposed to be some search engine incantations to make this better. I find this one works, though I can never actually remember it and have to go hunting again each time... picking a random-ish subject line from this list in the past: site:mail.python.org inurl:Python-list multiplication I don't know that we publicise such methods (there are probably others). -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] How to install tensorflow on Python 2.7 in Windows?
On 6/26/24 09:29, marc nicole wrote: Browsing the available version of tensorflow for the dates before January 2021 (date when Python 2.7 stopped being supported) I can't find a tensorflow version for Python 2.7 that works under Windows. The reference site I use is https://pypi.org/project/tensorflow/ Anybody can point out a compatible .whl file with Python 2.7 and Windows? The last version of tensorflow to support Python 2.7 was indeed 2.1, and I don't think there was *ever* an official Windows wheel for Python 2, but I'm not that expert to be completely sure. tensorflow support on Windows has never been good, and in a way they've given up, at least part of the fight: they no longer produce official releases for Windows with GPU support (although you may be able to get one from the vendor that produces the GPU hardware like Nvidia or Intel, or from a third party like Amazon Web Services). The official recommendation for WIndows used to be "build your own" (which nearly always failed), then for a few years they tried making Windows builds, now the new "best practice" recommendation is to install on WSL if you want to run on a Windows box (this *might* work for you, unless you're also on an ancient Windows that won't run WSL). Or, try seeing if you can find a docker setup (which, again, will give you a Linux environment running tensorflow). Note that like your other problem, getting numpy going, this is going to be an uphill battle trying to cobble things together to run on 2.7. This is really the problem when something like Python goes out of date / out of support: it's not that it magically stops working, it's that vast amounts of the ecosystem around it stop providing support for *their* bits on the old version, and the combinations become progressively harder to make work. -- https://mail.python.org/mailman/listinfo/python-list
Re: Difference method vs attribut = function
On 6/28/24 10:08, Ulrich Goebel via Python-list wrote: By the way: in my usecase I want to pass different functions to different instances of MyClass. It is in the context of a database app where I build Getters for database data and pass one Getter per instance. If I understood what you're trying to accomplish, you could take a look here (possibly a bit complex for what you need). https://refactoring.guru/design-patterns/strategy/python/example -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue with pip Installation on My Laptop
On 7/26/24 16:28, Thomas Passin via Python-list wrote: On 7/26/2024 7:25 AM, Lizna Shah via Python-list wrote: OSError: [WinError 225] Operation did not complete successfully because the file contains a virus or potentially unwanted software That part of the error message tells you the story. Windows thinks some file in the install has been corrupted with malware. The Windows installer comes with pip, there's no need to do an extra install to get it: python -m pip --version If you can't find the pip *command*, that's a problem with yout PATH settings. The Python installer offers to add the location of Python itself to PATH, and you've apparently taken it up on that offer, but that's not the same directory that pip goes to. Just use it as a module and you should be fine. === The typical paths will be something like C:\Users\you\AppData\Local\Programs\Python\Python310 # python executable C:\Users\you\AppData\Local\Programs\Python\Python310\Scripts # pip "executable" -- https://mail.python.org/mailman/listinfo/python-list
Re: Issue with pip Installation on My Laptop
On 7/27/24 17:13, MRAB via Python-list wrote: On 2024-07-27 21:58, Mats Wichmann via Python-list wrote: On 7/26/24 16:28, Thomas Passin via Python-list wrote: On 7/26/2024 7:25 AM, Lizna Shah via Python-list wrote: OSError: [WinError 225] Operation did not complete successfully because the file contains a virus or potentially unwanted software That part of the error message tells you the story. Windows thinks some file in the install has been corrupted with malware. The Windows installer comes with pip, there's no need to do an extra install to get it: python -m pip --version On Windows it's recommended that you use the Python Launcher 'py': py -m pip --version I agree! :-) but since the OP had apparently done enough to get the command named "python" to work, was trying to not introduce one extra factor. -- https://mail.python.org/mailman/listinfo/python-list
Re: Help needed - - running into issues with python and its tools
On 8/3/24 20:03, o1bigtenor via Python-list wrote: My question was, is and will be (and the doc absolutely doesn't cover it) how do I install a different version in the venv so that python 3.11.x on the system is not discombobulated by the python 3.12.x in the venv. That python 3.12 would let me run the tools needed. (Its the how to install the next version of python that I just haven't been able to find information on - - - and I would be looking for information on how to install on a *nix.) To get a different Python "in" the venv, you use the version you want in the construction of the venv. For example: $ python3.13 -m venv new_venv $ new_venv/bin/python --version Python 3.13.0b4 $ source new_venv/bin/activate ... -- https://mail.python.org/mailman/listinfo/python-list
Re: Help needed - - running into issues with python and its tools
On 8/5/24 06:48, o1bigtenor via Python-list wrote: On Sun, Aug 4, 2024 at 8:49 AM Mats Wichmann via Python-list < [email protected]> wrote: On 8/3/24 20:03, o1bigtenor via Python-list wrote: My question was, is and will be (and the doc absolutely doesn't cover it) how do I install a different version in the venv so that python 3.11.x on the system is not discombobulated by the python 3.12.x in the venv. That python 3.12 would let me run the tools needed. (Its the how to install the next version of python that I just haven't been able to find information on - - - and I would be looking for information on how to install on a *nix.) To get a different Python "in" the venv, you use the version you want in the construction of the venv. For example: $ python3.13 -m venv new_venv $ new_venv/bin/python --version Python 3.13.0b4 $ source new_venv/bin/activate "https://peps.python.org/pep-0668/ PEP 668, which prevents pip from interacting with the OS installed python. This change has been done in red hat and other distros too . . . " similarly your first command produces and error code for the same reason. Sorry - - - not my policy - - - What? Yes, the *system* pip should have some restrictions, if it's a system mainly managed by a package manager. Setting up a venv is the *expected* approach to such situations, and creating one doesn't cause any problems. You end up with a pip in the activated venv that's going to install to a different path (the one in the venv), and will not be marked as externally managed, as the package manager has no control over that path. That's the whole point. What error are you getting? The venv module is not the pip module so restrictions on the system pip have nothing to do with it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Help needed - - running into issues with python and its tools
On 8/5/24 14:39, o1bigtenor wrote: Matt - if you would rather that you were not included in the address list - - please advise. On Mon, Aug 5, 2024 at 8:51 AM Mats Wichmann <mailto:[email protected]>> wrote: On 8/5/24 06:48, o1bigtenor via Python-list wrote: > On Sun, Aug 4, 2024 at 8:49 AM Mats Wichmann via Python-list < > [email protected] <mailto:[email protected]>> wrote: > >> On 8/3/24 20:03, o1bigtenor via Python-list wrote: >> >>> My question was, is and will be (and the doc absolutely doesn't cover it) >>> how do I install a different version in the venv so that python 3.11.x on >>> the >>> system is not discombobulated by the python 3.12.x in the venv. >>> That python 3.12 would let me run the tools needed. >>> (Its the how to install the next version of python that I just haven't >> been >>> able to find information on - - - and I would be looking for information >>> on how to install on a *nix.) >> >> To get a different Python "in" the venv, you use the version you want in >> the construction of the venv. For example: >> >> >> $ python3.13 -m venv new_venv >> $ new_venv/bin/python --version >> Python 3.13.0b4 >> $ source new_venv/bin/activate >> >> > "https://peps.python.org/pep-0668/ <https://peps.python.org/pep-0668/> PEP 668, which prevents pip from > interacting with the OS installed python. This change has been done in red > hat and other distros too . . . " > > similarly your first command produces and error code for the same reason. > > Sorry - - - not my policy - - - What? Yes, the *system* pip should have some restrictions, if it's a system mainly managed by a package manager. Setting up a venv is the *expected* approach to such situations, and creating one doesn't cause any problems. You end up with a pip in the activated venv that's going to install to a different path (the one in the venv), and will not be marked as externally managed, as the package manager has no control over that path. That's the whole point. What error are you getting? The venv module is not the pip module so restrictions on the system pip have nothing to do with it. set up pyenv activated a venv trying to install python3.12 into it 1. download of python3.12 (blahblahblahetc).deb will not install 2. download of python3.12.tar.xz similarly will not install (venv2) memyself@devuanbigbox:~$ pip install /home/memyself/Downloads/Python-3.12.4.tar.xz Processing ./Downloads/Python-3.12.4.tar.xz ERROR: file:///home/memyself/Downloads/Python-3.12.4.tar.xz does not appear to be a Python project: neither 'setup.py' nor 'pyproject.toml' found. seems that I need a different version (installable as it were) of python3.12 or my approach is all wrong! you can't install Python "into" a venv. you use a version of Python as the base when *creating* a venv, the venv will use the same binary as the base python (symlinks if possible, as in the Linux case), but with different paths. Since you've already got pyenv, use it to build the version you want to use - I think you said there wasn't a deb for 3.12 in your distro? That's something like pyenv install 3.12.4 that will use the build recipe it has... and hopefully work. Distro Pythons sometimes have some strange setups that are hard to reproduce. Pyenv knows how to build micropython, too, should it ever come to that. If you indeed found a deb for the right Python, use apt to install it, and then use *that* Python to create your venv. If you have the pyenv-virtualenv plugin, you can ask it to make the virtualenv for you, if pyenv built the Python -- https://mail.python.org/mailman/listinfo/python-list
Re: Help needed - - running into issues with python and its tools
On 8/5/24 15:17, o1bigtenor via Python-list wrote: That's something like pyenv install 3.12.4 $ pyenv install 3.12.4 bash: pyenv: command not found pyenv is not a 'global' package there is a mountain of /root/.pyenv files though there is also quite a number of /root/.pyenv/plugins/pyenv-virtualenv/ files when looking in the /root/.pyenv files I can find options for all the older version of python but none for anything newer than what is on my system is there something else to install to achieve this 'version freedom' that pyenv promises? It has to go somewhere your shell can find it. Mine is a shell function, but it was set up so many years ago I don't remember details. It's presumably the pyenv installation instructions... -- https://mail.python.org/mailman/listinfo/python-list
Re: Installation of Slixfeed with pip fails
On 8/11/24 07:42, Schimon Jehudah via Python-list wrote: Barry. Thomas. I agree. I do not have his machine to make observations, and therefore this report is obscured. I want to solve an issue of a friend who has attempted to install Slixfeed, which is based on OMEMO, and the installation has failed. I have asked him to install python-omemo and he has reported this: $ pip install omemo [...] ERROR Failed building wheel for XEdDSA ERROR Could not build wheels for XEdDSA, which is required to install pyproject.toml-based projects Please see the attached screenshot. Kind regards, Schimon No screenshot arrived here, but this is a pretty typical failure, especially on Windows systems: pip didn't find a suitable binary wheel package for the Python version / platform combination, and so tried to build one from sources. That often requires additional setup before it can work. The question would be why - I looked here: https://pypi.org/project/XEdDSA/#files and there are binary wheels for Windows, Linux, Mac for CPython 3.7 through 3.12, and also wheels for PyPy from 3.7 through 3.10, so unless your friend's machine doesn't fit that range, you'd expect that particular package to install okay. -- https://mail.python.org/mailman/listinfo/python-list
Re: troglodytes
On 8/14/24 17:53, Mike Dewhirst via Python-list wrote: I read Chris McDonough's defence of Tim Peters and he has convinced me. Not because of everything he said but because I have experience of committees. And other things. The problem is generational. Later generations can see the faults of earlier generations in brilliant hindsight. I certainly did. As another self-proclaimed troglodyte weighing in, I'm always suspicious of authority shifting with limited explanations, which seems to have been at the heart of the dispute. Questioning such is a responsibility many of us take seriously. However, I'd just like to point out: cultures evolve. Inclusivity is no longer obtained, as in our younger days, by saying "suck it up and get on with it". The steering council has this in their charter - PEP-13. These are not people who are making difficult choices for reasons of personal aggrandizement. -- https://mail.python.org/mailman/listinfo/python-list
Re: learning Python
On 10/27/24 16:51, o1bigtenor via Python-list wrote: Greetings There are mountains of books out there. Any suggestions for documents for a just learning how to program and starting with Python (3)? Preference to a tool where I would be learning by doing - - - that works well for me. TIA Frankly, the mountain of resources is so vast that none of us can have experience of more than a small fraction, and effective learning is a factor not only of the quality of the teacher/book/training course, but how it meshes with your own learning style. If you like learn-by-doing, you might take a look at PyBites (https://pybit.es/). But they're by no means the only players in that space! -- https://mail.python.org/mailman/listinfo/python-list
Re: FileNotFoundError thrown due to file name in file, rather than file itself
On 11/12/24 12:10, Left Right via Python-list wrote: Finally, if you want your logs to go to a file, and currently, your only option is stderr, your shell gives you a really, really simple way of redirecting stderr to a file. So, really, there aren't any excuses to do that. an awful lot of the programs that need to do extensive logging don't run under control of a shell, and thus "shell redirection" helps not at all. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python 3.8 or later on Debian?
On 9/18/24 08:49, Ulrich Goebel via Python-list wrote: Hi, Debian Linux seems to love Python 3.7 - that is shown by apt-get list, and it's installed on my Debian Server. But I need at least Python 3.8 Is there a repository which I can give to apt to get Python 3.8 or later? Or do I really have to install and compile these versions manually? I'm not a friend of things so deep in the system... Not going to pile on and tell you you must upgrade... You can use a tool like pyenv to build Python IF another answer doesn't present itself - it how to build just about any version (not just cpython, but pypy, anaconda and more). The Real Python folks have written a fairly complete description (plus of course there's the project's own documentation): https://realpython.com/intro-to-pyenv/ -- https://mail.python.org/mailman/listinfo/python-list
Re: Python List is Not Dead
On 12/29/24 15:10, Cameron Simpson via Python-list wrote: On 29Dec2024 07:16, Kevin M. Wilson wrote: Excuse please, my failure. As I have not been following this discussion, why is the subject "Python List Is NOT Dead" a subject for discussion? Has the list been moving towards closing? No, the list's still around. But there was a significant migration to https://discuss.python.org/ which is a web forum running Discourse some time back, so python-list is a lot quieter these days. It's the somewhat parallel python-dev list that went away. This list still exists, but is now pretty low volume. -- https://mail.python.org/mailman/listinfo/python-list
Re: Tools to help with text mode (i.e. non-GUI) input
On 1/17/25 12:03, Keith Thompson via Python-list wrote: Alan Gauld writes: On 15/01/2025 00:41, Keith Thompson via Python-list wrote: Alan Gauld writes: On 11/01/2025 14:28, Chris Green via Python-list wrote: I'm looking for Python packages that can help with text mode input, I haven't followed this whole thread, but rich (low-level) and textual (higher-level) are designed for this - part of the same project family - and really worth a look. I know someone else mentioned rich earlier. There's a little video on the textual homepage that shows some of what it can do in action: https://github.com/Textualize/textual -- https://mail.python.org/mailman/listinfo/python-list
Re: Strategies for avoiding having to use --break-system-packages with pip
On 1/14/25 04:32, Chris Green via Python-list wrote: I have a (relatively) clean Debian 12 installation running on my two workhorse systems, a desktop server at home and my laptop that travels around with me. I moved from Xubuntu to Debian on both these systems a few months ago. I ran Xubuntu for many years and acquired a whole lot of python packages installed with pip, as root. For the last couple of years I had to use the --break-system-packages option to get things installed. As far as I'm aware I never hit any dependency problems doing this. It's probably because things I installed with pip were mostly quite small, specialised, packages that I used in just one or two utility programs that I had written myself. In quite a few cases these were realated to image processing and such things. So far I've managed to keep my Debian 12 installations 'pip free', I haven't even got pip installed. However I may have just come across something that would at least be very useful and it comes from PyPi. (It's tkintertable if that's of any interest or relevance) What are my options? Just install it using pip as root and --break-system-packages, what's likely to break? Use a virtual environment, what do I have to do then to make using my program (that uses tkintertable) 'transparent', i.e. I just want to be able to run the program from the command prompt like any other program. Download tkintertable from git into my development environment and use that. My PYTHONPATH will need to point to it but I can't see any further issues with doing this. Anything else? As far as I can see using pipx doesn't help me at all (see recent thread here). You might look at uv, which makes the managing of a virtualenv for your program pretty transparent. You declare your dependencies, and then just: uv run myscript.py And of course if you don't want to type three words to launch, you can put those in an executable shell script in your path, and invoke it with a single command. There was a nice article on this somewhere which I now can't find, but the project docs cover the topics pretty well: https://docs.astral.sh/uv/guides/scripts -- https://mail.python.org/mailman/listinfo/python-list
Re: Installing Python-3.10.16
On 1/13/25 22:47, roc str via Python-list wrote: having a difficult time installing Python-3.10.16.tgz using the Python-3.20.0a2.exe installer. Please Advise Mario Ramos. Your question doesn't exactly make sense, but note this: Windows installers are not built for "security bugfix" releases. The last python.org release in the 3.10 series that had installers was 3.10.11; subsequent 3.10 releases only consist of the source code (this pattern repeats for all Python release series, once they hit a certain age the move to source-only security bugfix releases, normally when there are two newer Python series available which would contain those fixes already). You have to download the source release and build it yourself if you need this. You can't install a source release using an installer for a different version. There are some instructions here: https://devguide.python.org/getting-started/setup-building/index.html but note that they're oriented to building from a revision control checkout, not from a source release bundle. There should be some instructions somewhere on the internet if buildi-for-windows-from-a-source-release really is exactly what you need. -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip installs to unexpected place
On 4/17/25 15:15, Grant Edwards via Python-list wrote: On 2025-04-17, Left Right via Python-list wrote: Also... when installing stuff with pip --user, it is always a package that is not installed for the system (usually not even available for the system). How can that "break system packages"? pip installs dependencies. Dependencies may disagree on the version with the system packages. Good point. I don't generally allow pip to install dependencies, so I forgot about that source of conflict. But as far as I can see, it still can only break stuff for the user, not for the system. The system is never going to look in my ~/.local/lib/python* directories. Sure, and it's "your fault" (sic) if you break yourself. You and I can maybe accept that. But it's usually not obvious that you're done anything to break stuff - you just asked to install something, according to the instructions you read on the project's website, which it's reasonable (?) to expect reflects best practices. Usually a simple "pip install". Say you've been using "MLwiz" installed via a system package. It has two dozen dependencies, some of which have further deps. And it works great. Then you install "Chatbridge" via pip, and it brings with it its own dependencies. It's not really useful to refuse to let it bring its own deps with it since there may be version-specific requirements on its deps, which that project has reasons for. So now you've got a few pkgs in the system with different versions in your .local, and you can't run MLwiz any longer, because a .local pkg (picked up first) conflicts with the requirements of MLwiz. There's just not a really great answer to this. "Use a virtualenv". Fine, but that's still daunting to many, and not necessarily as well described as it could be, and the choice of the word "virtual" in the name makes it sound more complex than it actually is. Projects can certainly do better at describing installation scenarios - at least if they have more than a trivial number of deps, where the conflict chances go up rapidly. -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip installs to unexpected place
On 4/15/25 10:43, Friedrich Romstedt via Python-list wrote: Many people put emphasis on that you need to *activate* a virtualenv before using it, but no-one so far stressed the fact that you got Sphinx installed to ~/jonathan/.local/lib/python3.13/site-packages *without using *--user. To be clear: you do not have to activate a virtualenv to use *Python* from it. If you just call the python by the path it's in, it figures everything out (and sets some variables you can query vi sysconfig if you have reason to actually need those details (look for installation schemes). What activating gives you is some path fiddling, and some prompt fiddling (although the prompt fiddling keeps saying it's deprecated). The latter is a visual clue; the former means you can also find *other* commands installed in the virtualenv - including pip. /path/to/virtualenv//bin/python -m pip install ... will work whether you activated or not. pip install ... finds the first command in your PATH named pip, which may or may not be the one in the virtualenv, *unless* you've activated it, because that's the only way the virtualenv bin directory ends up early in your path. Meanwhile - the install to ~/.local : some distros just default to that behavior whether you ask for it or not, because they consider it unsafe to install in the system location. Some have chosen to yell at you even if you try a "user install" with the system Python. Up to them what they do... -- https://mail.python.org/mailman/listinfo/python-list
Re: Pip installs to unexpected place
On 4/15/25 16:07, Grant Edwards via Python-list wrote: On 2025-04-15, Thomas Passin via Python-list wrote: On Linux, at least, it's standard for pip to install into the user's site-packages location if it's not invoked with admin privileges - even without --user. Pip will emit a message saying so. Well, that used to be true but nowadays Pip wants you to use the --break-system-packages flag if you want to insist on installing into the system's Python install, even if it's going to go into --user. I've always been a little baffled by that message when installing with --user. How can that possibly break system stuff? Your user install dir is in your python path, so when you go to run an installed Python program which imports other packages, it might pick up the version you have in your user space rather than the system one it was tested with. It's about a whole curated Python environment that the distro spends time validating - a different version picked up elsewhere *might* be fine. Or it might not. I think they've had enough "it's not" bug reports to have gotten quite prickly about the subject. -- https://mail.python.org/mailman/listinfo/python-list
Re: Book recommendation? For getting up to date
On 2/16/25 18:40, Salvador Mirzo via Python-list wrote: Jan Erik Moström writes: On 16 Feb 2025, at 20:47, rbowman via Python-list wrote: David Beasley's 'Python Distilled'. The author doesn't enumerate Python 3 features specifically but as the title suggests hits the important concepts. Thanks, I'll take a look I can reinforce this recommendation. I haven't read the entire book, but I'm reading it slowly. The beauty of this book is that it's very concise without being just a reference. Since you're familiar with Python already, this is likely a good match to you. It's what one might call the "spiritual successor" to Dabeaz's earlier Python Essential Reference, which for years (early 2000's) was the one book I referred to frequently. -- https://mail.python.org/mailman/listinfo/python-list
Re: "Getting 'This app can’t run on your PC' (Access Denied) error when running Python or checking version in CMD on Windows 11"
On 3/10/25 10:08, Praveen Kumar via Python-list wrote: Hi Matt, I pointed out onething that related to the errors, what I pointed out is I just gone through the system 32 path in c drive and I found the python executive and other python files indicating 0 kb, and I deleted these exe, since these are seem to be corrupted to me, then after I tried running python and python --version with admin and all those executables, anyway it works really well. (Finally The all issues stand resolved.) Thank you for support matt and team, I'm really thankful for your attention to this matter. The "empty" ones are part of the app execution alias system in Windows. If you do nothing at all, these at the things that offer to launch the Microsoft Store you can install Python from there. They're not actual files, they are NTFS reparse points, and if you need to remove them you should use the fsutil utility. Yes, this is pretty obscure. -- https://mail.python.org/mailman/listinfo/python-list
Re: Book recommendation? For getting up to date
On 2/16/25 05:50, Jan Erik Moström via Python-list wrote: I'm looking for a book that would teach me the lastest and greatest parts of Python, does anyone have any recommendations? I've looked at python.org and pythonbooks.org but I couldn't decide which one to get. I used to be fairly good at Python, but I haven't done any serious programming in the last 10 years or so. So I would like something that got me up-to-date with the latest features. I don't need anything that would teach me OOP, functional programming, etc (unless there is a new feature). In other words I'm looking for something that concentrates language specific changes that has happened the last 10 years or so. = jem Possibly scan through the "What's New in ..." pages for Python 3, to give you descriptions of new stuff that you can then use as search terms for further research. https://docs.python.org/3/whatsnew/index.html -- https://mail.python.org/mailman/listinfo/python-list
Re: WG: dont use C:\Windows as working directory when installed using microsoft store
On 5/18/25 08:39, Mike Dewhirst via Python-list wrote: Apologies for top-posting. It's my phone's fault.Since no-one appears to have responded, I'll stir up some aggro and offer my opinion based on ~45 years experience with Microsoft.Uninstall python/idle etc completely and download from python.org instead. I would advise ignoring recommendations and install to c:/python313 or whatever version suits. From then, I would establish a virtual environment for each project and ignore Windows paths. The clever things built into Windows specific kit have built-in assumptions which probably suit some people but not you. Nor me.Good luck.Mike --Unsigned mail from my phone I did respond and something went wrong with the copy that was supposed to go to the list, still need to investigate why. IDLE uses the directory it was started in. That's absolutely fine if you're in a directory you want to work in, and you type "idle" to a command-line shell. If you launch IDLE, like any command, by clicking on an icon, the start directory depends on how desktop-style launching works (it doesn't have the context of a "current working directory" that you have in a shell), and on configuration settings. Without configuration (whether by the user explicitly, or by the way the launch icon is set up during program installation), it's likely to be the location of the icon file, or some other uninteresting place. It's not just Windows where problems have happened with IDLE using current-directory that's not what folks expect - you can find grumbles for Mac as well if you look on the Internet. Configuring the launch directory for a command run via an icon is very system-specific. On Windows you can configure the properties of the icon (the real one, not the one in the launch menu, which is a shortcut)... except, as in the OP's case, if you used the Store version, which is an "app", where you apparently can't. Store apps have some special restrictions, which, in my possibly slightly less radical opinion, means the Python one is not really worth using. So: - start IDLE from a shell prompt (change directory first if you want a special dev dir) - use the python.org version and configure the launch dir via the icon - use one of the many good editors/IDEs that handle all this stuff. yes that's not a "battery includes" thing like IDLE is, but hey... there are many of these, free, proprietary, or in between. A pair of community-curated lists are at: https://wiki.python.org/moin/IntegratedDevelopmentEnvironments https://wiki.python.org/moin/PythonEditors and there are also a several-digit number of internet sites that promise "the Best Python Editors" and that kind of click-baity thing... -- https://mail.python.org/mailman/listinfo/python-list
Re: Dynamic classes
On 5/19/25 09:51, Jonathan Gossage via Python-list wrote:
I have created a dynamic class using the type() function:
x = type('MyFlags', (), {'Flag1': 1, 'Flag2': 2, 'Flag3: 4, ' '__init__' :
__init__})
The new class is there, and the class variables, Flag1, Flag2, and Flag3,
are present correctly. However, when I try to create an instance of this
class with the following code:
y = x('Flag1', 'Flag2')
it fails with a TypeError stating that 'MyFlags' does not accept arguments.
What do I have to do to make this happen?. BTW __init__(self, *args) is
defined as the instance initializer.
Might help if you show the init function. I've done something similar to
this without trouble, but not using the unpacking (i.e. *args). I used
this in an ancient blog post (thus, pre-typing, and such):
def transact(acct, amount):
acct.balance += amount
def pay_interest(acct):
acct.balance += acct.balance * acct.interest_rate
def account_init(acct, num, name, bal, rate):
acct.acct_number = num
acct.acct_holder = name
acct.balance = bal
acct.interest_rate = rate
account = {
"acct_number": "XXX",
"acct_holder": "",
"balance": 0.0,
"interest_rate": 0.0,
"transact": transact,
"pay_interest": pay_interest,
"__init__": account_init,
}
AccountType = type("AccountType", (), account)
myaccount = AccountType("1234567", "J. Q. Public", 20.0, 0.01)
print(myaccount.balance)
myaccount.transact(-10)
print(myaccount.balance)
myaccount.pay_interest()
print(myaccount.balance)
--
https://mail.python.org/mailman/listinfo/python-list
