Skip to main content

How to install 3rd parties modules to Python 3.6

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'

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:
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

Comments

Popular posts from this blog

Upgrade BeautifulSoup4 to compatible with Python 3.6

After upgraded to Python 3.6 from 3.5, I encountered BeautifulSoup (bs4) error, such as 'ImportError: cannot import name 'HTMLParseError'. Seems there's compatible problem for BeautifulSoup 4 version. Solution: Upgrade beautifulsoup 4 version to 4.6.0 Commands: $ pip3 install --upgrade beautifulsoup4 Deep in: Install pip3 command: $ sudo apt install python3-pip

Atom community packages recommendation for Python development

Below are Atom community packages I installed for Python development. They are covered most of functions u need. Take this post as an backup.  

Solved: Pyperclip could not find a copy/paste mechanism for your system.

OS: Debian 9 Python version: 3.5 After import pyperclip module, encounter error message ' Pyperclip could not find a copy/paste mechanism for your system. '. Solution: install xsel utility $ sudo apt install xsel then reboot Python IDLE3, import pyperclip, solved. *************** Install pip/pyperclip: $ sudo apt install python3-pip $ sudo pip3 install pyperclip