0

Hello I am new to Stackflow so please bear with me on asking this question.

Earlier today, requests module did not work on my IDLE (3.6.5), and asked a question on reddit how to get it work. However, I followed a bad advice, and might have deleted some site-packages. (https://www.reddit.com/r/learnpython/comments/8xgx1p/no_module_named_requests/)

Now, I was able to recover from it and pip module is running fine. (e.g. If I tried running import requests on IDLE, it gives me no error). However, on Terminal, when I try to run commands such as "pip list", it gives me Invalid syntax error.

Could someone help a newbie out?

jyabjyabs
  • 13
  • 1
  • 5
  • 1
    Please show exactly what you typed, and the exact error you got, rather than just describing it vaguely. – abarnert Jul 10 '18 at 00:12
  • Also, are you typing `pip list` into the bash shell in your Terminal (at the prompt that looks like `jyabjyabs-macbook:myproj jyabjyabs$`), or did you run `python` in the terminal, and then try to type `pip list` inside Python (at the prompt that looks like `>>>`)? If the latter, that's your problem: `pip` is a command that you run at the shell, not a Python statement. – abarnert Jul 10 '18 at 00:14
  • I am typing in terminal, where it says my user name jyabjyabs:~ – jyabjyabs Jul 10 '18 at 00:56
  • The error Terminal gives me is: Traceback (most recent call last): File "/anaconda3/bin/pip", line 7, in from pip._internal import main ModuleNotFoundError: No module named 'pip' – jyabjyabs Jul 10 '18 at 00:56
  • I tried adding my executable which is (/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6) infront of the command, but did not work. It just gives me, File "", line 1 "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6" -m pip install request ^ SyntaxError: invalid syntax – jyabjyabs Jul 10 '18 at 00:59
  • OK, is the Python installation you're trying to use an Anaconda one? And did you ever install two different Pythons on this machine (e.g., one from the python.org installer, and another from Anaconda)? Because it looks like you have a leftover `pip` command from a Python installation that you either uninstalled, or wiped clean. – abarnert Jul 10 '18 at 01:00
  • (You _always_ have at least one extra Python on macOS, because Apple gives you a 2.7.10 version whether you want it or not. But that one isn't in `/anaconda3` or in `Library/Frameworks/Python.framework/Versions/3.6`, so it isn't the problem here.) – abarnert Jul 10 '18 at 01:01
  • Also, it would really help if you could copy and paste each command—including the prompt, and the full error output—into your question, instead of just adding comments. – abarnert Jul 10 '18 at 01:07
  • I am using IDLE 3.6.5 to run python... – jyabjyabs Jul 10 '18 at 01:10
  • But I do have anaconda on my laptop, but I am not using it at all – jyabjyabs Jul 10 '18 at 01:10
  • No, IDLE is just the IDE, not the Python installation. Each Python installation will have its own copy of IDLE. – abarnert Jul 10 '18 at 01:11
  • I'm really sorry, I am trying to provide as much information. How can I check which installation I'm using to run python? All I know is that I'm currently using IDLE to run python codes – jyabjyabs Jul 10 '18 at 01:19
  • I am currently learning through the book called "Automate the boring stuff with Python", and I remember downloading something from python,org – jyabjyabs Jul 10 '18 at 01:21

2 Answers2

0

The fact that the error comes from /anaconda3/bin/pip means that you're running the pip command for your Anaconda installation, not the pip command for the other Python 3.6 installation you actually wanted to use (the one in /Library/Frameworks/Python/Versions/3.6).

I'm not sure how your Anaconda installation got broken, but if you don't want to use it, it may be easier to just uninstall it than to try to fix it.

And that will also save you a lot of confusion in the future. Having multiple Python installations around can be useful, but if you don't have any useful for it, why give yourself the headaches?1

Meanwhile, because of all of that confusion, when you have, or might have, multiple Python installations, the recommended way to run pip is not just pip, but instead python3 -m pip or python3 -m pip, or /Library/Frameworks/Python/Versions/3.6/bin/python -m pip. Basically, whatever command you use to run Python itself, use that same command (with -m pip added) to run pip.

You might also want to consider using a virtual environment. Once you've activated an environment, everything will just work, no matter what other Python installations you have lying around.


1. Unfortunately, on macOS, there's a pre-installed Python 2.7 whether you want it or not, so you will have at least two Python versions. But you can usually avoid this by either making sure to use python3, pip3, etc. instead of the no-suffix versions, or using virtual environments. Also, if your main Python is a 3.x version, and you've installed it so that it doesn't need sudo, so you never use sudo, you can never accidentally install something into the Apple Python instead of the one you wanted—if you do, you'll get permission errors and nothing will get installed anywhere.

abarnert
  • 354,177
  • 51
  • 601
  • 671
  • Thank you! Uninstalling Anaconda Navigator, Anaconda3 files seemed to do the trick. Now I can run pip commands successfully. – jyabjyabs Jul 10 '18 at 01:29
-1

Make sure pip is installed and added to your PATH.

https://pip.pypa.io/en/stable/installing/

Sam Bokai
  • 538
  • 1
  • 5
  • 13