5

I have pip install <package name> installing the packages to AppData/Python/Python36/Scripts folder. How do I know the exact path to this folder from Command line?

I tried doing py -m site --userbase This is showing AppData/Roaming/Python/Python36 which does not exist. How will I get to know the path without actually doing manual search?

PS : I am writing an automation script to install pip and awscli later. After I install pip, I face command not found error. So looking how to set path directly from a script without having to face the issue of manually setting it. Found out that pip.exe and aws.exe are under AppData/Python/Python36/Scripts. My question is how do I get this path from inside a script.

Nagireddy Hanisha
  • 1,290
  • 4
  • 17
  • 39
  • The normal per-user installation directory is `"%LocalAppData%\Programs\Python\PythonXY[-32]"`, and the installer has an option to add this directory plus the "Scripts" subdirectory to `"%PATH%"` (i.e. add Python to environment variables). The installation directory is `sys.prefix`. – Eryk Sun Feb 28 '18 at 13:04
  • "--user" package installations instead use roaming "%AppData%\Python\PythonXY". I don't recommend using this install option. It was always wrong-headed to use the roaming application data directory to install packages, which may be very large (e.g. scipy). Use virtual environments instead (i.e. `venv`). Maybe in future releases --user can be changed to use "%LocalAppData%\Programs\PythonXY[-32]" in harmony with the default per-user installation target. Then if you install per user to the default directory, using the --user option with pip would basically be ignored. – Eryk Sun Feb 28 '18 at 13:05

1 Answers1

28

Here's how to obtain the requested result:

python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
Pitto
  • 8,229
  • 3
  • 42
  • 51
  • I have edited my question.Can you please take a look at the edited version. – Nagireddy Hanisha Feb 28 '18 at 11:39
  • 1
    Hi there! I am not sure I 100% understand. So you basically want to be able to run pip command from every folder without having errors? – Pitto Feb 28 '18 at 11:42
  • Yes... The scenario is: I have python and pip installed. But path is not set to access it from everywhere. So how do I obtain path from batch/bash script commands to set PATH variable it from a script. – Nagireddy Hanisha Feb 28 '18 at 11:46
  • Please check updated version of answer I provided two ways – Pitto Feb 28 '18 at 11:46
  • I am glad it helped! Can you please share what worked for you so I can edit the answer in order to make it useful for others facing the same issue? – Pitto Mar 02 '18 at 20:27
  • 1
    The last line python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" – Nagireddy Hanisha Mar 05 '18 at 06:15