Notes To SetUp Python Dev Environment on My MacOs High Sierra Version 10.13.1

Notes To SetUp Python Dev Environment on My MacOs High Sierra Version 10.13.1

My Notes while setting up Python/Django/Postgres/Dockers Dev Environment on My MacOs High Sierra Version 10.13.1

 

VirtualEnv 

eSumit@Sumits-MacBook-Pro:~$ virtualenv
virtualenv virtualenvwrapper_initialize virtualenvwrapper_verify_active_environment
virtualenv-clone virtualenvwrapper_lazy.sh virtualenvwrapper_verify_project_home
virtualenvwrapper virtualenvwrapper_load virtualenvwrapper_verify_resource
virtualenvwrapper.sh virtualenvwrapper_mkproject_help virtualenvwrapper_verify_virtualenv
virtualenvwrapper_absolutepath virtualenvwrapper_mktemp virtualenvwrapper_verify_virtualenv_clone
virtualenvwrapper_cd virtualenvwrapper_mkvirtualenv_help virtualenvwrapper_verify_workon_environment
virtualenvwrapper_derive_workon_home virtualenvwrapper_run_hook virtualenvwrapper_verify_workon_home
virtualenvwrapper_expandpath virtualenvwrapper_setup_tab_completion virtualenvwrapper_workon_help
virtualenvwrapper_get_python_version virtualenvwrapper_show_workon_options 
virtualenvwrapper_get_site_packages_dir virtualenvwrapper_tempfile 
eSumit@Sumits-MacBook-Pro:~$ virtualenv

Installing Brew Install PyEnv

 

Brew Install PyEnv
Brew Install PyEnv

On SSL Error Issue

eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$ brew link --force openssl
 Warning: Refusing to link: openssl
 Linking keg-only openssl means you may end up linking against the insecure,
 deprecated system OpenSSL while using the headers from Homebrew's openssl.
 Instead, pass the full include/library paths to your compiler e.g.:
 -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$

configure: error: OpenSSL is not installed.
 make: *** No targets specified and no makefile found. Stop.
 Problem(s) detected while checking system.

See https://github.com/yyuu/pyenv/wiki/Common-build-problems for known solutions.
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$ ln -s /usr/local/opt/openssl /usr/local/ssl
 ln: /usr/local/ssl: Permission denied
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$ sudo ln -s /usr/local/opt/openssl /usr/local/ssl
 Password:
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$

 

 

Last login: Fri Jan 5 17:59:23 on ttys001
 eSumit@Sumits-MacBook-Pro:~$ pyenv doctor
 Cloning /Users/eSumit/.pyenv/plugins/pyenv-doctor/bin/.....
 Installing python-pyenv-doctor...
 python-build: use readline from homebrew
 Installed python-pyenv-doctor to /var/folders/kr/bq8kqm_54l13knm864fxk78m0000gn/T/pyenv-doctor.20180105180147.13580/prefix

Congratulations! You are ready to build pythons!
 eSumit@Sumits-MacBook-Pro:~$

Reference : https://github.com/pyenv/pyenv-doctor

 

if brew link openssl --force does not work

cd /usr/local/include
ln –s ../opt/openssl/include/openssl .

Common Build Problems 

https://github.com/pyenv/pyenv/wiki/Common-build-problems

Python Environment Doctor

https://github.com/pyenv/pyenv-doctor

 

eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$ pyenv-doctor
 -bash: pyenv-doctor: command not found
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$ pyenv doctor
 Cloning /Users/eSumit/.pyenv/plugins/pyenv-doctor/bin/.....
 Installing python-pyenv-doctor...
 python-build: use readline from homebrew

BUILD FAILED (OS X 10.13.1 using python-build 20160602)

Inspect or clean up the working tree at /var/folders/kr/bq8kqm_54l13knm864fxk78m0000gn/T/python-build.20180105173928.6027
 Results logged to /var/folders/kr/bq8kqm_54l13knm864fxk78m0000gn/T/python-build.20180105173928.6027.log

Last 10 log lines:
 checking whether we are cross compiling... no
 checking for suffix of object files... o
 checking whether we are using the GNU C compiler... yes
 checking whether clang accepts -g... yes
 checking for clang option to accept ISO C89... none needed
 checking for rl_gnu_readline_p in -lreadline... yes
 checking for readline/readline.h... no
 checking for SSL_library_init in -lssl... no
 configure: error: OpenSSL is not installed.
 make: *** No targets specified and no makefile found. Stop.
 Problem(s) detected while checking system.

See https://github.com/yyuu/pyenv/wiki/Common-build-problems for known solutions.
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$

Go there https://github.com/pyenv/pyenv/wiki/Common-build-problems and Install :

eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$ brew install readline xz
 Warning: readline 7.0.3_1 is already installed
 ==> Downloading https://homebrew.bintray.com/bottles/xz-5.2.3.high_sierra.bottle.tar.gz
 ######################################################################## 100.0%
 ==> Pouring xz-5.2.3.high_sierra.bottle.tar.gz
 🍺 /usr/local/Cellar/xz/5.2.3: 92 files, 1.4MB
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$

Python Version 

eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$ python -V
 Python 2.7.10
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$

Python –help

eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$ python --help
 usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
 Options and arguments (and corresponding environment variables):
 -B : don't write .py[co] files on import; also PYTHONDONTWRITEBYTECODE=x
 -c cmd : program passed in as string (terminates option list)
 -d : debug output from parser; also PYTHONDEBUG=x
 -E : ignore PYTHON* environment variables (such as PYTHONPATH)
 -h : print this help message and exit (also --help)
 -i : inspect interactively after running script; forces a prompt even
 if stdin does not appear to be a terminal; also PYTHONINSPECT=x
 -m mod : run library module as a script (terminates option list)
 -O : optimize generated bytecode slightly; also PYTHONOPTIMIZE=x
 -OO : remove doc-strings in addition to the -O optimizations
 -R : use a pseudo-random salt to make hash() values of various types be
 unpredictable between separate invocations of the interpreter, as
 a defense against denial-of-service attacks
 -Q arg : division options: -Qold (default), -Qwarn, -Qwarnall, -Qnew
 -s : don't add user site directory to sys.path; also PYTHONNOUSERSITE
 -S : don't imply 'import site' on initialization
 -t : issue warnings about inconsistent tab usage (-tt: issue errors)
 -u : unbuffered binary stdout and stderr; also PYTHONUNBUFFERED=x
 see man page for details on internal buffering relating to '-u'
 -v : verbose (trace import statements); also PYTHONVERBOSE=x
 can be supplied multiple times to increase verbosity
 -V : print the Python version number and exit (also --version)
 -W arg : warning control; arg is action:message:category:module:lineno
 also PYTHONWARNINGS=arg
 -x : skip first line of source, allowing use of non-Unix forms of #!cmd
 -3 : warn about Python 3.x incompatibilities that 2to3 cannot trivially fix
 file : program read from script file
 - : program read from stdin (default; interactive mode if a tty)
 arg ...: arguments passed to program in sys.argv[1:]

Other environment variables:
 PYTHONSTARTUP: file executed on interactive startup (no default)
 PYTHONPATH : ':'-separated list of directories prefixed to the
 default module search path. The result is sys.path.
 PYTHONHOME : alternate <prefix> directory (or <prefix>:<exec_prefix>).
 The default module search path uses <prefix>/pythonX.X.
 PYTHONCASEOK : ignore case in 'import' statements (Windows).
 PYTHONIOENCODING: Encoding[:errors] used for stdin/stdout/stderr.
 PYTHONHASHSEED: if this variable is set to 'random', the effect is the same
 as specifying the -R option: a random value is used to seed the hashes of
 str, bytes and datetime objects. It can also be set to an integer
 in the range [0,4294967295] to get hash values with a predictable seed.
 eSumit@Sumits-MacBook-Pro:~/Documents/PythonDoctor$

How to Install PIP on Macbook Pro 

eSumit@Sumits-MacBook-Pro:~/Documents/ZimpJanDev2018$ sudo easy_install pip
 Password:
 Sorry, try again.
 Password:
 Searching for pip
 Reading https://pypi.python.org/simple/pip/
 Best match: pip 9.0.1
 Downloading https://pypi.python.org/packages/11/b6/abcb525026a4be042b486df43905d6893fb04f05aac21c32c638e939e447/pip-9.0.1.tar.gz#md5=35f01da33009719497f01a4ba69d63c9
 Processing pip-9.0.1.tar.gz
 Writing /tmp/easy_install-f21EGa/pip-9.0.1/setup.cfg
 Running pip-9.0.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-f21EGa/pip-9.0.1/egg-dist-tmp-PVkBiI
 /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'python_requires'
 warnings.warn(msg)
 warning: no previously-included files found matching '.coveragerc'
 warning: no previously-included files found matching '.mailmap'
 warning: no previously-included files found matching '.travis.yml'
 warning: no previously-included files found matching '.landscape.yml'
 warning: no previously-included files found matching 'pip/_vendor/Makefile'
 warning: no previously-included files found matching 'tox.ini'
 warning: no previously-included files found matching 'dev-requirements.txt'
 warning: no previously-included files found matching 'appveyor.yml'
 no previously-included directories found matching '.github'
 no previously-included directories found matching '.travis'
 no previously-included directories found matching 'docs/_build'
 no previously-included directories found matching 'contrib'
 no previously-included directories found matching 'tasks'
 no previously-included directories found matching 'tests'
 creating /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
 Extracting pip-9.0.1-py2.7.egg to /Library/Python/2.7/site-packages
 Adding pip 9.0.1 to easy-install.pth file
 Installing pip script to /usr/local/bin
 Installing pip2.7 script to /usr/local/bin
 Installing pip2 script to /usr/local/bin

