Friday, January 22, 2016

Installing Python3 on Mac OSX

I have python 2.6 installed on my Mac.

I already had homebrew installed for perl.

I used the command

brew install python

and python 2.7 was installed. The bash profile command was altered to include the new python path at the start of the path command.

PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"

Install Python 3

Next, I tried to install python 3.

brew search

The name of the package is python3.

brew install python3

This was the first error:


C compiler cannot create executables

I had read a comment earlier about installing Xcode. I already had Xcode. Another comment was to enable command line tools. I did not know if they were already enabled. They weren't.

xcode-select --install

After this command and install, I was able to get further, but the install failed. After error

Need 'brew link xz'

Typed the command

brew link xz

and received an error. So, I ran

brew doctor

I changed the permission on a file. I was able to continue. python 3 is now installed in /usr/local/bin/python3

Install Virtual Environment 

I accessed Python Virtual Environment and learned about virtual environments.
 

Next, I created a virtual environment with the new python.

virtualenv -p python3 python3env

After installing, switch to the folder and activate the environment.

source bin/activate

Now, the path has the local python as the default python.

The virtual environment is alright, but I am limited to a text editor and console window.

Install Eclipse IDE

An IDE with code completion and syntax highlighting is preferable. 

Next, I installed Eclipse and added the PyDev plugin. I installed Eclipse for Java, since no option existed for python.

I followed the instructions at http://www.pydev.org/manual_101_install.html. I was required to accept a certificate that was not mentioned in the instructions.

For Mac, the preferences are not under the window menu, but in the usual preferences under Eclipse in the menu strip.

Next, I followed the instructions for creating a project. The interpreter was the default 2.7, not the new 3.5. I added the new interpreter to the preferences.

The tutorial is for 2. I am using 3, so tutorial code must be modified.

Install NetBeans IDE


Next, I checked to see if NetBeans had a plugin for python. NetBeans 8.1 has a python package that can be installed easily, 8.02 requires some worked. I upgraded to 8.1.

The default python was for jython in NetBeans. I added a reference to my python 3.

The default template for creating a module used python 2 syntax. The template for creating a package used python 3 syntax. 

Update

https://opensource.com/article/19/5/python-3-default-mac

use pip to install modules







 



No comments:

Post a Comment

Followers