在 mac osx 中安装 python 模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39014749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install python modules in mac osx
提问by ronit
I am new to python. I am using python 3.5 on mac os x el capitan. I tried using the command 'pip install requests' in the python interpreter IDLE. But it throws invalid 'syntax error'.
我是python的新手。我在 mac os x el capan 上使用 python 3.5。我尝试在 python 解释器 IDLE 中使用命令“pip install requests”。但它会抛出无效的“语法错误”。
I read about installing modules is only possible in the command line. So I moved to TERMINAL, but no command is working here also. (I tried 'python -m pip install requests')
我读过有关安装模块的信息只能在命令行中进行。所以我搬到了 TERMINAL,但这里也没有任何命令在工作。(我试过'python -m pip install requests')
I read that mac os x comes with python 2.7 already installed and I ran 'easy_install pip' but it also works on the 2.7 version. Then there's discussion about the PATH settings also.
我读到 mac os x 已经安装了 python 2.7,我运行了“easy_install pip”,但它也适用于 2.7 版本。然后还有关于 PATH 设置的讨论。
Can please anybody explain to me how I can use my current version in TERMINAL window and what is the PATH scenario.
请任何人向我解释如何在 TERMINAL 窗口中使用我当前的版本以及什么是 PATH 场景。
I am familiar with the environment variable settings and adding pythonpath in windows but not on mac.
我熟悉环境变量设置并在windows中添加pythonpath但在mac上不熟悉。
采纳答案by ronit
Followed this guide. https://docs.python.org/3/using/mac.html
遵循了本指南。 https://docs.python.org/3/using/mac.html
Found python3.5 in usr/local/bin instead of the default usr/bin where the default 2.7 exists.
在 usr/local/bin 中找到了 python3.5,而不是默认 2.7 所在的默认 usr/bin。
The 3.5 Package automatically genrates an alias for itself that is python3.5 for use in terminal.
3.5 包会自动为自己生成一个别名 python3.5 用于终端。
Ran the command 'python3.5 -m pip install requests' and everything went good.
运行命令“python3.5 -m pip install requests”,一切顺利。
回答by Daniel Lee
Here is what you should do.
这是你应该做的。
Use homebrew to install python 2.7 and 3.5 in a virtual environment.
使用 homebrew 在虚拟环境中安装 python 2.7 和 3.5。
pip install virtualenv
Then make a directory called virtualenvs
in your root folder and add local files with.
pip install virtualenv
然后virtualenvs
在根文件夹中创建一个目录并添加本地文件。
cd virtualenvs
virtualenv venv
activate a virtualenv with source ~/virtualenvs/bin/activate
激活一个 virtualenv source ~/virtualenvs/bin/activate
Then use pip to install brew in this virtualenv pip install brew
然后使用pip在这个virtualenv中安装brew pip install brew
Then install python 2.7 as python and python 3 as python3:
然后将 python 2.7 安装为 python,将 python 3 安装为 python3:
brew update
brew install python
brew install python3
Then you can use python and python3 and not have to worry about the local install.
然后你可以使用python和python3而不必担心本地安装。
Then to run a file python3 filename.py
然后运行一个文件 python3 filename.py