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.
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 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.
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'm trying to use AWS CLI S3 within the Terminal (Mac OS X v10.6.8) and after configuring all of the proper credentials when I run basic commands (e.g., aws s3 ls) it does not output anything.
When I do a slightly more complicated command (e.g., aws s3 mb s3://newbucketname) it outputs: __init__() keywords must be strings.
Based on some research I suspected the cause is that Python 2.6.1 is installed by default, so I downloaded v3.3.2, installed it, and used the 'Update Shell Profile.command' feature to set the correct PATH variable.
Now with the new version of Python installed and configured I still get the same results. The Terminal still appears to be using the old version of Python, despite the $PATH variable pointing to the new version (v3.3.2).
Any help would be greatly appreciated. I'm guessing that it has to do with the Terminal not using the new version of Python and thus the AWS CLI functionality doesn't work, but there may be a different cause that I'm not aware of.
Thank you!
If you installed aws with the easy_install that came with Python 2.6, it will be hardcoded to use Python 2.6—its first line will be something like this:
#!/usr/bin/python2.6
This shebang line means that the script will run with /usr/bin/python2.6. Installing Python 3.3 won't change what's at /usr/bin/python2.6. It has nothing to do with what's on the PATH, or what the first thing called python is on the PATH. The PATH only comes into play if a script uses /usr/bin/env on the shebang line. And /usr/bin/env python2.6 would of course still find Python 2.6. In fact, even /usr/bin/env python would still find Python 2.6, because 3.3 doesn't have anything named python, just python3.
Meanwhile, even if you managed to hack it up to run with Python 3.3 instead (e.g., by changing that first line to /Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3 or /usr/bin/env python3), that would just make it break completely. The aws script requires the aws package to be installed into your site-packages. You've installed them into your 2.6 site-packages, but not your 3.3 site-packages. (On top of that, many packages install different code for Python 2.x vs. 3.x, so the 2.6 script might not work with the 3.3 package even if it were there.)
Anyway, the right way to fix this is to uninstall aws from Python 2.6, and re-install it for Python 3.3.
If you'd used pip as recommended, this would be trivial:
pip-2.6 uninstall awscli
pip-3.3 install awscli
Unfortunately, because you used easy_install instead, you have to uninstall it manually.
And really, you don't need to uninstall the packages, just the scripts that ended up in /usr/local/bin or somewhere else on your PATH. I suspect rm /usr/local/bin/aws* will take care of that, but be careful—make sure there's nothing else installed there that starts with aws but isn't part of the package.
Meanwhile, for the future, install pip and use that. For Apple's Python 2.6, use sudo easy_install pip to install it. For Python 3.3, follow the instructions at the pip site.
I have been enjoying learning the basics of python, but before I started reading things I tried to install various python versions and modules clumsily. Now that I have some ideas of what I want to do and how to do it I'm finding that various aspects are broken. For instance, 2.6 IDLE won't launch, and when I try to import modules they usually don't work.
My question is, how would you recommend I clean this up and start fresh? I have read information about modifying the 2.6 install, but I still can't get it to work.
IDLE 2.4 works, and when I launch python from the terminal I am running python 2.4.4.
I had this problem so much when I first got my Mac. The best solution I found was to delete everything I'd installed and just go with the pythonmac.org version of Python (2.6). I then installed setuptools from the same site, and then used easy_install to install every other package.
Oh, and I got the GNU C Compiler from the Xcode developer tools CD (which you can download from Apple's website), so that I can compile C extensions.
Macports should be easy to get rid of; just delete /opt/local/. I think that Fink does something similar.
You can do which python to see what python is the default one. The system python should be in /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
The MacPython you may have downloaded would either be in /Library/Frameworks/Python.framework. You can delete this as well.
Also, both MacPython and MacPorts edit your ~/.profile and change the PYTHONPATH, make sure to edit it and remove the extra paths there.
The easiest way to start afresh with Mac Ports or Fink is to simply remove the folder /sw/ (for fink) or /opt/ for MacPorts.
To completely remove them, you will have to remove a line in your ~/.profile file:
For fink:
test -r /sw/bin/init.sh && . /sw/bin/init.sh
..and for MacPorts, I don't have it installed currently, but there will be something along the lines of:
export PATH=$PATH:/opt/local/bin
export PATH=$PATH:/opt/local/sbin
As for installing Python, currently the cleanest way is to build it from source..
I wrote up how I installed Python 2.6 on Leopard here. It was for one of the 2.6 beta releases, so change the curl -O line to the newest release!
In short, download and extract the latest python 2.6 source tarball, then (in a terminal) cd to where you extracted the tarball, and run the following commands..
./configure --prefix=/usr/local/python2.6
make
sudo make install
That will install python2.6 into /usr/local/python2.6/ (the last line requires sudo, so will ask you for your password)
Finally add /usr/local/python2.6 to $PATH, by adding the following line you the file ~/.profile
export PATH=$PATH:/usr/local/python2.6
Then you will be able to run the python2.6 command.
Ideally you would just install MacPython, but it doesn't seem to have a decent Python 2.6 installer yet.