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