简体   繁体   中英

Python Terminal Invalid Syntax Pip

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. (eg 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?

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.

Make sure pip is installed and added to your PATH.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM