6
votes

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'.

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')

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.

Can please anybody explain to me how I can use my current version in TERMINAL window and what is the PATH scenario.

I am familiar with the environment variable settings and adding pythonpath in windows but not on mac.

2
typepip install requests from the terminal. What does it say? Also try which pip and which python from the terminal - Daniel Lee
Now it says 'Requirement already satisfied (use --upgrade to upgrade): requests in /Library/Python/2.7/site-packages' .I ran easy_install pip first , it installed pip in the 2.7 version.and the requests module now also have been installed in the 2.7 version. But i want to install in the current 3.5 version i am using. - ronit
try which python and which pip to see which directories they are using - Daniel Lee
Ronits-Air:~ root# which python /usr/bin/python Ronits-Air:~ root# which pip /usr/local/bin/pip....heres the output - ronit

2 Answers

6
votes

Here is what you should do.

Use homebrew to install python 2.7 and 3.5 in a virtual environment.

pip install virtualenv Then make a directory called virtualenvs in your root folder and add local files with.

cd virtualenvs
virtualenv venv

activate a virtualenv with source ~/virtualenvs/bin/activate

Then use pip to install brew in this virtualenv pip install brew

Then install python 2.7 as python and python 3 as 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.

Then to run a file python3 filename.py

4
votes

Followed this guide. 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.

The 3.5 Package automatically genrates an alias for itself that is python3.5 for use in terminal.

Ran the command 'python3.5 -m pip install requests' and everything went good.