-1

Working on Automate The Boring Stuff project and having trouble with pyperclip and IDLE. pyperclip is successfully downloaded and works fine in Terminal but when I import pyperclip in IDLE, I get the below error.

UPDATE - This is happening with other modules - anything I've installed in the terminal aren't importing into IDLE.

import pyperclip Traceback (most recent call last): File "", line 1, in import pyperclip ModuleNotFoundError: No module named 'pyperclip'

I figure I have the module saved in the wrong folder somehow. Below are the sys.path outputs from my Terminal and IDLE.

In terminal:

'/anaconda/bin', '//anaconda/lib/python36.zip', '//anaconda/lib/python3.6', '//anaconda/lib/python3.6/lib-dynload', '//anaconda/lib/python3.6/site-packages', '//anaconda/lib/python3.6/site-packages/Sphinx-1.5.1-py3.6.egg', '//anaconda/lib/python3.6/site-packages/aeosa', '//anaconda/lib/python3.6/site-packages/IPython/extensions', '/Users/andrewricardo/.ipython']

In IDLE:

sys.path ['', '/Users/andrewricardo/Documents', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']

There are multiple paths here - how do I effectively move the pyperclip module to the correct place?

OR - Is there something else going on here?

  • This is a duplicate question, but my answer here gives, I believe, new information, with details specific to this situation. – Terry Jan Reedy Mar 28 '17 at 14:53
  • This question is really about multiple python installs, not about IDLE. It is possible that the anaconda python also has IDLE, and that it would work for you. My answer is for the question of how to use packages with the framework python. – Terry Jan Reedy Mar 28 '17 at 14:56

2 Answers2

0

Each python installation and uses its own .../lib/site-packages for 3rd party modules, and you have two. If you ran the non-anaconda python in the terminal, the same that is running IDLE, it would have the same problem. Indeed, that python is the source of the ImportErrors.

Option 1: Separately install all packages you want to use with the non-anaconda python (and IDLE) in its own site-package directory. In IDLE Shell, get the path to its executable

>>> import sys; sys.executable

Save are remember the resulting 'python-path'. Then in the terminal, run

python-path -m pip install package-name

for each package.

Option 2 (uses a little known feature of site-package directories): in

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages

add a file name, for instance, anaconda.pth, containing one line.

//anaconda/lib/python3.6/site-packages

(I have no idea why the double / or if it is really needed; I just copied it from your question.) This makes the anaconda python site-packages an extension of the framework python site-packages. Since both are for 3.6, one copy should work for both.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
0

Had this same issue and googled

'why is importing pyperclip in my python file giving an "modulenotfounderror"but working fine in the idle'

and this page came up. then i also checked this [installed Pyperclip, trouble importing to IDLE.

I am new to python, had the same issue using the same book after pip installing pyperclip here's what I did to solve this issue.

I copied the pyperclip-1.7.0-py3.7.egg-info and pyperclip folders from

C:\Users\USER\AppData\Local\Programs\Python\Python37\Lib\site-packages into the C:\Users\USER\Anaconda3\Lib\site-packages folders and C:\Users\USER\AppData\Local\Programs\Python\Python37 folders and it worked. Hope this helps. If it doesn't. Try this code in your text editor because that's what I did using Atom and how i was able to solve it.

import sys print(sys.executable)

Then copy the pyperclip-1.7.0-py3.7.egg-info and pyperclip folders into the path that the above code gives you.

Derin
  • 11
  • 3