Search code examples
pythonpython-idlepyperclip

Unable to import pyperclip in my python IDLE, but able to import from command prompt


This is my first question on stackoverflow and I'm new to Python.

I want to import pyperclip module. So I went to cmd, ran as administrator, moved to the path using - cd \Program Files\Python37\Scripts and downloaded pip via pip3 install pyperclip command and it is successfully downloaded.

Now from IDLE I'm not able to import it

Following is the output from IDLE, it has not got that pyperclip module to import

Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 22:45:29) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> import pyperclip
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pyperclip
ModuleNotFoundError: No module named 'pyperclip'
>>> 

After this I did some research I found that, there could be possibility that it must have installed in some other directory. so from the research I found pyperclip folder and pyperclip-1.8.0-py3.6.egg-info folder in one of sub directory, which I copied and pasted in C:\Program Files\Python36 directory.

With above thing also I unable to import pyperclip from IDLE.

I went to command prompt, typed python and able to import it

Following is output C:\Users\Administrator>python

Python 3.6.0 (v3.6.0:41df79263a11, Dec 23 2016, 08:06:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyperclip
>>>

So I'm not able to import from IDLE, but able to do in command prompt.

1 more problem I found as I'm new to python, IDLE is showing python 3.8.2 and on command prompt it is showing 3.6. I have downloaded only 1 python and I have only 1 python installed. why there is this version difference 3.6 and 3.8.2

UPDATE: With following command on IDLE, I able to import pyperclip. But it is only for current opened IDLE. After closing IDLE and reopening it, I have do these commands again. How to fix it for all time

>>> import sys
>>> sys.path.insert(1, 'C:/Program Files/Python36')
>>> import pyperclip
~~~~~~~~~~

SOLVED:

Solution

  • In your case, IDLE is using one Python interpreter (Python 3.8.2), while in the command-line you run another one (Python 3.6.0), with pyperclip installed. You'd be better off to do ONE of the following steps:

    1) use multiple virtual environments to solve this problem easily (recommended). Read this article for more information.

    2) install the required module on both Python interpreters, by running pip install pyperclip either (depending on the Python version) from C:\PythonXX\Scripts or C:\Program files\PythonXX\Scripts

    3) you may also use single Python interpreter on your machine: remove one of the interpreters and then "Repair" another one (to fix the filetypes associations). To do this, open the installer from Windows uninstall manager and follow the steps it will give you.