How to work with multiple versions of Python installed in parallel? Python version upgrades quickly, it's caused multiple versions on my Debian OS: Python 2 defaults to 2.7; Python 3 defaults to 3.5, then when I installed Python 3.6. It causes 3rd parties modules import problem in Python 3.6.
Take popular pyperclip as example. When I installed pyperclip module, which is popular one to copy/paste clipboard content, in bash with:
pip3 install pyperclip
It prompts install successful, but prompt error when I import in Python 3.6.
>>> import pyperclip
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
>>> import pyperclip
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
The reason is the default Python 3 is 3.5 i/o 3.6. Install with pip3 will point to 3.5 directly. So solved it, install as following:
peter@Debian:~$ python3.6 -m pip install pyperclip
Docs Refer:
https://docs.python.org/3/installing/index.html?highlight=pip#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 ofpip
:
Appropriately versioned
pip
commands may also be available.
On Windows, use the
py
Python launcher in combination with the -m
switch:
Comments
Post a Comment