0

I use the Python 3.10.10 in MINGW64, and I want to use a Python3 package that has not been updated in years, which I've installed successfully back in Python 3.7 on this platform - but of course, that is useless on Python 3.10.

Now I have to build this package again. It being old, it uses deprecated features for setuptools, so now I have to install old setuptools. Since that is likely to mess up the rest of my system, I'm thinking I should try this in python3 -m venv mingw64_py3.10_venv. This works, I can install old setuptools:

$ pip3 install setuptools==45
Collecting setuptools==45
  Downloading setuptools-45.0.0-py2.py3-none-any.whl (583 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 583.8/583.8 kB 4.6 MB/s eta 0:00:00
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 65.5.0
    Uninstalling setuptools-65.5.0:
      Successfully uninstalled setuptools-65.5.0
Successfully installed setuptools-45.0.0

... but upon building the package with python3 setup.py install, I get ModuleNotFoundError: No module named 'numpy'. Ok, so I do pip3 install numpy and it takes an hour to build from source, and then install process fails again for scipy - I can tell already this is going to be another hour.

So, I'm thinking - I already have numpy and scipy, why can't I reuse those? So I found:

Make virtualenv inherit specific packages from your global site-packages

Create the environment with virtualenv --system-site-packages . Then, activate the virtualenv and when you want things installed in the virtualenv rather than the system python, use pip install --ignore-installed or pip install -I . That way pip will install what you've requested locally even though a system-wide version exists. Your python interpreter will look first in the virtualenv's package directory, so those packages should shadow the global ones.

Ok, so I try:

$ python3 -m venv mingw64_py3.10_venv --system-site-packages
$ source mingw64_py3.10_venv/bin/activate
$ mingw64_py3.10_venv/bin/python3.exe -m pip install --ignore-installed --upgrade pip
...
Successfully installed pip-23.0.1
$ pip3 --version
pip 23.0.1 from C:/path/to/mingw64_py3.10_venv/lib/python3.10/site-packages/pip (python 3.10)

Ok, looks good so far; now old setuptools?

$ pip3 install --ignore-installed setuptools==45
Collecting setuptools==45
  Using cached setuptools-45.0.0-py2.py3-none-any.whl (583 kB)
Installing collected packages: setuptools
Successfully installed setuptools-65.5.0

Why does it say Collecting setuptools==45 - and then Successfully installed setuptools-65.5.0? How is that "successful"?

I asked for version 45.0.0 not 65.5.0??

$ pip3 show setuptools
Name: setuptools
Version: 65.5.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
Author-email: distutils-sig@python.org
License:
Location: c:/path/to/mingw64_py3.10_venv/lib/python3.10/site-packages
Requires:
Required-by: sip

Can I make a venv in Python 3.10, that inherits most of my system modules, and yet allows me to downgrade setuptools - and if so, how?

sinoroc
  • 18,409
  • 2
  • 39
  • 70
sdbbs
  • 4,270
  • 5
  • 32
  • 87
  • [From the documentation](https://pip.pypa.io/en/stable/cli/pip_install/#cmdoption-I): Ignore the installed packages, overwriting them. This can break your system if the existing package is of a different version or was installed with a different package manager! – Bibhav Mar 31 '23 at 03:41

1 Answers1

0

Well, apparently just for setuptools, I should not use --ignore-installed - then it installs:

$ pip3 install setuptools==45
Collecting setuptools==45
  Using cached setuptools-45.0.0-py2.py3-none-any.whl (583 kB)
Installing collected packages: setuptools
  Attempting uninstall: setuptools
    Found existing installation: setuptools 65.5.0
    Uninstalling setuptools-65.5.0:
      Successfully uninstalled setuptools-65.5.0
Successfully installed setuptools-45.0.0

$ pip3 show setuptools
Name: setuptools
Version: 45.0.0
Summary: Easily download, build, install, upgrade, and uninstall Python packages
Home-page: https://github.com/pypa/setuptools
Author: Python Packaging Authority
Author-email: distutils-sig@python.org
License: UNKNOWN
Location: c:/path/to/mingw64_py3.10_venv/lib/python3.10/site-packages
Requires:

... and my old package starts building too, so that is good ...

sdbbs
  • 4,270
  • 5
  • 32
  • 87