Installed /Library/Python/2.7/site-packages/pip-9.0.1-py2.7.egg
 Processing dependencies for pip
 Finished processing dependencies for pip
 eSumit@Sumits-MacBook-Pro:~/Documents/ZimpJanDev2018$

 

Reference :

Virtualenv with Virtualenvwrapper on Ubuntu

http://roundhere.net/journal/virtualenv-ubuntu-12-10/

Failed to initialize virtualenvwrapper. #17

https://github.com/pyenv/pyenv-virtualenvwrapper/issues/17

Where is virtualenvwrapper.sh after pip install?

https://stackoverflow.com/questions/12647266/where-is-virtualenvwrapper-sh-after-pip-install

Only this worked for me on Macbook Pro : sudo easy_install virtualenvwrapper

 

Installing Django on MacBook Pro

Command “python setup.py egg_info” failed with error code 1 in /private/tmp/pip-build-CypAKk/Django/

Reference : https://github.com/facebook/prophet/issues/140

Command “python setup.py egg_info” failed with error code 1 in /private/tmp/pip-build-CypAKk/Django/

eSumit@Sumits-MacBook-Pro:~$ pip install Django
The directory ‘/Users/eSumit/Library/Caches/pip/http’ or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
The directory ‘/Users/eSumit/Library/Caches/pip’ or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo’s -H flag.
Collecting Django
Downloading Django-2.0.tar.gz (8.0MB)
100% |████████████████████████████████| 8.0MB 141kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File “<string>”, line 1, in <module>
File “/private/var/folders/kr/bq8kqm_54l13knm864fxk78m0000gn/T/pip-build-V83QwL/Django/setup.py”, line 32, in
version = __import__(‘django’).get_version()
File “django/__init__.py”, line 1, in <module>
from django.utils.version import get_version
File “django/utils/version.py”, line 61, in <module>
@functools.lru_cache()
AttributeError: ‘module’ object has no attribute ‘lru_cache’

—————————————-
Command “python setup.py egg_info” failed with error code 1 in /private/var/folders/kr/bq8kqm_54l13knm864fxk78m0000gn/T/pip-build-V83QwL/Django/
eSumit@Sumits-MacBook-Pro:~$

 

eSumit@Sumits-MacBook-Pro:~$ sudo pip install mysqlclient
Password:
Collecting mysqlclient
Downloading mysqlclient-1.3.12.tar.gz (89kB)
100% |████████████████████████████████| 92kB 122kB/s
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient … done
Successfully installed mysqlclient-1.3.12
eSumit@Sumits-MacBook-Pro:~$

 

eSumit@Sumits-MacBook-Pro:~$ sudo pip install pystan
Collecting pystan
Downloading pystan-2.17.0.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (35.2MB)
100% |████████████████████████████████| 35.2MB 33kB/s
Collecting Cython!=0.25.1,>=0.22 (from pystan)
Downloading Cython-0.27.3-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.6MB)
100% |████████████████████████████████| 4.6MB 230kB/s
Requirement already satisfied: numpy>=1.7 in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from pystan)
Installing collected packages: Cython, pystan
Successfully installed Cython-0.27.3 pystan-2.17.0.0
eSumit@Sumits-MacBook-Pro:~$

 

Final Solution for Django Installation 

Reference : https://www.djangoproject.com/download/

eSumit@Sumits-MacBook-Pro:~$ sudo -H pip install Django==1.11
Collecting Django==1.11
 Downloading Django-1.11-py2.py3-none-any.whl (6.9MB)
 100% |████████████████████████████████| 6.9MB 161kB/s 
Requirement already satisfied: pytz in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from Django==1.11)
Installing collected packages: Django
Successfully installed Django-1.11
eSumit@Sumits-MacBook-Pro:~$

If installing on virtual environment, then install on that virtual environment.

Check if Django Installed :

eSumit@Sumits-MacBook-Pro:~/Documents/ZimpJanDev2018/zBackend$ python -c “from distutils.sysconfig import get_python_lib; print get_python_lib()”
/Users/eSumit/.virtualenvs/zBackend/lib/python2.7/site-packages
eSumit@Sumits-MacBook-Pro:~/Documents/ZimpJanDev2018/zBackend$

Reference : https://stackoverflow.com/questions/14013728/django-no-module-named-django-core-management

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s