3

I've been using Pycharm to learn the basics of Python, but using the terminal to test a file.py is causing me trouble. The issue I get is

ImportError: No module named pyperclip

I've seen this issue occurring often on this website, finding references about PYTHONPATH, and suggestions to change the directory of either PyCharm or the terminal. But I'm not clear at how to proceed. the inventwithpython.com tackles part of this issue with "This file must be in the same folder as the Python program files that you type. (A folder is also called a directory.) "

I have python 3.7 installed under /usr/local/bin/python3.7 and I have pyperclip installed under /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages

When I run a python file, they're under /Users/myusername/PycharmProjects

importing the module with PyCharm causes no issue, but importing it via the terminal is not working.

How do I make the terminal copy the settings of PyCharm ? There has been discussion about export PYTHONPATH= , but some comments advised against it.

EDIT 1: I have now changed the path in PyCharm from /usr/local/bin/python3.7 to /Library/Frameworks/Python.framework/Versions/3.7/bin/python3

I still have the issue, but both the module and Python are now under the same directory.

EDIT 2: Beginner's mistake, I was running the command line as 'python test.py' instead of 'python3 test.py', the python version ran was thus 2.7, which doesn't have the modules installed. I found it by running a test.py file containing

import sys
print (sys.path)

and comparing the different result of python test.py vs python3 test.py

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Wick End
  • 31
  • 3

1 Answers1

0

Try installing pyperclip in the directory where your python is installed i.e., /python3.7 Make sure that you have set the PATH to environment variables.

Prachi Sharma
  • 331
  • 1
  • 5
  • 14
  • Do you mean I have to move all the modules currently installed in the the /lib directory to the /bin ? – Wick End Jul 18 '18 at 19:00
  • Don't move it. Just install pyperclip in Python directory. Your default python directory will be ..\local\programs\python\python37. Also, make a habit of doing Custom installation of Python instead of direct Install Now. – Prachi Sharma Jul 18 '18 at 19:32
  • Ok I see, I will use the custom installation from now on. I corrected the issue by running "python3" instead of just "python" in the command line. – Wick End Jul 18 '18 at 19:38