How to install python library for specific python version
11 Juni, 2024 oleh
How to install python library for specific python version
Aris Khumaini
| No comments yet

How to install Python packages on Windows, Mac, and Linux for various versions of Python which are simultaneously installed:

I have multiple versions of Python installed on my Windows 8.1 machine (Python 2.7, 3.5, and 3.7). This created problems (confusion, I should say). You must therefore be very explicit when installing packages. Ex:

py -3.7 -m pip install PyPDF2   # on Windows
python3.7 -m pip install PyPDF2 # on Mac and Linux

INSTEAD OF the more generic:

pip install PyPDF2 or
pip3 install PyPDF2

And to upgrade pipbe very specific in your python version, like this:

py -3.7 -m pip install --upgrade pip   # on Windows
python3.7 -m pip install --upgrade pip # on Mac and Linux

INSTEAD OF the more generic:

py -3 -m pip install --upgrade pip   # on Windows
python3 -m pip install --upgrade pip # on Mac and Linux

Now, I can run python 3.7 with py -3.7 on Windows, or with python3.7 on Linux, and since I did py -3.7 -m pip install PyPDF2 on Windows, or python3.7 -m pip install PyPDF2 on Linux or Mac, the import PyPDF2 command works! Previously, since I had only done pip3 install PyPDF2, the import PyPDF2 command only worked if I ran py -3.5 on Windows or python3.5 on Linux, oddly enough, since apparently that was my "default Python3 version" which the more generic pip3 install PyPDF2 command must have installed the PyPDF2 module into. I think it has something to do with the fact that I installed Python 3.5 for all users, but Python 3.7 for only my user account, so the different pip install commands were placing the installed packages into different locations, with the 3.5 version being the "default" Python3 install location.

See more here: https://docs.python.org/3/installing/index.html:

... work with multiple versions of Python installed in parallel?

On Linux, Mac OS X, and other POSIX systems, use the versioned Python commands in combination with the -m switch to run the appropriate copy of pip:

python2   -m pip install SomePackage  # default Python 2
python2.7 -m pip install SomePackage  # specifically Python 2.7
python3   -m pip install SomePackage  # default Python 3
python3.4 -m pip install SomePackage  # specifically Python 3.4

Appropriately versioned pip commands may also be available.

On Windows, use the py Python launcher in combination with the -m switch:

py -2   -m pip install SomePackage  # default Python 2
py -2.7 -m pip install SomePackage  # specifically Python 2.7
py -3   -m pip install SomePackage  # default Python 3
py -3.4 -m pip install SomePackage  # specifically Python 3.4


How to install python library for specific python version
Aris Khumaini 11 Juni, 2024
Share this post
Label
Arsip
Masuk to leave a comment