How to install python on Mac with wide-build - python

I found that Python on my Mac build with narrow-build which will raise character range error when i use the re model.
So I want to install the wide-build in my Mac.So how can I install Python with wide-build on Mac?

If you really need a "wide build" of Python 2 on OS X to support Unicode code points above 0xffff, you'll probably have to build it yourself from source. Most distributions for OS X that I am aware of use the default "narrow build"; one exception is MacPorts which does support a wide-build variant:
sudo port install python27 +ucs4
To build Python yourself from source, download and unpack the latest Python source tarball and set appropriate configure arguments for your situation. The key one is --enable-unicode=ucs4. For example, a minimal configuration might be:
curl -O https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz
tar xf ./Python-2.7.8.tgz
cd ./Python-2.7.8
./configure --enable-unicode=ucs4 --prefix=/path/to/install MACOSX_DEPLOYMENT_TARGET=10.9
make
make install
cd
/path/to/install/bin/python2.7
Python 2.7.8 (default, Aug 3 2014, 22:27:28)
[GCC 4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.40)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.maxunicode
1114111
As noted by Jason, current Python 3 releases always support all Unicode characters.

If using Python3 upgrade to the latest version. In 3.3 and later:
The distinction between narrow and wide Unicode builds is dropped.
http://legacy.python.org/dev/peps/pep-0393/

Related

default python won't switch to homebew installation

