0

So I installed different versions of Pythons on my mac and it seems this is the root of all my problems at the moment. I want to import the module named pyperclip in Mueditor but it always says No module named 'pyperclip'

I read a lot of different other threads and tried to sudo /usr/bin/python get-pip.py But I always get /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'get-pip.py': [Errno 2] No such file or directory Which indicates that it is searching in the wrong directory (not sure with the correct terminology here).

I installed Python 3.8 with homebrew and everything is updated fine.

For context: I started programming with anaconda, deleted it downloaded Python from the official website and am using Mueditor right now while following the tasks in the book 'Automate the boring stuff with Python'.

I am even considering setting up my OSX again... Help is much appreciated!

Mxngls
  • 437
  • 1
  • 5
  • 16

2 Answers2

1

I read a lot of different other threads and tried to sudo /usr/bin/python get-pip.py But I always get /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'get-pip.py': [Errno 2] No such file or directory Which indicates that it is searching in the wrong directory (not sure with the correct terminology here).

I installed Python 3.8 with homebrew and everything is updated fine.

  1. You need to download the get-pip.py file and then execute that command referencing that file.
    https://bootstrap.pypa.io/get-pip.py

  2. Make sure you are selecting the right Python interpreter. You have multiple installed. You can check their versions with /usr/bin/python -V. In your case /usr/bin/python/ is Python 2.7.

  3. Python 3.8 comes with pip installed. Once you figured out the path of your Python3 interpreter you can do: /path/to/your/python3 -m pip install pyperclip.

Community
  • 1
  • 1
Tin Nguyen
  • 5,250
  • 1
  • 12
  • 32
  • How can I find out the path of my Python3 interpreter? – Mxngls May 29 '20 at 07:36
  • `which python3` to get your "default" python3 interpreter path if it exists. Else you will have to search through your file system e.g. `find /usr -name "python3"`, `find ~ -name "python3"` – Tin Nguyen May 29 '20 at 07:40
  • I did as you said and got: Requirement already satisfied: pyperclip in /usr/local/lib/python3.7/site-packages (1.8.0) But when I try to import pyperclip (in Mueditor) I still get: Traceback (most recent call last): File "/Users/XXX/mu_code/mclip.py", line 8, in import sys, pyperclip ModuleNotFoundError: No module named 'pyperclip' – Mxngls May 29 '20 at 07:44
  • You are executing your project with a different Python interpreter. You installed pyperclip with `/path/to/your/python3 -m pip install pyperclip` but you are executing your project with `/path/to/a/different/python3 main.py` – Tin Nguyen May 29 '20 at 07:45
  • How can I change this? I guess I understand why it is not working but I am not sure what I can do to fix it. Thanks for the help! – Mxngls May 29 '20 at 07:52
  • Go into your project settings and adjust the python's interpreter's path. As to selecting the correct python interpreter when merely typing `python` or `python3` there are different approaches. Anaconda has something for that but I don't use that. I use pyenv `https://github.com/pyenv/pyenv`. If you want to see how that works you will have to research it. It is a lot to take in. More importantly is you set up a proper development environment, stick to it and become comfortable with it before jumping from one to the next. – Tin Nguyen May 29 '20 at 07:57
  • As far as I can see it seems that I can't change the path in Mueditor. I started with Anaconda and felt fine but was unable to run a script from terminal (probably my fault). To be honest I really feel overwhelmed with all the possibilities. – Mxngls May 29 '20 at 08:07
  • The Mueditor looks very simplistic which is why I wouldn't use it. I recommend using Visual Studio Code with Python add-ons or PyCharm. These are more advanced editors and it has a lot more options so it is easy to be overwhelmed but they are necessary. PyCharm is available on Mac, Linux and Windows and it has a very big user base which is also what I use most often. I sometimes have to develop with Visual Studio Code because of its free remote SSH support. Start with a fresh OSX and decide what tools you want to employ and stick to it so you get the chance to familiarize. – Tin Nguyen May 29 '20 at 08:17
  • I know a lot of people who use anaconda. I don't so I can't give you any advice there. I only know the Python tools I use and I'm comfortable with them. Pick an editor: PyCharm vs Visual Studio Code vs ???. Choose between virtualenv, pyenv, anaconda, ... (https://stackoverflow.com/questions/38217545/what-is-the-difference-between-pyenv-virtualenv-anaconda), get familiar with unix commands and develop an understanding how they work. – Tin Nguyen May 29 '20 at 08:22
0

Check the Python version :

python --version
python3 --version

Install pip using easy_install on MacOS

easy_install is a Python module bundled with setuptools which gives us the ability to download, build, install and manage Python packages

sudo easy_install pip

Install pip using get-pip.py on MacOS

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

python get-pip.py

or

python3 get-pip.py

Install pip with brew on MacOS

brew install python

If any problems related to the pip usage we will have to relink the python with the following command.

brew unlink python && brew link python
brew unlink python3 && brew link python3

In the end after following any of the above steps, check and verify pip version

pip -V

pip3 -V
psorab
  • 135
  • 1
  • 16