I am experiencing difficulty with installing Python correctly on my Mac (Fresh Install, I wiped my PC clean). I installed firstly
Home Brew
Xcode through App Store
Command line tools using command: "xcode-select --install"
On typing the following command:
which python3
Output is as follows:
gaurangsmacbookpro#Gaurangs-New-MacBook-Pro ~ % which python
/usr/bin/python
gaurangsmacbookpro#Gaurangs-New-MacBook-Pro ~ % which python3
/usr/bin/python3
upon running the following command which I was following off a blog from this site:
https://www.pyimagesearch.com/2016/12/05/macos-install-opencv-3-and-python-3-5/
brew install eigen tbb
Home brew installed python 3.9 dependencies so no when I type the following commands:
brew list python3
I get the following output:
gaurangsmacbookpro#Gaurangs-New-MacBook-Pro ~ % brew list python3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/2to3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/2to3-3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/easy_install-3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/idle3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/idle3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/pip3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/pip3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/pydoc3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/pydoc3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/python3
/usr/local/Cellar/python#3.9/3.9.1_8/bin/python3-config
/usr/local/Cellar/python#3.9/3.9.1_8/bin/python3.9
/usr/local/Cellar/python#3.9/3.9.1_8/bin/python3.9-config
/usr/local/Cellar/python#3.9/3.9.1_8/bin/wheel3
/usr/local/Cellar/python#3.9/3.9.1_8/Frameworks/Python.framework/ (3019 files)
/usr/local/Cellar/python#3.9/3.9.1_8/IDLE 3.app/Contents/ (8 files)
/usr/local/Cellar/python#3.9/3.9.1_8/lib/pkgconfig/ (4 files)
/usr/local/Cellar/python#3.9/3.9.1_8/libexec/bin/ (7 files)
/usr/local/Cellar/python#3.9/3.9.1_8/libexec/pip/ (480 files)
/usr/local/Cellar/python#3.9/3.9.1_8/libexec/setuptools/ (334 files)
/usr/local/Cellar/python#3.9/3.9.1_8/libexec/wheel/ (44 files)
/usr/local/Cellar/python#3.9/3.9.1_8/Python Launcher 3.app/Contents/ (16 files)
/usr/local/Cellar/python#3.9/3.9.1_8/share/man/ (2 files)
The contents of my ~./bash_profile file are as follows:
# Add Homebrew's executable directory to the front of the PATH
export PATH=/usr/local/bin:$PATH
export PATH="/usr/local/sbin:$PATH"
export PATH="/usr/local/opt/python#3.8/bin:$PATH"
What am I doing wrong? I just want a fresh clean install of Python 3.8 not 3.9 as there is no support for TF Lite on 3.9 yet. Can someone help me fix this mess? I will be very grateful!
I'm a bit late at the game, but I hope this will be useful to somebody. The best solution here is to use a virtual environment, but for the sake of argument and because it is a little bit more involved, I won't discuss that as an option here and will assume you just want a specific version installed on your machine where you can just add all the dependencies you need.
From looking at the page OP was using, the easiest solution here is probably to use a distribution like Anaconda if you are particularly interested in OpenCV or that type of libraries. Then it's just a case of setting up your path like export PATH=$HOME/anaconda/bin:$PATH or whatever path you used to install Anaconda with your shell of choice.
But let's imagine that Anaconda doesn't help you and you still need a specific version of Python, and you figure 3.8.2 is good enough for your needs and a newer version wouldn't work. Using the Python version that comes with the Xcode command line tools is probably a bad idea, just like using the system installed Python is. That version is really meant to support the Apple toolchain and while I've never run into any issues with it, I would not recommend it.
Next option is is to use homebrew. Great option since most people will already be using it, and you might already have python installed as part of a dependency but maybe like OP it's not the version you were hoping for. You can still make it work by installing an older version like so brew install python#3.8 however, it comes with a few caveats. Whenever one of the python dependencies is updated, you might need to unlink and relink it so that you can continue to use the correct version. Believe me, it's no way to live.
What I've found works (in combination with virtual environments is to use pyenv. Install it through homebrew, set your shell as described in the install doc and use it to install the python version you want (very easy) and then set the global interpreter to be whatever version you want and your system will stick to it until you set it to something else. It also works great in combination with tools like pipenv which allow you to manage virtual environments.
Related
Background
Currently, I have Python 2.7.17 and Python 3.8.1 installed on my Mac (v 10.14.6). Both Python versions were downloaded directly from Python.org using a "macOS 64-bit installer" .pkg file, in late 2019. Both were installed here:
python2: /Library/Frameworks/Python.framework/Versions/2.7/bin/python2
python3: /Library/Frameworks/Python.framework/Versions/3.8/bin/python3
Currently, I use only pip (either pip2 or pip3, depending) to install python packages, which are saved here:
python2: /Library/Frameworks/Python.framework/Versions/X.X/lib/python2.7/site-packages
python3: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages
I am about to begin an online course which requires that I install miniconda in order to install the packages that I need for the course. But after having a very bad experience having Anaconda installed on my machine years ago, and it taking me months to remove it and re-create a clean Python install, I am nervous. I don't want my machine to become a mess again, rife with error messages that it can't find this or that python version or this or that python library.
Question(s)
Assuming there will now be multiple installations of Python on my machine (in addition to the versions that I already have, since I believe yet another version of python is installed along with conda), and there will be new places where python packages will be saved, what can I expect to change about how I write python after I install miniconda?
Is there anything I will need to do differently from what I am doing now when I write python code?
How can I ensure that everything remains working and compatible and I avoid the fate I suffered many years ago?
Happy to edit/clarify this question per user suggestions. Thanks!
Use conda environments and install Python into those environments. This ignores, by design, the versions of Python that are installed at the system level. Also, what's installed into environments (other than the one you're in) is ignored. As somebody who uses conda for all Python development, I don't even know what I have installed in /usr/local/bin/ or other places. Everything is in /path/to/miniconda3/envs/env_name_n. You don't have to uninstall other versions of Python you have elsewhere; the point of environments is to keep everything isolated.
What can I expect to change about how I write python after I install miniconda?
Is there anything I will need to do differently from what I am doing now when I write python code?
Use conda environments and use conda as your package manager. For almost every major project, it nearly a drop-in replacement for pip. Outside of managing dependencies, not much changes.
I would like to install pip for the default installation of Python on Mac OS.
Please don't recommend brew, I already have it and installed Python 3 with it, but it seems that Automator only knows how to use the default version of Python located in /usr/bin/python That's the reason behind my specific request
I did my homework first, or tried to, before asking the question, but what I found confusing is that the recommended method seems to be using get-pip.py, but the pip documentation says
Warning Be cautious if you are using a Python install that is managed
by your operating system or another package manager. get-pip.py does
not coordinate with those tools, and may leave your system in an
inconsistent state.
This threw me off, as I don't want to risk breaking the default Python on Mac OS, as I understood that might mess my system.
I also didn't want to use the deprecated easy_install.
And I couldn't find an answer to my question, as usually the answers just recommend installing a different version of Python with brew.
Please don't recommend brew, I already have it and installed Python 3 with it, but it seems that Automator only knows how to use the default version of Python located in /usr/bin/python That's the reason behind my specific request
Can you possibly use "Run Shell Script" in Automator and specify the python version you want to use. See Specify which version of Python runs in Automator? and https://apple.stackexchange.com/questions/233890/calling-python-3-script-from-applescript
Problem
Seems like Automator isn’t loading /usr/local/Cellar/bin into your PATH. You can echo $PATH in Automator to confirm this.
Solution
Reinstall using brew and ensure that you run brew link python.
You can export PATH=... before running your script or move /usr/bin/python to /usr/bin/pythonx.x where x is the default version installed, then symlink /usr/bin/python to your brew installed python in /usr/local/bin/.
I have to use an API which uses Python 2.6 and am having a very difficult time getting it installed on my mac. I have downloaded it but figuring out what I am supposed to write in my bash_profile is exceedingly difficult. For all versions of Python that I have used so far I write
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export Path
in my bash profile. But I can't do that for python 2.6 because it does not have a bin folder. Does anyone know what I'm suppoed to write on my bash profile in order to get Python to use version 2.6?
I'm aware that one solution is pyenv but I tried that a long time ago and there were too many modules that I could not install with it so I don't like that program.
I'm also hoping brew will work but according to this page
https://formulae.brew.sh/formula/
python 2.6 is no longer available for brew install. And when I run brew install python#2.6 no formulae are found.
My current strategy is to try macports so we'll see how that goes.
I've installed anaconda, but I still want to use python as normal within a Terminal window (zsh). At the moment, running which python shows /Users/USERNAME/opt/anaconda3/bin/python.
I don't want this command to point to my anaconda installation. I want to use python as I have in the past, and for it to point to my python 2.7 installation (/usr/bin/python).
The same issue is present with pip and with python3. How do I change these paths back to their default locations?
I want to start out by saying I personally have never used Anaconda, but I have many friends who have and they always seem to wind up getting into hot water as far as configurations go. If you don't need the data-science specific tools that Anaconda offers (most of which I imagine you can get just as easily by using pip install <package_name>), then I STRONGLY urge you to not use Anaconda. I would suggest you instead use homebrew to install python 3.7 and leave the system version of python 2.7 alone... Anyways...
I recently fixed an issue similar to the one you're describing for a friend. I ended up deleted his anacaonda build and reinstalling fresh from homebrew (link: https://brew.sh/), so this is how I helped him and hopefully this will help you too.
Firstly, I would check the configuration of your ~/.bash_profile (or potentially ~/.bashrc) file. Comment out any lines you find that have to do with Anaconda by preceding with the # character. I believe when anaconda installs it puts the location of the anaconda-version-of-python higher in the PATH hierarchy, therefore you computer sees it first before it has the chance to look in /usr/bin...
Secondly, you need to move the anaconda-python to the trash... I would start by trashing the whole '/Users/USERNAME/opt/anaconda3' directory. If memory serves me correctly anaconda stores other python related things in the /MacitoshHD/Library/Frameworks directory, but don't quote me on that. I would advise looking there and trashing whatever seems to be related to the anaconda install.
After that, in a new terminal (so that your PATH refreshes), I installed homebrew, and then ran the command brew install python3 to install python3. I think perhaps I ran the command recommended in the installer output, something like "brew link python3" to symlink python3 where it needs to be linked after the installation.
Finally, everything is done python2 and python3 are installed and working with no issues. python2 is the system default version and python3 is the homebrew installed version. Feel free to ask any questions and I will try to help more, hopefully those instructions will get you started though.
I'm currently doing some embedded systems programming. This was set up by somebody else a few years ago. So now I'm looking to upgrade to Python 2.7.2 to make things simpler because I have already run into two cases where what I coded wasn't supported.
What is currently running:
: uname -a
Linux host1 2.6.18-6-486 #1 Sun Feb 10 22:06:33 UTC 2008 i586 GNU/Linux
: python -v
Python 2.4.4
: pyversions -i
python2.4
So right now only 2.4 is installed.
I untarred python2.7.2 and when I go to that directory and run python27 setup.py install --home=/home/jhemilian and it seems like python2.4 doesn't seem to know the with...as statement syntax:
host1:/home/jhemilian/src/Python-2.7.2: python setup.py install --home=/home/jhe
milian
File "setup.py", line 361
with open(tmpfile) as fp:
^
SyntaxError: invalid syntax
Before I go figuring this out I first have a question: python itself is being used to install Python? What if I didn't have the first version of Python installed? I know it's shipped with most Linux but hypothetically -- how does such a seeming catch-22 like that work?
What I am looking to do is install python2.7 in a benign location, keeping the python command still as using Python 2.4 just in case the "legacy" software i'm running is dependent on it, and running python2.7 myscript.py et cetera when I want to run one of my newer scripts. Feel free to comment if there is a cleaner or more practical (or even safer!) way to do this.
I don't think it would make much sense to go replacing all the with statements with compatible try blocks. I've looked though the READMEs and online documentation but I can't seem to find a way to install Python without already having Python. Note that I DO NOT have internet connection, although if desirable or necessary I could. It would be great if somebody could point me in the right direction. Thanks!!
It's all right in the README...
You don't need to use python to install, in fact, you shouldn't...just:
./configure
make
make install
If you want to install in a specific dir, just follow what the README says:
Installing
To install the Python binary, library modules, shared library modules
(see below), include files, configuration files, and the manual page,
just type
make install
This will install all platform-independent files in subdirectories of
the directory given with the --prefix option to configure or to the
prefix' Make variable (default /usr/local). All binary and other
platform-specific files will be installed in subdirectories if the
directory given by --exec-prefix or theexec_prefix' Make variable
(defaults to the --prefix directory) is given.
If DESTDIR is set, it will be taken as the root directory of the
installation, and files will be installed into $(DESTDIR)$(prefix),
$(DESTDIR)$(exec_prefix), etc.
All subdirectories created will have Python's version number in their
name, e.g. the library modules are installed in
"/usr/local/lib/python/" by default, where is the
. release number (e.g. "2.1"). The Python binary is
installed as "python" and a hard link named "python" is
created. The only file not installed with a version number in its
name is the manual page, installed as "/usr/local/man/man1/python.1"
by default.
If you want to install multiple versions of Python see the section
below entitled "Installing multiple versions".
The only thing you may have to install manually is the Python mode for
Emacs found in Misc/python-mode.el. (But then again, more recent
versions of Emacs may already have it.) Follow the instructions that
came with Emacs for installation of site-specific files.
EDIT: virtualenv is apparently for already-installed Python versions. Disregard this recommendation.
I think what you want is virtualenv.
I haven't used it myself, but I understand this is what it's meant for.
From the website:
virtualenv is a tool to create isolated Python environments.
The basic problem being addressed is one of dependencies and versions, and indirectly permissions. Imagine you have an application that needs version 1 of LibFoo, but another application requires version 2. How can you use both these applications? If you install everything into /usr/lib/python2.7/site-packages (or whatever your platform's standard location is), it's easy to end up in a situation where you unintentionally upgrade an application that shouldn't be upgraded.
EDIT: Upon review, I think you want Alberto's answer, so I voted him up for visibility.