rye icon indicating copy to clipboard operation
rye copied to clipboard

Venv activate doesn't work / PATH not correctly set in venv

Open Uninen opened this issue 1 year ago • 1 comments

Steps to Reproduce

  1. rye init rye-test
  2. cd rye-test
  3. rye add uvicorn
  4. rye sync
  5. source .venv/bin/activate
  6. uvicorn

Expected Result

Running uvicorn after manually activating venv should work.

Actual Result

Rye venv path nor uvicorn is not in the PATH (zsh: command not found: uvicorn)

My PATH starts with /Users/uninen/.rye/shims before and after activating venv manually running source .venv/bin/activate, nothing else rye-related in it before or after.

Otherwise Rye works; rye run uvicorn and rye shell both work.

Also noticed that source deactivate fails with pyenv-virtualenv: no virtualenv has been activated. after running source .venv/bin/activate. (Plain deactivate results in pyenv-virtualenv: deactivate must be sourced. Run 'source deactivate' instead of 'deactivate')

Not sure if I'm doing something wrong or is it my setup. Petty familiar with venvs and pip-tools but couldn't figure this one out.

Version Info

rye 0.21.0
commit: 0.21.0 (2e0e02459 2024-02-03)
platform: macos (aarch64)
self-python: [email protected]
symlink support: true

Stacktrace

No response

Uninen avatar Feb 09 '24 00:02 Uninen

Just figured out that this is due to a clash with pyenv; if I rename or remove .python-version everything Just Works.

uninen@nataly  ~/Code/Misc/rye-test   main  source .venv/bin/activate uninen@nataly  ~/Code/Misc/rye-test   main  rm .python-version uninen@nataly  ~/Code/Misc/rye-test   main  source .venv/bin/activate (rye-test) uninen@nataly  ~/Code/Misc/rye-test   main 

Uninen avatar Feb 09 '24 00:02 Uninen

FWIW I wasn't able to repro this in a fresh environment

@cnpryer ➜ /workspaces $ rye init rye-test
success: Initialized project in /workspaces/rye-test
  Run `rye sync` to get started
@cnpryer ➜ /workspaces $ cd rye-test/
@cnpryer ➜ /workspaces/rye-test (main) $ rye add uvicorn
Added uvicorn>=0.27.0.post1 as regular dependency
@cnpryer ➜ /workspaces/rye-test (main) $ rye sync
Initializing new virtualenv in /workspaces/rye-test/.venv
Python version: [email protected]
Generating production lockfile: /workspaces/rye-test/requirements.lock
Creating virtualenv for pip-tools
Generating dev lockfile: /workspaces/rye-test/requirements-dev.lock
Installing dependencies
Looking in indexes: https://pypi.org/simple/
Obtaining file:///. (from -r /tmp/tmppr6fu8mw (line 2))
  Installing build dependencies ... done
  Checking if build backend supports build_editable ... done
  Getting requirements to build editable ... done
  Preparing editable metadata (pyproject.toml) ... done
Collecting click==8.1.7 (from -r /tmp/tmppr6fu8mw (line 1))
  Using cached click-8.1.7-py3-none-any.whl.metadata (3.0 kB)
Collecting h11==0.14.0 (from -r /tmp/tmppr6fu8mw (line 3))
  Downloading h11-0.14.0-py3-none-any.whl (58 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 58.3/58.3 kB 1.2 MB/s eta 0:00:00
Collecting uvicorn==0.27.0.post1 (from -r /tmp/tmppr6fu8mw (line 4))
  Downloading uvicorn-0.27.0.post1-py3-none-any.whl.metadata (6.4 kB)
Using cached click-8.1.7-py3-none-any.whl (97 kB)
Downloading uvicorn-0.27.0.post1-py3-none-any.whl (60 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 60.7/60.7 kB 1.4 MB/s eta 0:00:00
Building wheels for collected packages: rye-test
  Building editable for rye-test (pyproject.toml) ... done
  Created wheel for rye-test: filename=rye_test-0.1.0-py3-none-any.whl size=1315 sha256=def78796a1bafc03e0ff17289bcd4c4b821b06e345c6e893375e0a152989044c
  Stored in directory: /tmp/pip-ephem-wheel-cache-1gnotgbj/wheels/8b/19/c8/73a63a20645e0f1ed9aae9dd5d459f0f7ad2332bb27cba6c0f
Successfully built rye-test
Installing collected packages: uvicorn, rye-test, h11, click
Successfully installed click-8.1.7 h11-0.14.0 rye-test-0.1.0 uvicorn-0.27.0.post1
Done!
@cnpryer ➜ /workspaces/rye-test (main) $ . ./.venv/bin/activate
(rye-test) @cnpryer ➜ /workspaces/rye-test (main) $ uvicorn
Usage: uvicorn [OPTIONS] APP
Try 'uvicorn --help' for help.

Error: Missing argument 'APP'.
@cnpryer ➜ /workspaces/rye (main) $ rye --version
rye 0.21.0
commit: 0.21.0 (2e0e02459 2024-02-03)
platform: linux (x86_64)
self-python: [email protected]
symlink support: true

With some effort I can try and repro on my Mac, but could you share how you installed Rye?

cnpryer avatar Feb 09 '24 01:02 cnpryer

I should have mentioned that I also set up pyenv and installed a Python distribution to use.

@cnpryer ➜ /workspaces/rye (main) $ which pyenv
/home/codespace/.pyenv/bin/pyenv

cnpryer avatar Feb 09 '24 01:02 cnpryer

My hunch is that this might have to do with pyenv's shims that it puts into ~/.pyenv somewhere. They are not virtualenv aware and wrack havoc if used with higher priority. I have seen problems before where you you need to run rehash on such a file. I'm not sure what can be done here.

mitsuhiko avatar Feb 09 '24 11:02 mitsuhiko

With some effort I can try and repro on my Mac, but could you share how you installed Rye?

Not sure how to get all of the info but I selected the "Transparently pass through to non Rye (system, pyenv, etc.) Python" option and moved the source "$HOME/.rye/env" from ~/.profile to ~/.zshrc as it didn't work from the former.

I just tested the install on another Mac where I thought I had identical setup, there I couldn't repro this either, Rye works fine.

Maybe I should just close this issue as it's clearly just my setup?

Uninen avatar Feb 09 '24 21:02 Uninen

I will close it for now as it does not seem actionable. I will keep it in mind though if it comes up again.

mitsuhiko avatar Feb 09 '24 21:02 mitsuhiko

I had the same problem. I have disabled the pyenv plugin in .zshrc. And removed the eval "$(pyenv virtualenv-init -)" in .zprofile. Then it works.

yuanhao-li avatar Feb 29 '24 15:02 yuanhao-li