How can I install pyenv-win Python versions outside C:\Users?

1.6k views Asked by At

My C: drive is always too full, some useful stuff but 80% execrable, unremovable Microsoft bloatware. I always install new stuff on another drive.

I've tried this installation page for installing pyenv-win.

Even if I set the pyenv installation directory itself somewhere off C: drive, I find that pyenv install [version] installs that version under C:\Users... Python version 3.10.5 (for example) takes up 200 MB.

I went pyenv install --help but could see no options for installing Python versions somewhere else. Is it possible?

2

There are 2 answers

1
Davi Gray On

OK, you don't specify what instructions, exactly, you followed on the installation page, nor how you "set the pyenv installation directory itself somewhere off C: drive," however, it is possible to fix things to do what you want.

  1. I used the PowerShell installation method, as recommended on the page you linked to, which installed pyenv-win to ~\.pyenv. I assume other installation methods will end up with everything in the same place. (Note that the PowerShell installation script is hardcoded to use ${env:USERPROFILE}\.pyenv.)
  2. Move the .pyenv folder from your user profile folder to wherever you want it to exist (Explorer seems the easiest way to do this, but whatever works for you.)
  3. Update your PYENV environment variables (PYENV, PYENV_ROOT, PYENV_HOME) to match the new location. You can use the Windows Settings dialog to do so, or you can do it from a PowerShell command prompt, like so (if, for example, you were using D:\pythons\.pyenv\):
[System.Environment]::SetEnvironmentVariable('PYENV', 'D:\pythons\.pyenv\pyenv-win\', 'User')
[System.Environment]::SetEnvironmentVariable('PYENV_ROOT', 'D:\pythons\.pyenv\pyenv-win\', 'User')
[System.Environment]::SetEnvironmentVariable('PYENV_HOME', 'D:\pythons\.pyenv\pyenv-win\', 'User')
  1. Finally, update your PATH to use the new location (the easiest way to do this is through the settings dialog); at the beginning of the path (if your username is, for example, miker):

Replace

C:\Users\miker\.pyenv\pyenv-win\bin

with

D:\pythons\.pyenv\pyenv-win\bin.

Replace

C:\Users\miker\.pyenv\pyenv-win\shims

with

D:\pythons\.pyenv\pyenv-win\shims.

Now you should be able to run pyenv to your heart's content. Enjoy!

4
ivan_pozdeev On

Frame challenge:

Since Win7, there's no real need to use drives other than C:, see my answer to "Is there a reason to keep Windows' primary partition / drive C: small?" - Super User.

This will solve your "my C: drive is always too full" problem once and for all (as well as all other current and future problems like this one that stem from that): you'll only ever have low space on it when you have low space, period.


Answering the question as asked:

With multiple drives, you can create a symbolic link from the required location to a directory on another drive (Windows supports symbolic links since Vista) -- so that directory will appear on C: while physically being elsewhere. Link Shell Extension is the best software I've seen to use links in Windows.

While it's sometimes possible to configure a program to look in another location, this is completely program-specific and the program needs to explicitly support redirecting that specific location. While links are transparent (so no support from the program's side is needed) and allow redirecting arbitrary paths thus are also more flexible. (E.g. at some machines that had multiple physical drives, I moved C:\Users to another drive which Windows never officially supported.)