How to upgrade to python 3.6.4 on macos? - python

I'm trying to use python 3.6.4:
n155-p250:Desktop sahandzarrinkoub$ brew upgrade python3
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
bash-preexec jenkins presto ttf2eot
cppcheck khard qpdf txr
docker-gen lz4 scummvm unixodbc
duplicity mdp scummvm-tools verilator
get-flash-videos mycli sslsplit
get_iplayer ola tin
gobuster ponyc tokei
Error: python3 3.6.4_2 already installed
n155-p250:Desktop sahandzarrinkoub$ python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Even though I already have it installed, I can't use it by typing python3. How do I solve this? I want to remove 3.6.2 and have python3 map to 3.6.4.

As your python3 is not linked to homebrew one, you should let homebrew force relink python3:
rm /usr/local/bin/python3
brew unlink python3; brew link --overwrite python3
link of python3 on my machine is:
/usr/local/bin/python3 -> ../Cellar/python3/3.6.4/bin/python3

To update python run brew update in the Terminal (this will update Homebrew)
Then brew upgrade python3
At the end you can run brew cleanup python3 to remove the older version

Related

Can't Import Django using Python3 on macOS Sierra

Have both versions of Python (Legacy 2.7.10 and 3.6.2) installed on macOS Sierra.
Installed pip using the following steps.
Downloaded it using curl:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Installed pip it by running the installer script:
sudo python get-pip.py
Checked for any upgrades / updates for pip:
sudo pip install -U pip
Installed django 1.11:
sudo pip install django==1.11
When I run python (legacy):
python
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print(django.get_version())
1.11
However, when trying it using python3:
python3
Python 3.6.2 (v3.6.2:5fd33b5926, Jul 16 2017, 20:11:06)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'django'
Note: I followed a different tutorial and got python3 working with django 1.11 using virtualenv - please don't suggest this as I am new to the python world and just want to use python3 / django 1.11 in a non-virtual environment - I just want have it working like the legacy python interpreter is behaving.
pip installs libraries differently for python2 and python3, so you effectively have different environments for each. If you want to install Django for python3, you'll want to install it like this:
pip3 install django==1.11

Python3, lxml and "Symbol not found: _lzma_auto_decoder" on Mac OS X 10.9

I have installed python 3 using homebrew and afterwards installed pip3 and lxml.
The following line
from lxml import entree
leads to the following error:
$ python3
Python 3.3.5 (v3.3.5:62cf4e77f785, Mar 9 2014, 01:12:57)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site- packages/lxml/etree.so, 2): Symbol not found: _lzma_auto_decoder
Referenced from: /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/lxml/etree.so
Expected in: flat namespace
in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/lxml/etree.so
>>> exit();
Does anybody know how to fix this?
I have deleted all versions of python from
/Library/Frameworks/Python.framework/Versions/
afterwards I have reinstalled python 3 using brew and recreated the symlinks using
brew link --overwrite python3
Deleting lxml and re-installing lxml a SECOND time worked for me (weird, not happy with this solution):
pip3.4 uninstall lxml
pip3.4 install lxml
pip3 complains about lxml being already installed, remove manually the install files with a command like:
rm -fr /private/var/folders/dj/saljfdsf12_sd7s89dfg9080000rb/T/pip_build_user/lxml
Then again:
pip3.4 install lxml
And it worked. I couldn't reproduce the original error message to find root cause of this problem.
If you use Homebrew and have xz installed, the following should work:
STATIC_DEPS=true CFLAGS=-I/usr/local/include/lzma pip install -U lxml
Otherwise set CFLAGS to the place where your lzma headers are located.
I had this same issue,
What I did:
First, I ensured I did not have the ports py27-xml2, py27-xslt or py27-lxml installed
sudo port installed | grep py27
I installed port py27-pip and checked that $PATH variable pointed it. Also installed py27-setuptools.
$ sudo port contents py27-pip | grep /pip$
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
in ~/.bash_profile:
export PATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
$ which pip
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin/pip
Then I installed lxml with easy_install which was located in the same directory than pip
STATIC_DEPS=true sudo easy_install-2.7 lxml
The building process was displaying:
$ STATIC_DEPS=true sudo easy_install-2.7 lxml
Searching for lxml
Reading https://pypi.python.org/simple/lxml/
Downloading
....
Building without Cython.
Using build configuration of libxslt 1.1.29
Building against libxml2/libxslt in the following directory: /Applications/MAMP/Library/
....
libxml/xmlversion.h: No such file or directory
I moved MAMP (seems to already come with those libs) at the end of $PATH, uninstalled lxml (displayed "Symbol not found: _lzma_auto_decoder" error) and repeated last command:
$ STATIC_DEPS=true sudo easy_install-2.7 -m "lxml==3.6.4"
in ~/.bash_profile:
export PATH="/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}:/Applications/MAMP/Library/bin:/Applications/MAMP/Library"
$ source ~/.bash_profile
$ STATIC_DEPS=true sudo easy_install-2.7 lxml
This fixed the error either inside or outside virtualenv
$ python
Python 2.7.12 (default, Jun 29 2016, 12:46:54)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from lxml import etree
>>>

Upgrading devel version of statsmodels

I've got statsmodels 0.5.0 and I want to upgrade to the latest version which is 0.6.0.
So I do
$ git clone git://github.com/statsmodels/statsmodels.git
$ cd statsmodels
$ pip install .
But, I get an error:
error: can't copy 'statsmodels/nonparametric/_smoothers_lowess.c': doesn't exist or not a regular file
Apparently the solution is to install Cython (which I thought was already installed, or how could statsmodels 0.5.0 ever have worked in the first place..?!?).
Anyway, so it becomes:
$ git clone git://github.com/statsmodels/statsmodels.git
$ cd statsmodels
$ pip install cython
$ pip install .
$ python
Python 2.7.3 |CUSTOM| (default, Apr 11 2012, 17:52:16)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import statsmodels
>>> statsmodels.version.full_version
'0.6.0.dev-b472807'

