Trying to install third party modules on my mac using pip and I am getting this error (Using IDLE as the Python shell):
Traceback (most recent call last): File "<pyshell#1>", line 1, in <module> import pyperclip ModuleNotFoundError: No module named 'pyperclip'
(Have tried multiple modules and all return the same error)
I have installed the modules using:
pip3 install pyperclip
I can see that it has installed into the directory:
/opt/homebrew/lib/python3.9/site-packages
Ive tried going through several of the posts posted on StackOverflow such as this and this but after trying their steps I cant seem to resolve it.
which -a pip3 gives:
/opt/homebrew/bin/pip3 /Library/Frameworks/Python.framework/Versions/3.9/bin/pip3 /usr/local/bin/pip3 /usr/bin/pip3
which -a python3 gives:
/Library/Frameworks/Python.framework/Versions/3.9/bin/python3 /usr/local/bin/python3 /usr/bin/python3
print(sys.version) gives:
3.9.1 (v3.9.1:1e5d33e9b9, Dec 7 2020, 12:44:01) [Clang 12.0.0 (clang-1200.0.32.27)]
pip –version gives:
pip 22.1.2 from /opt/homebrew/lib/python3.9/site-packages/pip (python 3.9)
Running /usr/local/bin/python3 test1.py
:
Traceback (most recent call last): File "/Users/dxz/Downloads/test1.py", line 1, in <module> import pyperclip ModuleNotFoundError: No module named 'pyperclip'
Thanks
Advertisement
Answer
You can run this command for seeing pip3 uses which python:
pip3 --version
But i guess you are not choosing right python to run your .py file
if you run your .py like this:
python3 main.py
You must be sure pip3 installing libraries to ‘python3’ linked python or you can run your main.py file with one of pip3 linked python
I mean if pip3 –version gives you
/usr/bin/python3
this python path you can run your main.py like this
/usr/bin/python3 main.py
but if you want to use best practice i recommend to you using virtualenv