astral-sh / rye

a Hassle-Free Python Experience
https://rye.astral.sh
MIT License
13.64k stars 466 forks source link

ModuleNotFoundError: No module named 'setuptools' #655

Open anna-hope opened 7 months ago

anna-hope commented 7 months ago

Steps to Reproduce

  1. Have an existing project with a setup.py file
  2. Run rye init

The setup.py is extremely simple:

from setuptools import setup

# See setup.cfg file

if __name__ == "__main__":
    setup()

I know the docs say "Note that Rye today does not support setup.py based projects," but also I found this issue, which suggests rye init should work in some capacity.

I guess rye init --no-import could be a workaround, but that would complicate the project setup.

I also uninstalled and re-installed Rye to make sure it wasn't some issue with my installation.

Expected Result

The project can be initialized successfully.

Actual Result

error: failed to proxy setup.py
Traceback (most recent call last):
  File "/Users/annahope/<project>/./setup.py", line 2, in <module>
    from setuptools import setup
  File "/var/folders/b6/nm_w0grs5vx0_xq0tpsvft6h0000gn/T/.tmpmXonDM/setuptools.py", line 12, in <module>
    import setuptools as __setuptools
  File "/var/folders/b6/nm_w0grs5vx0_xq0tpsvft6h0000gn/T/.tmpmXonDM/setuptools.py", line 12, in <module>
    import setuptools as __setuptools
ModuleNotFoundError: No module named 'setuptools'

Version Info

rye 0.23.0 commit: 0.23.0 (0fdcdda6c 2024-02-13) platform: macos (aarch64) self-python: cpython@3.12 symlink support: true

Stacktrace

No response

mitsuhiko commented 7 months ago

The import doesn't really work today for setupl.py based projects, at least not well enough. You probably can make some progress by running rye init --build-system=setuptools.

anna-hope commented 7 months ago

@mitsuhiko rye init --build-system=setuptools has the same issue. But, thank you for clarifying that the import doesn't work at the moment. I'll try to proceed with rye init --no-import.

willfrey commented 7 months ago

I ran into this same issue and was able to use pip to install setuptools into the rye virtual environment located at ~/.rye/self (at least for me with a default installation).

cd ~/.rye/self
./bin/pip install setuptools

Not ideal to be manually installing packages into the rye-managed virtual environment, but it did work.

WinChua commented 6 months ago

The same as me. And with some research, it seems that it's because setuptools is not been installed when create a venv by default since python 3.12. So is that worth to execute pip install setuptools automaticlly when we use python3.12

what's new in python 3.12 Remove bundled setuptools

sbor23 commented 6 months ago

This also happens with python 3.10.

Edit: It seems rye uses 3.12 internally to run rye init, even if the config.toml contains

[default]
toolchain = "3.10"
God-damnit-all commented 21 hours ago

What I did was I activated the virtual environment in ~/.rye/self/Scripts and then I ran curl -sSL https://bootstrap.pypa.io/get-pip.py | python and that installed pip, wheel, and setuptools

You can have it skip wheel by setting the env variable PIP_NO_WHEEL to 1, though. Or you can do curl -sSL https://bootstrap.pypa.io/get-pip.py | python - --no-wheel