I know this question has been asked - but none of the solutions there seem to be working. I recently found out that on Mac OS, the native installation of python isn't very good. So, I installed homebrew, and installed Python 2 through there. My path is as follows:
~ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin
However, I still get the following:
~ which python
/usr/bin/python
~ which python2
/usr/local/bin/python2
It's also probably important to note that my ~/.bash_profile, ~/.profile and ~/.zshrc files are empty.
Somehow, I think I got pip to work with the python2 (homebrew) installation. Basically, I did pip install pandas and I get the following outputs for the two python interpreters:
~ 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 pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
That is, it doesn't appear with the default python installation. However, I also have the following:
~ python2
Python 2.7.14 (default, Sep 25 2017, 09:53:22)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>>
So, pandas is imported in the python2 (homebrew) python, but not the standard one. How can I get it so that the default python is my homebrew python? I also read somewhere that brew link python would work, but when I do that I get
~ brew link python
Warning: Already linked: /usr/local/Cellar/python/2.7.14
To relink: brew unlink python && brew link python
I want to be able to just use python my_file.py and have it use the homebrew installation. (Not sure if it's related, but hopefully this would also allow Sublime to use the homebrew install when I hit command + B).
Sorry for the long post, new computer and I'm trying to get this all correct before I do any big projects and find out halfway through that things aren't working the way I need them to.
Thanks!
The macOS system Python is installed at /usr/bin/python. This is the only one called python on your path.
Homebrew doesn't create a link for python in /usr/local/bin. If you want one you can create it yourself:
ln -s /usr/local/bin/python2 /usr/local/bin/python
Alternatively, just update your shebang lines to specify python2 or python3, which is probably better anyway (explicit is better than implicit).

Is it possible to use ipython based on a builtin python

I am using paraview 4.3.1 in Centos 7. There is a built-in python named pvpython:
Python 2.7.2 (default, Jan 15 2015, 09:36:49)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys;sys.path
['', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/site-packages/vtk', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/site-packages', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python27.zip', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/plat-linux2', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/lib-tk', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/lib-old', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/lib-dynload', '/tmp/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3/lib/python2.7/site-packages']
>>>
The problem is, original pvpython do not support many useful features such as code completion. And there is no setup_tools in the pvpython, so I cannot install new modules to the built-in python.
Could anyone help me to install ipython on this built-in python?
See the install instructions for get-pip:
https://pip.pypa.io/en/latest/installing.html
However, you must use the pvpython instead of python when using the install instructions.
Depending on how you install it, you may end up with more than one easy_install or pip on your path. Just make sure you're using the one associated with pvpython - look at the script you're running to find out (it's just a shell script).
Once you've done that, installing ipython should be the same as installing it with any other version of python (assuming that pvpython doesn't break anything that ipython needs).

Using twisted on OS X Mavericks

I am trying to use twisted on OS X Mavericks, but I get this error message when I try to import it.
christohersmbp2:~ christopherspears$ python
Python 2.7.6 (default, Mar 8 2014, 09:29:01)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twisted
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named twisted
My guess is that I am receiving this error because I am not using the default Python. I am using a Python installed with brew. Ideally, I would want to install twisted into a virtual environment to play with, but the docs are seriously lacking in details. Apparently, a dmg exists for Mac OS X 10.5, which is not helpful for me. I can install from the tarball into the virtual environment, but I am not sure how to do this. Any hints?
If you're using virtualenv, it doesn't matter whether you are using the system python or not.
Simply pip install twisted in your virtualenv, like:
$ workon MyTwistedEnv
$ pip install twisted
Currently, due to a bug in Xcode that affects all projects which contain extension modules, you may need to spell this
$ CFLAGS= pip install twisted
instead; hopefully this will be fixed soon. It may not affect brew installed Pythons, however.

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

python location on mac osx

I'm a little confused with the python on osx. I do not know if the previous owner of the laptop has installed macpython using macport. And I remembered that osx has an builtin version of python. I tried using type -a python and the result returned
python is /usr/bin/python
python is /usr/local/bin/python
However running both python at these locations give me [GCC 4.2.1 (Apple Inc. build 5646)] on darwin. Do they both refer to the same builtin python mac provided?
I also read that installing macpython one would
A MacPython 2.5 folder in your Applications folder. In here you
find IDLE, the development environment that is a standard part of
official Python distributions...
I looked at Applications, and theres a MacPort folder with python2.6 and the mentioned stuff in it. But running IDLE, i find the same message as above.
Hmm I'm a little confused. Which is which?
This one will solve all your problems not only on Mac but
to find it on Linux also ( & every basic shell).
TL;DR (you don't have to go through all the answer - just the 1st half).
LET'S GO
Run in terminal:
which python3
On Mac you should get:
/usr/local/bin/python3
WAIT!!! It's prob a symbolic link, how do you know? Run:
ls -al /usr/local/bin/python3
and you'll get (if you've installed Python w/ Brew):
/usr/local/bin/python3 -> /usr/local/Cellar/python/3.6.4_4/bin/python3
which means that your
/usr/local/bin/python3
is actually pointing to (the real location)
/usr/local/Cellar/python/3.6.4_4/bin/python3
That's it!
Longer version (optional):
If for some reason, your
/usr/local/bin/python3
is not pointing to the place you want, which in our case:
/usr/local/Cellar/python/3.6.4_4/bin/python3
just back it up (+cool trick to add .orig suffix to file):
cp /usr/local/bin/python3{,.orig}
and run:
rm -rf /usr/local/bin/python3
now create a new symbolic link:
ln -s /usr/local/Cellar/python/3.6.4_4/bin/python3 /usr/local/bin/python3
and now your
/usr/local/bin/python3
is pointing to
/usr/local/Cellar/python/3.6.4_4/bin/python3
Check it out by running:
ls -al /usr/local/bin/python3
I found the easiest way to locate it, you can use
which python
it will show something like this:
/usr/bin/python
[GCC 4.2.1 (Apple Inc. build 5646)] is the version of GCC that the Python(s) were built with, not the version of Python itself. That information should be on the previous line. For example:
# Apple-supplied Python 2.6 in OS X 10.6
$ /usr/bin/python
Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
# python.org Python 2.7.2 (also built with newer gcc)
$ /usr/local/bin/python
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Items in /usr/bin should always be or link to files supplied by Apple in OS X, unless someone has been ill-advisedly changing things there. To see exactly where the /usr/local/bin/python is linked to:
$ ls -l /usr/local/bin/python
lrwxr-xr-x 1 root wheel 68 Jul 5 10:05 /usr/local/bin/python# -> ../../../Library/Frameworks/Python.framework/Versions/2.7/bin/python
In this case, that is typical for a python.org installed Python instance or it could be one built from source.
On Mac OS X, it's in the Python framework in /System/Library/Frameworks/Python.framework/Resources.
Full path is:
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Btw it's easy to find out where you can find a specific binary: which Python will show you the path of your Python binary (which is probably the same as I posted above).
I checked a few similar discussions and found out the best way to locate all python2/python3 builds is:
which -a python python3
On High Sierra
which python
shows the default python but if you downloaded and installed the latest version from python.org you can find it by:
which python3.6
which on my machine shows
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
installed with 'brew install python3', found it here
Run this in your interactive terminal
import os
os.path
It will give you the folder where python is installed
i found it here:
/Library/Frameworks/Python.framework/Versions/3.6/bin
which python3 simply result in a path in which the interpreter settles down.
run the following code in a .py file:
import sys
print(sys.version)
print(sys.executable)
I have a cook recipe for finding things in linux/macos
First update the locate db then do a
locate WHATiWANTtoSEARCH | less
do a /find to find what you are looking for.
to update your locate db in macos do this:
sudo /usr/libexec/locate.updatedb
it sometimes takes a while. Hope this helps :)

Categories