Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError when installing a package with a dependency on another package even though the required package is installed #2991

Closed
AlessandroPomponio opened this issue Apr 11, 2024 · 5 comments
Labels
question Asking for clarification or support

Comments

@AlessandroPomponio
Copy link

Issue

Hello,
I'm trying out uv and I'm encountering a weird error with it.

The package pytorch-fast-transformers requires torch to be installed. Despite it being installed in the venv and appearing when doing uv pip show torch, attempting to install pytorch-fast-transformers will result in an ImportError.

Example:

uv venv
source .venv/bin/activate
uv pip install torch
uv pip install pytorch-fast-transformers

Will output the following:

error: Failed to download and build: pytorch-fast-transformers==0.4.0
  Caused by: Failed to build: pytorch-fast-transformers==0.4.0
  Caused by: Build backend failed to determine extra requires with `build_wheel()` with exit status: 1
--- stdout:

--- stderr:
Traceback (most recent call last):
  File "<string>", line 19, in <module>
ModuleNotFoundError: No module named 'torch'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 14, in <module>
  File "/Users/alessandropomponio/Library/Caches/uv/.tmp2WMNKV/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=['wheel'])
  File "/Users/alessandropomponio/Library/Caches/uv/.tmp2WMNKV/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
    self.run_setup()
  File "/Users/alessandropomponio/Library/Caches/uv/.tmp2WMNKV/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 487, in run_setup
    super().run_setup(setup_script=setup_script)
  File "/Users/alessandropomponio/Library/Caches/uv/.tmp2WMNKV/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 311, in run_setup
    exec(code, locals())
  File "<string>", line 22, in <module>
ImportError: PyTorch is required to install pytorch-fast-transformers. Please install your favorite version of PyTorch, we support 1.3.1, 1.5.0 and >=1.6
---

Note

Output with -v flag below

Disclose here
INFO Found a virtualenv through VIRTUAL_ENV at: /Users/alessandropomponio/uv-test/.venv
DEBUG Cached interpreter info for Python 3.10.12, skipping probing: .venv/bin/python
DEBUG Using Python 3.10.12 environment at .venv/bin/python
DEBUG Trying to lock if free: .venv/.lock
DEBUG Using registry request timeout of 300s
DEBUG Solving with target Python version 3.10.12
DEBUG Adding direct dependency: pytorch-fast-transformers*
TRACE Fetching metadata for pytorch-fast-transformers from https://pypi.org/simple/pytorch-fast-transformers/
TRACE cached request https://pypi.org/simple/pytorch-fast-transformers/ is storable because its response has a 'public' cache-control directive
DEBUG Found fresh response for: https://pypi.org/simple/pytorch-fast-transformers/
TRACE Received package metadata for: pytorch-fast-transformers
TRACE selecting candidate for package pytorch-fast-transformers with range Range { segments: [(Unbounded, Unbounded)] } with 8 remote versions
TRACE found candidate for package PackageName("pytorch-fast-transformers") with range Range { segments: [(Unbounded, Unbounded)] } after 0 steps: "0.4.0" version
DEBUG Searching for a compatible version of pytorch-fast-transformers (*)
TRACE selecting candidate for package pytorch-fast-transformers with range Range { segments: [(Unbounded, Unbounded)] } with 8 remote versions
TRACE found candidate for package PackageName("pytorch-fast-transformers") with range Range { segments: [(Unbounded, Unbounded)] } after 0 steps: "0.4.0" version
DEBUG Selecting: pytorch-fast-transformers==0.4.0 (pytorch-fast-transformers-0.4.0.tar.gz)
TRACE cached request https://files.pythonhosted.org/packages/ea/bc/00f597fefeab6341114c41045c1b232c38436738e0e8eac1bc9d5e9d5962/pytorch-fast-transformers-0.4.0.tar.gz is storable because its response has a 'public' cache-control directive
DEBUG Found fresh response for: https://files.pythonhosted.org/packages/ea/bc/00f597fefeab6341114c41045c1b232c38436738e0e8eac1bc9d5e9d5962/pytorch-fast-transformers-0.4.0.tar.gz
DEBUG Preparing metadata for: pytorch-fast-transformers==0.4.0
DEBUG No static `PKG-INFO` available for: pytorch-fast-transformers==0.4.0 (DynamicPkgInfo(UnsupportedMetadataVersion("2.1")))
DEBUG No static `pyproject.toml` available for: pytorch-fast-transformers==0.4.0 (MissingPyprojectToml)
DEBUG Solving with target Python version 3.10.12
DEBUG Adding direct dependency: setuptools>=40.8.0
TRACE Fetching metadata for setuptools from https://pypi.org/simple/setuptools/
TRACE cached request https://pypi.org/simple/setuptools/ is storable because its response has a 'public' cache-control directive
DEBUG Found fresh response for: https://pypi.org/simple/setuptools/
TRACE Received package metadata for: setuptools
TRACE selecting candidate for package setuptools with range Range { segments: [(Included("40.8.0"), Unbounded)] } with 550 remote versions
TRACE found candidate for package PackageName("setuptools") with range Range { segments: [(Included("40.8.0"), Unbounded)] } after 0 steps: "69.2.0" version
DEBUG Searching for a compatible version of setuptools (>=40.8.0)
TRACE selecting candidate for package setuptools with range Range { segments: [(Included("40.8.0"), Unbounded)] } with 550 remote versions
TRACE found candidate for package PackageName("setuptools") with range Range { segments: [(Included("40.8.0"), Unbounded)] } after 0 steps: "69.2.0" version
DEBUG Selecting: setuptools==69.2.0 (setuptools-69.2.0-py3-none-any.whl)
TRACE cached request https://files.pythonhosted.org/packages/92/e1/1c8bb3420105e70bdf357d57dd5567202b4ef8d27f810e98bb962d950834/setuptools-69.2.0-py3-none-any.whl.metadata is storable because its response has a 'public' cache-control directive
DEBUG Found fresh response for: https://files.pythonhosted.org/packages/92/e1/1c8bb3420105e70bdf357d57dd5567202b4ef8d27f810e98bb962d950834/setuptools-69.2.0-py3-none-any.whl.metadata
TRACE Received built distribution metadata for: setuptools==69.2.0
DEBUG Installing in setuptools==69.2.0 in /Users/alessandropomponio/Library/Caches/uv/.tmpbwwP79/.venv
DEBUG Requirement already cached: setuptools==69.2.0
DEBUG Installing build requirement: setuptools==69.2.0
DEBUG Calling `setuptools.build_meta:__legacy__.get_requires_for_build_wheel()`
error: Failed to download and build: pytorch-fast-transformers==0.4.0
  Caused by: Failed to build: pytorch-fast-transformers==0.4.0
  Caused by: Build backend failed to determine extra requires with `build_wheel()` with exit status: 1
--- stdout:

--- stderr:
Traceback (most recent call last):
  File "<string>", line 19, in <module>
ModuleNotFoundError: No module named 'torch'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<string>", line 14, in <module>
  File "/Users/alessandropomponio/Library/Caches/uv/.tmpbwwP79/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
    return self._get_build_requires(config_settings, requirements=['wheel'])
  File "/Users/alessandropomponio/Library/Caches/uv/.tmpbwwP79/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
    self.run_setup()
  File "/Users/alessandropomponio/Library/Caches/uv/.tmpbwwP79/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 487, in run_setup
    super().run_setup(setup_script=setup_script)
  File "/Users/alessandropomponio/Library/Caches/uv/.tmpbwwP79/.venv/lib/python3.10/site-packages/setuptools/build_meta.py", line 311, in run_setup
    exec(code, locals())
  File "<string>", line 22, in <module>
ImportError: PyTorch is required to install pytorch-fast-transformers. Please install your favorite version of PyTorch, we support 1.3.1, 1.5.0 and >=1.6
---

With the following, however, we can see that torch is correctly installed and available:

uv pip show torch
Name: torch
Version: 2.2.2
Location: /Users/alessandropomponio/uv-test/.venv/lib/python3.10/site-packages
Requires: filelock, fsspec, jinja2, networkx, sympy, typing-extensions
Required-by:

Running import torch from an interactive python session also works.

Details

System: MacOS
Python Version: Python 3.10.12
UV Version: uv 0.1.31

@AlessandroPomponio
Copy link
Author

The fact that setuptools gets installed in a temporary venv despite being available in the currently active venv makes me think the installation process is working in isolation and ends up causing the error I encountered

@charliermarsh
Copy link
Member

I believe you need to run with --no-build-isolation since pytorch-fast-transformers depends on Torch, but doesn't include it in its build dependencies.

pip also fails to install this package with --use-pep517, which will eventually be the default in pip (and is the default in uv today):

❯ pip install pytorch-fast-transformers --use-pep517
Collecting pytorch-fast-transformers
  Downloading pytorch-fast-transformers-0.4.0.tar.gz (93 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 93.6/93.6 kB 4.2 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error

  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [26 lines of output]
      Traceback (most recent call last):
        File "<string>", line 19, in <module>
      ModuleNotFoundError: No module named 'torch'

      The above exception was the direct cause of the following exception:

      Traceback (most recent call last):
        File "/Users/crmarsh/.local/share/rtx/installs/python/3.12.1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/Users/crmarsh/.local/share/rtx/installs/python/3.12.1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/Users/crmarsh/.local/share/rtx/installs/python/3.12.1/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/pip-build-env-wn0uzfrt/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 325, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/pip-build-env-wn0uzfrt/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 295, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/pip-build-env-wn0uzfrt/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 487, in run_setup
          super().run_setup(setup_script=setup_script)
        File "/private/var/folders/nt/6gf2v7_s3k13zq_t3944rwz40000gn/T/pip-build-env-wn0uzfrt/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 311, in run_setup
          exec(code, locals())
        File "<string>", line 22, in <module>
      ImportError: PyTorch is required to install pytorch-fast-transformers. Please install your favorite version of PyTorch, we support 1.3.1, 1.5.0 and >=1.6
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Try uv pip install pytorch-fast-transformers --no-build-isolation.

@charliermarsh charliermarsh added the question Asking for clarification or support label Apr 11, 2024
@charliermarsh
Copy link
Member

(Added a note here: #2252)

@AlessandroPomponio
Copy link
Author

Thank you very much Charlie! That was it!
Have a great day!

@charliermarsh
Copy link
Member

No prob :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for clarification or support
Projects
None yet
Development

No branches or pull requests

2 participants