简体   繁体   English

Python Terminal无效语法点

[英]Python Terminal Invalid Syntax Pip

Hello I am new to Stackflow so please bear with me on asking this question. 您好,我是Stackflow的新手,所以请允许我提出这个问题。

Earlier today, requests module did not work on my IDLE (3.6.5), and asked a question on reddit how to get it work. 今天早些时候,requests模块在我的IDLE(3.6.5)上不起作用,并询问了有关reddit的问题。 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/ ) 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. 现在,我能够从中恢复并且pip模块运行正常。 (eg If I tried running import requests on IDLE, it gives me no error). (例如,如果我尝试在IDLE上运行导入请求,则不会出现任何错误)。 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 ). 错误来自/anaconda3/bin/pip的事实意味着您正在为Anaconda安装运行pip命令,而不是实际要使用的其他Python 3.6安装的pip命令( /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. 我不确定您的Anaconda安装是如何损坏的,但是如果您不想使用它,则直接卸载它比尝试修复它会容易。

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? 周围有多个Python安装会很有用,但是如果您对此没有任何用处,为什么要让自己头痛呢? 1 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 . 同时,由于所有这些混乱,当您有或可能有多个Python安装时,建议的运行pip方法不仅是pip ,而是python3 -m pippython3 -m pip/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 . 基本上,无论您使用什么命令运行Python本身,都使用同一命令(添加-m pip )运行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. 激活环境后,无论您周围有其他Python安装如何,一切都将正常运行。


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. 1.不幸的是,在macOS上,是否需要预安装的Python 2.7,因此您将至少有两个Python版本。 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. 但是通常可以通过确保使用python3pip3等(而不是无后缀的版本)或使用虚拟环境来避免这种情况。 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. 另外,如果您的主Python是3.x版本,并且已经安装了它,因此不需要sudo ,那么就永远不要使用sudo ,就永远不能将某些东西(而不是您想要的东西)意外地安装到Apple Python中—如果这样做,将会出现权限错误,并且任何地方都不会安装任何东西。

Make sure pip is installed and added to your PATH. 确保已安装pip,并将其添加到您的PATH中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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