mise icon indicating copy to clipboard operation
mise copied to clipboard

Can't use virtualenv with system python

Open its-red-beard opened this issue 2 years ago • 5 comments

Describe the bug

It fails with this output:

rtx setting up virtualenv at: /home/redbeard/research/.venv
rtx failed to get virtualenv: failed to execute command: ~/.local/share/rtx/installs/python/system/bin/python -m venv /home/redbeard/research/.venv

To Reproduce

Create local configuration somewhere:

[tools]
python = { version='system', virtualenv='.venv' }

and change current directory to that directory.

Expected behavior

It should create virtual environment with system python.

rtx doctor output

rtx version:
  2023.12.34 linux-x64 (7abe91a 2023-12-21)

build:
  Target: x86_64-unknown-linux-gnu
  Features: DEFAULT, NATIVE_TLS, OPENSSL
  Built: Thu, 21 Dec 2023 18:44:22 +0000
  Rust Version: rustc 1.74.1 (a28077b28 2023-12-04)
  Profile: release

shell:
  /usr/bin/zsh
  zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

rtx data directory:
  /home/redbeard/.local/share/rtx

rtx environment variables:
  RTX_SHELL=zsh

settings:
  {
    "experimental": true,
    "color": true,
    "always_keep_download": false,
    "always_keep_install": false,
    "legacy_version_file": true,
    "legacy_version_file_disable_tools": [],
    "plugin_autoupdate_last_check_duration": "7d",
    "trusted_config_paths": [],
    "log_level": "info",
    "trace": false,
    "debug": false,
    "verbose": false,
    "quiet": false,
    "asdf_compat": false,
    "jobs": 4,
    "shorthands_file": null,
    "disable_default_shorthands": false,
    "disable_tools": [],
    "raw": false,
    "yes": false,
    "ci": false
  }

config files:
  /home/redbeard/.config/rtx/config.toml
  /home/redbeard/research/.rtx.toml

plugins:
  bun      (core)
  deno     (core)
  erlang   (core)
  go       (core)
  java     (core)
  node     (core)
  python   (core)
  ruby     (core)

toolset:
  python@system, node@20, go@1

No problems found

its-red-beard avatar Dec 22 '23 09:12 its-red-beard

it doesn't really make sense to use system this way. "system" in rtx really just means lack of using rtx at all.

Perhaps I should rename it to "omit" or "null" or something to make the behavior clearer.

jdx avatar Dec 22 '23 15:12 jdx

My use case is to activate (create one if not exists) virtual env in the folder using the system python. This can be done with direnv using layout python which will use the system python, here.

The layout python directive will look for a python executable on the path.

Is this possible in rtx?

its-red-beard avatar Dec 23 '23 07:12 its-red-beard

this would require a fair amount of work since currently rtx goes out of its way to ignore the system versions. It is possible to fix though

jdx avatar Dec 24 '23 17:12 jdx

Maybe the real issue here is that virtualenv management should be separated from the Python tool and a different plugin/tool dedicated to virtualenv management could be created? There could then even be competing ones based on the way different folks think virtualenvs should be managed (#1438)?

The virtualenv management tool/plugin would just use the python on the current PATH and not care whether it was mise managed or not.

rsyring avatar Jan 11 '24 21:01 rsyring

you can do that today, just write a plugin that has a bin/exec-env like the poetry plugin: https://github.com/mise-plugins/mise-poetry/blob/main/bin/exec-env

I would like to make this possible though so it wouldn't require so much boilerplate:

[env]
_.script = '~/scripts/setup_my_venv.sh'

jdx avatar Jan 11 '24 21:01 jdx