I installed a fresh version of Python via
brew install python
Also
brew info python
tells me that it is at version 2.7.7.
I seem to remember that the python OSX Mavericks ships with is 2.5. So that
python --version
gives me 2.7.5 makes even less sense.
Also
which python
/usr/local/bin/python
should be the Homebrew version, correct?
I'm lost. Does anybody know, why my Python isn't version 2.7.7?
You have to explicitly tell brew that you want to switch to the version of python you just installed. To do that, type:
brew switch python 2.7.7
in your command line. This may not work if the version you installed is actually 2.7.7_2. In that case, just replace 2.7.7 with 2.7.7_2 above and run it again. Once this is done, you'll have to reload your environment to pick up the changes.
Python from my experience doesn't do an upgrade in the sense we would like it. Basically it will install python but not overwrite the old version. If you look in your main drive you will prolly see Python 2.7.7 and Python 2.7.5
usually in Windows its: C:\Python27
It doesn't really show the last digit (which from my knowledge refers to bugs fixed in the version), so it may overwrite unless it is an entirely new version. '
But I would check first if you have two files of Python. If you do then change your PATH variable environment to point to the latest and delete the old version.
That's my suggestion but I use Windows and pip install, so hopefully it is not too different.
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'm trying to install PyAudio but it needs a Python 3.6 installation and I only have Python 3.9 installed. I tried to switch using brew and pyenv but it doesn't work.
Does anyone know how to solve this problem?
You may install multiple versions of the same major python 3.x version, as long as the minor version is different in this case x here refers to the minor version, and you could delete the no longer needed version at anytime since they are kept separate from each other.
so go ahead and install python 3.6 since it's a different minor from 3.9, and you could then delete 3.9 if you would like to since it would be used over 3.6 by the system, unless you are going to specify the version you wanna run.
I use Python 3.4 as 'python3' in terminal (Python 2.7 as 'python'). I recently installed Python 3.6 with Homebrew, but I cannot seem to replace the 3.4 version under 'python3' with 3.6.
I tried this, but I get an error and "Operation not permitted". I'm figuring I need to change a path somewhere, but I'm not sure which files to change.
EDIT: The answer to this question did not solve my problem, I'm fine keeping the default as it is. It does make me realise that maybe just changing the alias is enough, or it that not the appropriate way to go about this? (e.g. this)
To use your newly installed Python, follow ths link: python homebrew by default
Instead of changing the alias named "python3", you could use a virtualenv, that way, you can choose your Python version:
virtualenv -p python3.6 my_venv
source my_venv/bin/activate
python --version
# -> Python 3.6.1
Why do you use homebrew to install a new version of Python 3? You could have done directly from Mac OS X.
I ended up reinstalling, manually removing/reinstalling versions and packages, and then relinked the alias to the Python version I wanted to use. This setup seems to work for me so far.
My Mac came with Python 2.6.9 and 2.7.6 (the default 'Python') installed. I needed several modules from the SciPy stack and installed them using MacPorts:
py27-numpy
py27-scipy
py27-matplotlib
py27-pandas
Now for whatever reason this installed another Python version alongside the ones I already had, Python 2.7.8. All the packages only work with this one. When I start a new project in XCode and point it to this new instance, /usr/bin/python2.7, nothing works and I get
'/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file '
I can make XCode work with the 2.7.6 version, /usr/bin/python, but then none of the packages I need are available.
Is there any way to either make XCode work with this other python instance, or to remove the 2.7.6 entirely and replace the default python with the new one?
The correct path to the MacPorts python is /opt/local/bin/python2.7. By using the MacPorts version of Python, you are ensured that all of the necessary dependencies are found. I was able to follow these instructions and get everything to work. The only catch was in step 16 I had to manually enter the path because /opt was not visible.
Alternatively, you could try adding the MacPorts library path to your PYTHONPATH. Just add
export PYTHONPATH=$PYTHONPATH:/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/
to your .bash_profile. I will warn you that when I tried mixing Pythons in the past I frequently got errors relating to trying to import wrong module.
So I have installed python 2.7 in cygwin and it runs without any problem. However, when I install new packages using cygwin's setup.exe, it will always select new version 2.6.8 for the python package by default, and if I don't switch back to 2.7.2, it will uninstall python 2.7 and install python 2.6. What's wrong with my cygwin? Is there any method to fix this problem?
Python 2.7.3 is currently experimental; the current supported version of Python for Cygwin is 2.6.8. Every time you run Cygwin's setup.exe, it sees that the version of Python you have installed isn't the latest supported version, and attempts to "upgrade" you to that version.
Noticing when you've intentionally selected an experimental version of a package, and not "upgrading" you to the stable version would be a nice feature for Cygwin's setup.exe to have. Sadly it doesn't; you just have to remember to change the install list every time you run setup.
(Although if you fancy it, I imagine such an enhancement to Cygwin's setup.exe would be gratefully received by the Cygwin community; it's an open source project and someone has to do the work!)
Jason Tishler, Cygwin's Python maintainer, announced the experimental package in December 2012. To quote his email:
I will update Cygwin to make 2.7.3-1 (or later) current on or about February 1, 2013.
That change will be announced on the "cygwin" and "cygwin-announce" mailing lists, if you fancy following them. Once that happens, the installer will work as you'd like it to.
I think I have figured out what the problem is. In the package selection window, there are three options above the package list, namely, keep, Curr and Exp. The default one is Curr, which means that cygwin will select the most stable version for each selected package. In some way, python 2.6.8-2 is considered more stable than 2.7.3-1, and then each time the 2.6 version is selected. The only way is to switch to Keep option, but then we will not update other packages as well. This is quite annoying.