I am installing modules with homebrew and other installers, and they are not recognized by my default python. Module installations with easy_install (such as pip) appear to be available for my system and system python).
My default python is located here and is this version:
15:49 [~]: which python
/usr/local/bin/python
15:49 [~]: python -d
Python 2.7.2 (default, Mar 18 2012, 15:13:08)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin Type "help",
"copyright", "credits" or "license" for more information.
The packages do appear to be located in /library/frameworks/, GEOS.framework is one example.
What do I need to modify to gain access to my modules?
System: Mac os x 10.5.8
From the Homebrew page: "Homebrew installs packages into their own isolated prefix and then symlinks everything into /usr/local"
I think that the OS X preinstalled python looks for modules in
/Library/Frameworks/Python.framework/Versions/Current//lib/python2.7/site-packages
So maybe you need to symlink your Homebrew installed packages to there.
Related
I am trying to make a Python script on my Mac (MacOS 10.14.6 Mojave) and I am getting trouble with installing a module (watchdog). I have the built-in Python 2 and I installed Python 3 with Homebrew.
If a type in the terminal python, I get:
Python 2.7.16 (default, Oct 16 2019, 00:34:56)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
So Python 2 correctly uses GCC (the one provided by Apple? I am not sure) instead of Clang. Now, if I do python -m pip install watchdog it just works. But I want to install the module on Python 3, that for some reason uses Clang instead of GCC. In fact, if I type `python3', I get:
Python 3.8.0 (v3.8.0:fa919fdf25, Oct 14 2019, 10:23:27)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
I assume that as a consequence python3 -m pip install watchdog gives a compile error because Python 3 is not using GCC. The error message is very long and can be found here: https://pastebin.com/DEAKANQ9
In my $PATH I have /usr/local/bin (where gcc is installed) before /usr/bin, i.e.
echo $PATH
/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
I would say everything is set up correctly, but apparently that is not the case. How can I make Python 3 use GCC instead of Clang?
I have fixed the issue.
First, I have removed Python 3.8 which was installed using the pkg installer (by accident actually). Then, I have created an alias for Python 3 in the .bash_profile. Another mistake was that I created the file ~/.bashrc (as in Ubuntu) instead of editing the file ~/.bash_profile to modify the $PATH.
# ~/.bash_profile
#
# Python alias
alias python=/usr/local/bin/python3
# Setting PATH for Python 3.7.5 (Homebrew)
PATH="/usr/local/bin:${PATH}"
export PATH
# Set module path
PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.7/site-packages
# Set PATH priority to Homebrew installation folder
export PATH=/usr/local/bin:/usr/local/sbin:$PATH
With this settings, I was able to install the module and make it work in my script!
OSX. When I installed the Canopy IDE, Enthought Canopy Python 2.7.6 was set as the default Python for the bash shell:
$ python
Enthought Canopy Python 2.7.6 | 32-bit | (default, Sep 15 2014, 17:36:57)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Currently, I am using another IDE (PyCharm) for a project where a Python module is needed. I tried to download the module directly from the bash shell using pip but it did not work:
pip install psycopg2 <---module
I believe it has something to do with Enthought Canopy Python running, so I attempted to restore the original python. However, I could not restore it. The instructions from this Enthought post (2011) did not work:
OS X - After EPD installation, restore system python to be default
They say to comment out the following lines from the ~/.bash_profile file, save the changes and restart the bash shell:
# PATH="/Library/Frameworks/Python.framework/Versions/Current/bin:${PATH}"
# export PATH
Didn't work.
I've installed python27 on my MacBook Pro (OS X 10.6.8) using Macports. Here is the output for sudo port select --list python:
Available versions for python:
none
python25-apple
python26-apple
python27 (active)
But when I type the python command, it's running python26:
rod:~ $python
Python 2.6.6 (r266:84292, Feb 11 2012, 09:09:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
I've tried uninstalling my Macports pythons (I used to have the python31 and python25 macports as well) and reinstalling, but to no avail.
I should note that I recently had to do a time machine restore due to a hard drive failure, and I've been finding that some of the soft links seem not to have restored properly. I wonder if this could be a source of my problems here. Any tips?
Does your .profile still have the /opt/local paths prepended to $PATH? If its not present then despite being selected you wont get it by default because it symlinks the version to /opt/local/bin/python
I download python 3.2 and my first thought was that I need to uninstall the python 2.6.1 pre-installed in my computer. But later I found in python.org "You should never modify or delete these, as they are Apple-controlled and are used by Apple- or third-party software". I used "sudo rm -rf /Library/Frameworks/Python.Framework" to delete python 2.6.1. Now I truly want to undo this command(I want python 2.6.1 back!). What should I do?
(or the question can be expressed as follows: how can I re-install the pre-installed python 2.6.1 in my mac?)
Don't worry, that command will not remove it. The Apple-supplied Python in Mac OS X 10.6 is located at /System/Library/Frameworks/Python.framework.
$ ls -l /usr/bin/python2.6
lrwxr-xr-x 1 root wheel 75 Nov 7 23:52 /usr/bin/python2.6# -> ../../System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
Anything in /Library/Frameworks/Python.framework was not put there by Apple, rather most likely by a python.org Python installer. The way to be sure is type:
$ /usr/bin/python2.6
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.
>>>
That's the signature of the current Apple-supplied Python 2.6 in Mac OS X 10.6.
In general, do not modify or delete files in /System/Library or in /usr other than /usr/local. Files in /Library are under your control.
Reinstalling would work. In the future, don't delete Frameworks you didn't install.
Hi there I have downloaded the mac installer here, http://www.python.org/download/releases/3.1.2/ , & installed it. But when I run terminal & type python it says:
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
What I want to know is, is it safe to run Update Shell Profile.command in the Python 3.1 folder ? or should I run python 3.1.2 separately ? If I should run python 3.1.2 separately, how do I do so ? also how do I start IDLE ?
Is there another python executable, perhaps python31?
You can also install other python versions via MacPorts if you need (although you'll still have to choose the right executable).
This should also be relevant: Multiple versions of Python on OS X Leopard