简体   繁体   English

在 Mac 上安装 Python 和 pip 不显示版本?

[英]Python and pip installation on Mac don't show version?

On Mac OS.在 Mac 操作系统上。

Downloaded the Python from their website.从他们的网站下载了Python

Python -V return Python 2.7.16 , and python3 -V return Python 3.9.4 Python -V返回Python 2.7.16python3 -V返回Python 3.9.4

Installed pip with: python3 get-pip.py , got Successfully installed pip-21.0.1安装pippython3 get-pip.pySuccessfully installed pip-21.0.1

But when I run pip -V I get File "/usr/local/bin/pip", line 1.... SyntaxError: invalid syntax但是当我运行pip -V我得到File "/usr/local/bin/pip", line 1.... SyntaxError: invalid syntax

After reading here a lot, i could not understand (in simple words for dumbs):在这里阅读了很多之后,我无法理解(对于笨蛋来说简单的话):

  1. How could you "alias" or update python to show/run in version 3+?您如何“别名”或更新 python 以在版本 3+ 中显示/运行?
  2. Why I can't get the pip version if it's installed ?如果安装pip版本,为什么我无法获得它?

Use pip as a module instead使用 pip 作为模块代替

% python3 -m pip --version
pip 21.0.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)

Anyone who's interested, what i had to do is to任何有兴趣的人,我要做的就是

  1. CD the project on terminal在终端上 CD 项目
  2. run python3 -m venv env (this create virtual environment of python3 inside project)运行python3 -m venv env (这会在项目中创建 python3 的虚拟环境)
  3. run source env/bin/activate activate it.运行source env/bin/activate激活它。
  4. now pip --version or python --version will return the right results.现在pip --versionpython --version将返回正确的结果。

From my basic knowledge i understand that the mac is using python2 which we don't want to interrupt, so we install python3 and create a 'virtual environment' for it inside our project folder, once its in, we can install all other things.根据我的基本知识,我知道mac正在使用我们不想中断的python2,所以我们安装python3并在我们的项目文件夹中为它创建一个“虚拟环境”,一旦它进入,我们就可以安装所有其他东西。

to deactivate (stop the virtual env) we run deactivate停用(停止虚拟环境)我们运行deactivate

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

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