Creating a Python workspace in MacOS Sierra v.10.12.6

Making yourself a workspace on your Mac to start writing Python code doesn’t even seem necessary at first glance, since Python comes with MacOS X. It’s true that Python does come preinstalled on a Mac. But, that install turns out to be rather useless for coding in Python. Apple may not keep the runtime environment up to date, but when they do upgrade the OS, the upgrade may wipe out all the site packages you’ve added to the preinstalled version of Python. Also, adding third party libraries to the system version of Python is a repetitive pain of telling your Mac it’s OK every time and making sure all permissions end up in correct mode. Furthermore, at the current time (August, 2017) there are two versions of Python in heavy use, 2.7 and 3.6. Python v.3.6 is not backward compatible with code written for 2.7 – which is a lot of code! And Python v.2.7 will not run all code written for 3.6 – also a lot of code, and the current and growing version. As you dig into creating your Python coding environment properly for you Mac, you find out that you’ll need to have 3 (at minimum) versions of Python running. The system version, the 2.7 version, and the 3.6 version – and that these need to be kept isolated from one another so libraries and packages for one don’t mix in and corrupt those for another. The system version needs to be left alone, exactly as any apps or system software that might need it expects it to be. Libraries and packages and environment for 2.7 and for 3.6 are incompatible and require isolation from each other. System wide sharing of one Python environment is not possible.
The folks writing documentation and instruction for Python users have a fuzzy consensus for the basics of what a solution for this looks like. It involves installing Xcode, an Apple IDE that has some tools you need; Homebrew, a third party package manager; using that to install fresh new copies of Python v.2.7 and v.3.6; pip, a Python package manager that comes with Python 3.6 as pip3 but a different version, pip2 needs manual install for Python 2.7; virtualenv, a tool to create virtual environments that are like separate shells that can’t see inside each other for the two Python versions you’ll be coding in; virtualenvwrapper which is an ease-of-use wrapper around virtualenv; pyenv, which is like a new version of virtualenv that comes with Python3. Along the way of installing these different pieces of software you’ll be making changes to your .bash_profile with additions to the PATH environmental variable, add a new environmental variable called WORKON_HOME and you’ll initialize virtualenvwrapper and pyenv. You’ll make a directory to hold your virtual environments called ~/.virtualenvs and you’ll create and activate a couple of virtual environments. Once that’s done you’ll go inside each these virtual environments and add whatever tools and libraries and packages you want for your Python programming convenience and needs. And that brings up a flaw you will run into – you can’t really run IDLE, the sort of basic, no frills free IDE that many use for writing Python, from within these virtual environments. IDLE wants a different version of Tkint, the tcl/tk language and libraries than what comes included in the Python installation packages, where it’s hard-coded. Outside the virtual environments you can install the correct version, but IDLE can’t see outside the virtual shell and won’t see it. You can’t install it inside the virtual environment, for reasons I’m frankly not very clear on, I just know it didn’t work by any of the usual methods when I tried, and many others have brought up this issue. You can add a flag (—system-site-packages) to virtualenv to make outside packages visible when you make a new virtual environment, but I didn’t like that. I don’t like IDLE very much either, so rather than spend time figuring out why it doesn’t run without complaining about Tkint, I just downloaded a different, nicer IDE called PyCharm which runs just fine – you just give each project the path to the Python version inside the virtual environment you want for that project, and everything’s copacetic.

I did not go into great detail in this article, no step-by-step “now type this and press enter” type stuff. I feel that would be very redundant, since there are several such scripted installation how-to’s already published – I used some of them myself. But for the convenience of cst’s readers and website visitors, I bookmarked the sites I went to as I was figuring all this out – here they are:

Add Color to the Terminal in Mac OS X

Installing Python 2 And Python 3 Alongside Each Other On Apple Mac Os X With Virtualenv And Virtualenvwrapper | Joe Bergantine | Designer

add python 2.7 to path mac – Google Search

osx – How to setup python path for 2.7 on mac? – Stack Overflow

sitecustomize.py and usercustomize.py mechanisms – Google Search

site – Site-wide configuration – Python Module of the Week

Python Imports — Reference Pages 0.2 documentation

Installing Python 2 on Mac OS X — The Hitchhiker’s Guide to Python

osx – Add to python path mac os x – Stack Overflow

4. Using Python on a Macintosh — Python 2.7.13 documentation

