Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install python modules in mac osx

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.

like image 245
ronit Avatar asked Aug 18 '16 09:08

ronit


2 Answers

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

like image 137
Daniel Lee Avatar answered Oct 22 '22 09:10

Daniel Lee


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.

like image 4
ronit Avatar answered Oct 22 '22 09:10

ronit