Python Module madness

Concerning pip and venv, I found this a bit clearer than the article Karl linked, simply because it tells you one good way to do it at each step, rather than offering alternatives.
https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments

This bothers me a bit. If one uses pip install numpy, it should get everything numpy depends on. The closest experience I’ve had to this was the need to install other tools or loadable libraries (not Python modules, and not for Numpy) that were technically optional – that is, only some of the functionality depended on them. pip, backed by repositories at PyPI, does the dependency management.

This is from a standing start (Windows, PowerShell):

PS import> py -V
Python 3.12.1
PS import> py -m venv mathvenv
PS import> .\mathvenv\Scripts\activate
(mathvenv) PS import>
(mathvenv) PS import> py -m pip install numpy
Collecting numpy
  Obtaining dependency information for numpy from https://files.pythonhosted.org/packages/16/2e/86f24451c2d530c88daf997cb8d6ac622c1d40d19f5a031ed68a4b73
a374/numpy-1.26.4-cp312-cp312-win_amd64.whl.metadata
  Using cached numpy-1.26.4-cp312-cp312-win_amd64.whl.metadata (61 kB)
Using cached numpy-1.26.4-cp312-cp312-win_amd64.whl (15.5 MB)
Installing collected packages: numpy
Successfully installed numpy-1.26.4

[notice] A new release of pip is available: 23.2.1 -> 24.0
[notice] To update, run: python.exe -m pip install --upgrade pip
(mathvenv) PS import> 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.
>>> import numpy as np
>>> a = np.arange(15).reshape(3, 5)
>>> a @ a.transpose()
array([[ 30,  80, 130],
       [ 80, 255, 430],
       [130, 430, 730]])
>>>

Ok. Not quite a standing start, because I already have the NumPy distribution in pip’s cache. But a clean installation as far as the local environment goes, and the point is, once you find the right way, it just works.

Just some general comments I have, as I’m also new to Python as well.

  1. Don’t use Python 3.12, some third-party modules don’t work with it. Use Python 3.11.
  2. You can search for module names on pypi.org but if you don’t know the module name for a task you want to do, that’s where searching for tutorials can help more. They will tell you the module they import.
  3. When I want to learn how to do something I search Youtube or the web but I only ask for results from the past year. Many tutorials are out of date or require a Python older than 3.11.
  4. Not all tutorials will tell you the install name for a module.
  5. I’m finding some AI Chatbot tutorials need Python 3.8 or before.
  6. With Python the module name you install is sometimes different from the module name you import. Someone on here told me a method to list the module install name if you have the import name.

If it’s what I’m recalling, that will only work if you already have it installed.

You have said this in several threads now, but instead, file bug reports with modules that don’t work. Python 3.12 is current and stable, so people should normally be fine using it.

Please don’t spread FUD.

2 Likes

Usually what holds me back is numba. The lag is about 6 months. Another case is tensorflow (I don’t use it): the latest version on conda-forge (2.15) does not support Python 3.12. I would consider filing a bug report a bit rude.

Then it’s not really fair to tell people not to use 3.12, is it? PyPI shows that numba does work on3.12, and when I tried installing it, it downloaded a wheel.

The latest version on PyPI does support 3.12, and is available as a wheel.

Not HALF as rude as telling people to avoid an entire Python version just because of this. You are blaming Python for a problem that is solvable by the package maintainers. And one that, as of today, has in fact been solved. So I will say again: Please stop spreading FUD. You are being completely unfair to Python and its maintainers by telling people to avoid Python 3.12.

Different person

Ahh, whoops. That’s what I get for coming back to a thread after a few hours and failing to read in sufficient detail.

I’m sorry @yt87 - those comments were unfair when directed at you. Although I will still say that filing a bug report isn’t rude; if a package is lagging six months behind the corresponding Python version (at least on PyPI; I’m not sure what’s a reasonable time frame on conda, they may move slower there), it’s entirely reasonable to file a tracker issue - or, more likely, to locate an existing one, since the chances are high that someone opened the issue during alpha or beta of that Python version, and there’s some sort of blocker that is known about.

1 Like

I vaguely remember having to load more modules associated with Numpy.

There are other modules which make use of numpy. Depends on what you’re
doing - numpy does a lot of stuff right out of the box.

I also had problems with finding syntax.

If you know the statement (if, for etc) you can usually go to the
index (Index — Python 3.12.3 documentation) and look if, for
exapple, “for statement”.

I can’t get too specific about the graphics and maths because of confidentiality requirements.

Surely you can say things like “I want to drop a graph”, “I need to find
the ode of part of this dataset” etc?

My understanding is that cona (mostly?) builds packages from pypi, so there is an additional delay. For tensorflow, I did run

mamba search 'tensorflow>=2.15'
Loading channels: done
# Name                       Version           Build  Channel             
tensorflow                    2.15.0 cpu_py310h7825f03_0  conda-forge         
tensorflow                    2.15.0 cpu_py310h7825f03_1  conda-forge         
tensorflow                    2.15.0 cpu_py310h7825f03_2  conda-forge         
tensorflow                    2.15.0 cpu_py311hd3d7757_0  conda-forge         
tensorflow                    2.15.0 cpu_py311hd3d7757_1  conda-forge         
tensorflow                    2.15.0 cpu_py311hd3d7757_2  conda-forge         
tensorflow                    2.15.0 cpu_py39h433cda9_0  conda-forge         
tensorflow                    2.15.0 cpu_py39h433cda9_1  conda-forge         
tensorflow                    2.15.0 cpu_py39h433cda9_2  conda-forge         
tensorflow                    2.15.0 cuda120py310h9360858_2  conda-forge         
tensorflow                    2.15.0 cuda120py310h9360858_3  conda-forge         
tensorflow                    2.15.0 cuda120py311h5cbd639_2  conda-forge         
tensorflow                    2.15.0 cuda120py311h5cbd639_3  conda-forge         
tensorflow                    2.15.0 cuda120py39hb94c71b_2  conda-forge         
tensorflow                    2.15.0 cuda120py39hb94c71b_3  conda-forge         

Numba supporting Python 3.12 was released in February, the one for Python 3.11 dates May last year. For the project I am currently working on, I switched to Python 3.12 as soon as numba support was available.
Binary logic is what computers use (although that may change with the advent of quantum computing). The reality is more subtle, the answer usually is “it depends”. Neither “use Python 3.11” or “you should use Python 3.12 as soon as it is released” are correct, IMO.
I used the word “rude”, because most projects are developed by volunteers, who, may have to attend to tasks.

To get back on topic: I use conda/mamba almost exclusively. I found conda environments much easier to manage than pip/venv. Maybe because I do mostly scientific computing, Conda is rarely mentioned on this forum.