mac os x software update – Google Search

Check and Install Mac OS X Software Updates from the Terminal

running python 2.7 and 3.6 on mac os x – Google Search

osx – Switch between python 2.7 and python 3.5 on Mac OS X – Stack Overflow

Homebrew — The missing package manager for macOS

Installation — Homebrew

osx – Installing Python 2.7 and 3.6 Side by Side on Mac – Stack Overflow

Installing Python 2 And Python 3 Alongside Each Other On Apple Mac Os X With Virtualenv And Virtualenvwrapper | Joe Bergantine | Designer

Installing Python 2 And Python 3 Alongside Each Other On Apple Mac Os X With Virtualenv And Virtualenvwrapper | Joe Bergantine | Designer

Install Python3 on OS X, virtualenv & virtualenvwrapper

Install Python 2.7, virtualenv and virtualenvwrapper on OS X

Command Reference — virtualenvwrapper 4.7.3.dev12 documentation

28.3. venv — Creation of virtual environments — Python 3.4.7rc1 documentation

How do I edit $PATH (.bash_profile) on OSX? – Stack Overflow

Hathaway

How to Add a New Path to PATH at Command Line the Right Way

Add Color to the Terminal in Mac OS X

bash – Setting PATH environmental variables in OSX permanently – Stack Overflow

CST Thought repair shop and cognition cleansing service now open.

Cute headline, but it really describes my vision for a large category of web publishing work I’m planning, initiated by the article you are reading now. I call the category “errors in thought” in part because I own that domain and once had a website up there containing a previous version of this project. That version was taken offline when I could not devote enough time to creating content for it. So I’m doing what Hollywood calls a “reboot” here, and the errorsinthought.com website will be back online fairly quickly.

So what is this “thought repair workshop and cognition cleansing service?”

It’s a long term project to create a web resource devoted to studying and promoting good, rational thinking and decision making. Building this resource begins with writing informative articles rich with information on this topic, and creating a database of research papers, informal articles, raw data, feeds, links, media such as videos, podcasts, documentaries, and anything else I think belongs in the collection. As time goes on I plan to identify ways that creating new software can help people repair their poor thinking and cleanse their cognition of bias, fallacy and flaw to the maximum extent possible. Flawed thinking cannot be eliminated, but it can be greatly reduced, which would be a huge benefit to individuals who improve their thinking and to society at large.

By “poor thinking” you must mean holding political or philosophical positions you don’t like – right, Chris?

NO, absolutely not and I will make every effort I can to ensure that teaching people ways to think better and make better decisions here only speaks to that which is common to all human beings and is free of ideological, religious, or other content that is divisive and exclusionary. It’s my true desire to provide a place where improving one’s thinking can be done in peace, away from the typical internet site tribal warfare, trolling, flaming and all the rest.

What makes you qualified to help people understand and improve their thinking and decision making?

Nothing. I am not qualified by any credentials or employment experience to do to such a thing. I am going to do it anyway, and looking inside myself for doubt, I find none. I’m supremely confident I can create this resource and help a lot of people, and that what I create will be as accurate and consistent with the research record as any similar resource created by universities and PhD’s in psychology. I would not do this if I thought there was any danger that my lack of qualifications would result in a low-quality site giving out inaccurate information, that could hurt our website visitors. No, every sentence I publish here will be fact checked and references put in the database before I allow it on this section of the site. I don’t need to be qualified in psychology for that.

The way I envision it, creating the site, doing all the research, accumulating the database, engaging in discussions in the site’s forums and chatrooms and writing all the articles will make me very highly qualified in this topic in a very short time. That is my primary reason for building this project – to improve my own thinking and decisions.

Aren’t there plenty of sites and/or blogs that cover this same material already? Why is yours needed, Chris? Why waste your time doing what others have already done?

Indeed there ARE plenty of sites, blogs, and pages covering this same subject matter. Some are devoted to it, others cover it as part of covering a broader topic like psychology or philosophy. But I did not build those sites, or write those articles or publish those blogs – and thus I did not get the thorough, in-depth education in this topic that this project will give me, which I am hoping will considerably improve my own thinking and decision making. I want to study this subject rigorously and in detail and completely master the knowledge, and I cannot think of a better way to do that than to fill entire websites with articles I have written about it, create a database of relevant material, and design software that helps people with it. That is why doing this project makes sense even though the needs of this market are already met.