22

I have a problem on Windows 10 where both Python 2.6 and 2.7 are installed.

python -m pip install myPack --no-index --find-links=. --user

When running this command with user AutoUser it installs myPack to Default user directory C:\Users\Default\Python\Python27\site-packages or C:\Users\Default\Appdata\Roaming\Python\site-packages instead C:\Users\Autouser\Appdata\Roaming\Python\site-packages

  • Installation is automatic soon after windows logon, but I can see in logs that "query user" returns a row with AutoUser (before calling pip).
  • Other OS don't have this problem.
  • Reproduction is unstable on Windows 10: maybe 1 time of 100.
  • Truth that python 2.6 is also installed on these machines, but I'm not sure it is meaningful: 2.6 goes later than 2.7 in Path system variable. Here they write it could be a problem, but pip doesn't confuse python versions, it confuses users' directories.

Path:

C:\ProgramData\Oracle\Java\javapath;C:\Python27\;C:\Python27\Scripts\;C:\Python26\;C:\Python26\Scripts;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\ProgramData\chocolatey\bin;

Python version:

python --version
Python 2.7.13

Pip version:

python -m pip --version
Pip version: pip 9.0.1 from C:\Python27\lib\site-packages (python 2.7) 
flam3
  • 1,897
  • 2
  • 19
  • 26
  • I think this answer will be useful. https://stackoverflow.com/a/34803087/5774004 – Sreeragh A R Sep 16 '18 at 11:52
  • What is the value of %APPDATA%? – OrdoFlammae Sep 17 '18 at 02:25
  • From the commands you ran, it's clear that *Python 2.6* doesn't have anything to do here. But what about the real scenario? How is the install triggered? Is is from a service? What is the user that launches the command? You should print its environment before launching the command. **Always specify the full path** when there's a chance for confusion. So it's not reproducible? Are you sure that some previous module installation doesn't have anything to do? – CristiFati Sep 17 '18 at 18:15
  • @CristiFati, install is triggered automatically from our software: 1) it restores a target VM to the default snapshot, 2) waits for a handshake from a built-in "dropper" service; 3) sends command to this "dropper" to run powershell script containing "pip install". 4) Script is run as AutoUser (I logged it with 'query user'). I failed to reliably reproduce the issue. As for printing environment, what exactly would you recommend besides PATH? Other modules definitely have nothing to do here: they do not use python at all. – flam3 Sep 18 '18 at 14:40

4 Answers4

10

You can try setting the install target with the --target option like so:

pip install --target=C:\Users\Autouser\Appdata\Roaming\Python\site-packages package_name

If that doesn't work, another option is to try using --install-option like this:

pip install --install-option="--prefix=$PREFIX_PATH" package_name

Finally, if all else fails, here's one more way to do it:

PYTHONUSERBASE=/path/to/install/to pip install --user

You can specify which python version to install the package for by using python2.x -m pip install ...

Hopefully one of these helps you! :)

DeltaMarine101
  • 753
  • 2
  • 8
  • 24
  • 1
    None of those worked for me. What did work was adding `\site-packages\ ` (and `` gave me the path to the install location. – PfunnyGuy Jun 30 '22 at 21:51
2

Try running cmd as admin when installing

Pepe
  • 39
  • 5
  • Using an admin cmd prompt caused `pip install ` to install the package into e.g. `c:\program files\python39\scripts`, whereas a non-admin cmd prompt installed it into e.g. `c:\users\\appdata\roaming\python\python39\scripts'. – David Ching Aug 07 '21 at 23:25
0

CMD Prompt non-administrator, installed for current user:

Location: C:\Users\myuser\AppData\Roaming\Python\Python311\Scripts

enter image description here

CMD Prompt as ADMINISTRATOR, installed for all users:

C:\Program Files\Python\Scripts

enter image description here

Mohit
  • 807
  • 9
  • 11
-3

Unfortunately I had to fix the problem in production quickly, so I gave up and installed it without the --user option to c:/python27/... directory. I guess one of @DeltaMarine101 suggestions would help.

flam3
  • 1,897
  • 2
  • 19
  • 26
  • 2
    "I give up" is not a Solution. This would be fine if it were moved to a Comment, but it shouldn't be here as an Answer, especially the Accepted Answer. – Chris Moschini Oct 13 '20 at 13:35