pypa / setuptools

Official project repository for the Setuptools build system
https://pypi.org/project/setuptools/
MIT License
2.52k stars 1.19k forks source link

[BUG] pip install ./path/to/package requires the network #3734

Open dvarrazzo opened 1 year ago

dvarrazzo commented 1 year ago

setuptools version

setuptools-65.6.3

Python version

Python 3.10

OS

Ubuntu

Additional environment information

No network connectivity, e.g.

Description

Running python ./path/to/package/setup.py install raises a warning:

SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.

however, pip install ./path/to/package requires access to the network in order to work, even if all the dependencies are available locally. This means that it's impossible to hack on your favourite C extension if the network is not available.

Expected behavior

See above.

How to Reproduce

With the network available. Note that all the build dependencies are available:

$ git clone git@github.com:psycopg/psycopg.git
$ cd psycopg
$ pip install -v ./psycopg_c/
Using pip 22.3.1 from /home/piro/dev/psycopg3/.venv/lib/python3.10/site-packages/pip (python 3.10)
Processing ./psycopg_c
  Running command pip subprocess to install build dependencies
  Collecting setuptools>=49.2.0
    Using cached setuptools-65.6.3-py3-none-any.whl (1.2 MB)
  Collecting wheel>=0.37
    Using cached wheel-0.38.4-py3-none-any.whl (36 kB)
  Collecting Cython>=3.0.0a11
    Using cached Cython-3.0.0a11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl (2.6 MB)
  Installing collected packages: wheel, setuptools, Cython
  Successfully installed Cython-3.0.0a11 setuptools-65.6.3 wheel-0.38.4
  Installing build dependencies ... done
  Running command Getting requirements to build wheel
  Getting requirements to build wheel ... done
  Running command Preparing metadata (pyproject.toml)
  running dist_info
...
Successfully built psycopg-c
Installing collected packages: psycopg-c
Successfully installed psycopg-c-3.1.8.dev1

Taking down the network:

$ pip install -v ./psycopg_c/
Using pip 22.3.1 from /home/piro/dev/psycopg3/.venv/lib/python3.10/site-packages/pip (python 3.10)
Processing ./psycopg_c
  Running command pip subprocess to install build dependencies
  WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f45501461d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/setuptools/
  WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f45501464d0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/setuptools/
^C  Installing build dependencies ... canceled

setup.py install works instead:

$ python ./psycopg_c/setup.py install
/home/piro/dev/psycopg3/.venv/lib/python3.10/site-packages/setuptools/installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
  warnings.warn(
running install
/home/piro/dev/psycopg3/.venv/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/home/piro/dev/psycopg3/.venv/lib/python3.10/site-packages/setuptools/command/easy_install.py:158: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running bdist_egg
running egg_info
writing psycopg_c.egg-info/PKG-INFO
writing dependency_links to psycopg_c.egg-info/dependency_links.txt
writing top-level names to psycopg_c.egg-info/top_level.txt
reading manifest file 'psycopg_c.egg-info/SOURCES.txt'
adding license file 'LICENSE.txt'
writing manifest file 'psycopg_c.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_py
running build_ext
building 'psycopg_c._psycopg' extension
...

Installed /home/piro/dev/psycopg3/.venv/lib/python3.10/site-packages/psycopg_c-3.1.8.dev1-py3.10-linux-x86_64.egg
Processing dependencies for psycopg-c==3.1.8.dev1
Finished processing dependencies for psycopg-c==3.1.8.dev1

Output

See above.

abravalheri commented 1 year ago

Hi @dvarrazzo, thank you for opening the issue.

Since the PEP 517 implementation in pip, pip will try to create an isolated virtual environment when building the project.

This probably means that pip will reach out to PyPI to find out what the dependency graph for the build dependencies (the ones specified in pyproject.toml [build-system] requires + wheel). I don't think pip is caching this information as for the time being, so that would explain why it tries to connect via the internet.

If you want to do a completely offline build, I suppose you can try:

  1. Make sure all the build dependencies are installed in your environment (I suppose that would be setuptools and wheel)
  2. Call pip install -v --no-build-isolation .

Does that work for you?