Can not import wxPython (Mac)

I thought I'd move from using Tkinter to wxPython, but I'm having some troubles. All I get is this:
>>> import wx
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named wx
I have installed wxPython. When I run the uninstaller I clearly see that wxPython IS installed:
1. wxPython3.0-osx-cocoa-py2.7 3.0.0.0
Enter the number of the install to examine or 'Q' to quit:
When I start Python I see that my version should match the version of wxPython:
Python 2.7.1 (r271:86832, Jul 31 2011, 19:30:53)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
I'm on OS X 10.7.5 32-bit.
Any help would be awesome! :)
Macs can have multiple versions of Python installed. Are you sure that you installed wxPython for the same python you invoke with the interpreter?
Try, which python, and make sure that this version of python has a wxredirect.pth file in site-packages pointing to the wxPython installation. (If it doesn't search for wxredirect.pth.)
Here's one version on my system...
> which python2.6
/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
> more /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/wxredirect.pth
import site; site.addsitedir('/usr/local/lib/wxPython-3.0.0.0/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-2.9.1.1/lib/python2.6')
#import site; site.addsitedir('/usr/local/lib/wxPython-unicode-2.8.12.1/lib/python2.6')
Here, btw, I can comment out lines in the wxredirect.pth to choose the version of wxPython I want to use.
I just find the same problem.
I used brew install wxpython to install it on mac.
I try the method above but no use.
I happen to find the solution when I install another package, it showen below:
brew install tbb
Downloading https://homebrew.bintray.com/bottles/tbb-2017_U7.sierra.bottle.t
############################################################ 100.0%
==> Pouring tbb-2017_U7.sierra.bottle.tar.gz
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/ningrongye/.local/lib/python2.7/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-
packages")' >> /Users/ningrongye/.local/lib/python2.7/site-
packages/homebrew.pth`
this is what homebrew said and I just try those, and it works.
ningrong
I have Python 2.7 and 3.7 .
In /usr/local/bin/ there are symbolic links for 2.7 and 3.7 Python versions and also symbolic links for pip.
I've installed wxPython with pip3
pip3 install -U wxPython
Then i checked the installation for Python3
myname$ python3
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> wx.version()
'4.0.4 osx-cocoa (phoenix) wxWidgets 3.0.5'
Antonio
In my case it worked by resetting the brew environment to 2.7:
brew link --overwrite python#2

How to install a module for python 2.6 on CentOS?

After I install python 2.6 on CentOS by:
wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
sudo rpm -ivh epel-release-5-4.noarch.rpm
yum install python26
Then I install pyPdf by:
yum install pyPdf
However, the pyPdf is only available to the old python 2.4:
# python
Python 2.4.3 (#1, Jan 9 2013, 06:49:54)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyPdf
>>> import sys
>>> print sys.path
['', '/usr/lib/python24.zip', '/usr/lib/python2.4', '/usr/lib/python2.4/plat-linux2', '/usr/lib/python2.4/lib-tk', '/usr/lib/python2.4/lib-dynload', '/usr/lib/python2.4/site-packages', '/usr/lib/python2.4/site-packages/Numeric', '/usr/lib/python2.4/site-packages/gtk-2.0']
it's not available to the newly install python 2.6:
# python26
Python 2.6.8 (unknown, Nov 7 2012, 14:47:34)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print sys.path
['', '/usr/lib/python26.zip', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/site-packages']
>>> import pyPdf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pyPdf
How can I install pyPdf for python 2.6?
How about creating a virtualenv and install pyPdf with pip
$ curl -O https://pypi.python.org/packages/source/v/virtualenv/virtualenv-X.X.tar.gz
$ tar xvfz virtualenv-X.X.tar.gz
$ cd virtualenv-X.X
$ python26 virtualenv.py myVirtualenv
$ source myVirtualenv/bin/activate
$ pip install pyPdf
Read more about virtualenv here
Not sure how you're doing it. I have recently installed pyPdf on CentOS for Python 2.7. A simple yum worked for me.
yum install pyPdf
pyPdf is also available for newer versions. Check here
Edit:
May be having two different versions of Python is causing this issue
for you. CentOS comes with default installation of v2.4. Remove all
the previous versions and install again.
For CentOS version lower than 6, python 2.4 comes by default. For version 6 and above its python2.6 .
Now I would strictly advise not to upgrade the base Python installation i.e python2.4 in the earlier versions, as that would break lot of system level funcationalities that expect default python to be 2.4.
Your question can be solved in multiple ways :
yum install always does an installation for default python. If its 2.4 it will install the package for 2.4.
To install package for 2.6, download easy_install for 2.6 or PIP for 2.6 and then simply do easy_install {{package_name}} or pip install {{package_name}}
To keep your environments different, as suggested by #Dikei install a virtual-env and then install your packages. This is method is one of the best practices for maintaining multiple python environments.
Quick installation of Python !!!
Get the latest verion of Python 2.6.9
wget https://www.python.org/ftp/python/2.6.9/Python-2.6.9.tar.xz
Extract thae package
tar xf Python-2.6.9.tar.xz
Configure them
cd Python-2.6.9
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
Install them
make && make altinstall
Check Version:
python --version
Python 2.6.9
Credits:https://danieleriksson.net
Hope this helps !!!

Categories