How to install a package for a specific Python version on Windows 10?

package-managers, python, python-3.x

Solution

The golden rule when one wants to access one of the multiple software versions (applies to any software (other than Python), on any OS) existing on a machine: use absolute paths.

There are multiple ways of `pip install`ing (especially when involving VEnvs):

Run PIP directly - most frequently used:

pip install --upgrade pyaudio

Run `python -m pip`:

python -m pip install --upgrade pyaudio

Run other convenience wrappers (Py (Win specific): [Python.Docs]: Using Python on Windows - From the command-line):

py -3.6 -m pip install --upgrade pyaudio

But the form that I prefer (as it will always work - because it doesn't rely on environment variables like PATH), is the 2nd one:

"${PATH_TO_YOUR_PYTHON_3_6}" -m pip install --upgrade pyaudio

where ${PATH_TO_YOUR_PYTHON_3_6} is just a placeholder for the actual Python 3.6 executable path (e.g. %ProgramFiles%\Python 3.6\python.exe). Note that this works fine (end easy) when having multiple Python versions installed (custom built, VEnvs, ...). Check [Python.Docs]: Using Python on Windows - Installing Without UI for more details regarding install paths.

Generalizing:

"${PATH_TO_PYTHON_EXECUTABLE}" -m pip install ${PACKAGE_NAME}

where ${PACKAGE_NAME} is (obviously) the package name. Note that sometimes, due to special conditions (like local PIP repositories configuration, ...), the installation would have to be done in 2 steps:

Download the .whl locally

Pass it to PIP (in order to install it)

as described in [SO]: Installing pygraphviz on Windows 10 64-bit, Python 3.6 (@CristiFati's answer) (Shortcut section (somewhere at the end)).

${PATH_TO_PYTHON_EXECUTABLE} (using v3.9 as an example) can be (from my machines):

Win:

%ProgramFiles%\Python 3.9\python.exe

E:\Work\Dev\VEnvs\py_pc064_03.09_test0\Scripts\python.exe

F:\Install\pc064\Anaconda\Anaconda\Version\python.exe

Nix:

/usr/bin/python3.9

/opt/qti-aic/dev/python/qaic-env/bin/python

When not sure about an executable location (actually not limited to executables), that can be checked:

Win: [MS.Docs]: where (`where /?`)

Nix: [Die.Linux]: which(1) (`man which`). Worth mentioning aliases: [Man7]: ALIAS(1P) (`man alias`)

Might also worth reading:

[SO]: PyCharm doesn't recognize installed module (@CristiFati's answer)

[SO]: How to update pywin32 automatically? (@CristiFati's answer)

[SO]: PyAudio.write SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats (@CristiFati's answer)

Problem

I currently have Python 3.7.4(64 bit) and Python 3.6.6(64 bit) on a Windows 10 64 bit laptop with both versions in my system environment variables(path). I previously only had 3.7 and installed 3.6 to use `pocketsphinx`, and now I want to upgrade `PyAudio` of my 3.6. doing `pip install --upgrade pyaudio` is upgrading the `pyaudio` of 3.7. So, how do i upgrade(or even install) packages of specific python versions on a windows machine? Here's also what I've tried: `python-3.6.6 pip install --upgrade pyaudio`, `python3.6.6 pip install --upgrade pyaudio`, `python3.6 pip install --upgrade pyaudio` and `pip3.6.6 install --upgrade pyaudio`. Yes, these may be stupid, but I was helpless. EDIT 1: I also run `pip install --upgrade pyaudio` in power shell by opening it in the directory where my python 3.6 is installed, which is(default installation directory for windows): `C:\Users\--user-name--\AppData\Local\Programs\Python\Python36` like: as you can see from the version, `pip install` would still install new packages for python 3.7

Original source

Related problems