Skip to content

Add option to specify python version for virtualenv#2083

Open
GibbonJojo wants to merge 2 commits intojordansissel:mainfrom
GibbonJojo:main
Open

Add option to specify python version for virtualenv#2083
GibbonJojo wants to merge 2 commits intojordansissel:mainfrom
GibbonJojo:main

Conversation

@GibbonJojo
Copy link

I sometimes want to package virtualenvs with other python version than my system default. This adds another cli option to specify an alternative python executable. Naming is the same as for virtualenv
https://virtualenv.pypa.io/en/latest/cli_interface.html

I decided not to check for a valid executable in this code as virtualenv will forward the error anyways

I hope the code is fine as is, I'm not really versed in Ruby, but this might serve as a proposal for the requested change.

Tested it locally and works on my linux machine with a caveat though:

  1. virtualenv should not be installed in environments, instead it should be installed in the global interpreter or (preferred) via pipx
  2. virtualenv-tools can misfunction if you're trying to run it on a virtualenv, that has a different version than the one it's running on
    E.g. having Python3.10 as base, running
    virtualenv --python python3.12 environment_name
    cd environment_name
    virtualenv-tools --update-path /some/path

will throw an error while updating the .pycs

So given the example of having Python3.10 as your base python, but you want to build your virtualenv for Py3.12, you need to install virtualenv with pipx, then create a Py3.12 environment, install virtualenv-tools3 in there and run fpm in this environment.
It is a bit finicky, but that would need solving in virtualenv-tools, I guess. Atleast that enables fpm to build virtualenvs for different Python versions

@mummynobbit
Copy link

Is it a duplicate of #1476?

@jordansissel
Copy link
Owner

jordansissel commented Oct 2, 2025

Is it a duplicate of #1476?

@mummynobbit agreed.

virtualenv-tools can misfunction if you're trying to run it on a virtualenv, that has a different version than the one it's running on

@GibbonJojo - I also noticed this. I wonder if it would help to install virtualenv-tools3 inside the virtualenv and then that setup it to perform the virtualenv-tools --update-path ... step using the same version of python?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants