Remove old Python Installation in MAC OS - python

I installed python using MacPort and I am satisfied with the result, but found that there are other versions of Python installed in other directories, and can not remember how they were instaldas, it's been five years that use this notebook and perhaps installed by other means a few years.
I tried to remove all references to extra Python, beyond that were installed with MacPorts, but do not think like, I tried to remove the directories with the command rm -rfmas even using sudo rm -rf have success.
The old instalation are in directories:
/System/Library/Frameworks/Python.framework/Versions/
/Library/Python/
How to discover the origin of such facilities and remove permanently?

Don't remove the system Pythons. They may be used by other programs. (I don't know if anything on OS X actually uses them, but it's best to keep them.)
Instead, just make sure that your MacPorts bin directory (at /opt/local/bin) is first on your $PATH.

Don't! The name /Library and /System suggest that they are OS-level directories. Nobody installed them. Instead, Mac and other linux-based systems use them by default for system-level services (and they should not be even manually upgraded or system stability may suffer).
For all what matters, you should just prepend your installation directory to a system variable called PATH in your $HOME/.bashrc file. Then, whenever YOU use python, the system will always search for the first occurrence of python on PATH, which is your python. Open terminal, enter the following command (once in a life time):
echo "PATH={a-path-to-the-folder-containing-your-executable-python}:\$PATH" >> $HOME/.bashrc
To explain it, the quoted command prepends your installation directory as the first place to search for executable files. The >> $HOME/.bashrc write this command to the last line of .bashrc, which is a file that setup your terminal environment automatically upon login.

Related

Setting meld as git mergetool with Python3

I've tried setting meld as my mergetool to use with git doing:
git config --global merge.tool meld
git config --global mergetool.meld.path c:/Progra~2/meld/bin/meld
As outlined in answers to questions like:
How to set Meld as git mergetool
I used to have this working on my old work machine but now on my new machine where I have Python3 installed instead of 2.7 I am getting the following error whenever I try git mergetool:
C:/Program Files/Git/mingw64/libexec/git-core/mergetools/meld:
c:/Progra~2/Meld/bin/meld: C:/msys64/MINGW32/bin/python3.exe: bad
interpreter: No such file or directory
Any ideas what extra steps I need to make to get this to work with Python3?
EDIT: I have tried pointing directly to Meld.exe too but that causes the following crash:
The .../bin/meld script is mostly there for reference. You should set
git config mergetool.meld.path "C:/Program Files (x86)/Meld/Meld.exe"
You don't need to use Progra~2 notation unless you really want to for some reason.
The only issue that I am having is that it is not properly picking up the installed dependency extensions in C:/Program Files (x86)/Meld/lib. You need to add C:/Program Files (x86)/Meld/lib to your PATH environment variable, either with SET PATH=C:/Program Files (x86)/Meld/lib;%PATH%, or through the "Edit Environment Variables for your account" somewhere in control panel/start menu.
Alternative Approach
If you open C:\Program Files (x86)\Meld\bin\meld in a text editor, you will see that it is a shell script that is intended to be run in python3 (called from C:\Program Files\Git\bin\sh.exe most likely).
The first line of meld reads:
#!C:/msys64/MINGW32/bin/python3.exe
This issue does not pop up when using Meld.exe because it does not use the script through a python interpreter.
It is unlikely that the python interpreter is installed at that location on your machine. Instead, you can replace the shebang line to point to an existing interpreter. For example, on my machine, meld starts with:
#!C:/Users/MadPhysicist/AppData/Local/Continuum/anaconda3/python.exe
This still won't be enough for the script to find the meld package and all the installed GTK, cairo, etc. DLLs, so you have to tweak both the python and system paths. Insert the following before the line import meld # noqua: E402 (line ~78):
os.environ['PATH'] = os.pathsep.join((melddir, os.path.join(melddir, 'lib'), os.environ['PATH']))
sys.path[0:0] = [os.path.join(melddir, 'lib/python3.7/site-packages')]
I was not ever able to get the first line to set up Cairo, GTK, etc. correctly for meld. You can, however, skip the first line and just install the packages using conda or pip. You will still need to insert the meld package into sys.path.
Keep in mind that meld is compiled in 32 bits, as evidenced by the x86 in the install folder. You can only run it with a 32-bit python interpreter if you use the included DLLs, which may require additional installation. You do not need a 32-bit interpreter if your environment contains all the necessary packages already.

change python directory from conda

Recently, I installed miniconda, and because of which, my default python directory seems to have changed to,
/home/user/miniconda3/bin/python
Also, the default version seems to have changed to python 3.7 instead of python 2.7
And I cannot seem to install various libraries like tensorflow.
How do I get my python back to normal?
The miniconda installation has properly added itself to your PATH. You can check whether /home/user/miniconda3/bin is listed when you run
echo $PATH
in a terminal. If so, it most likely added some lines to the bottom of your ~/.bashrc file. Simply remove these lines yourself, and your PATH should be back to normal (save the file and open up a new terminal), meaning that typing e.g. python will give you the system Python.

How can I make my PATH more succinct in ZSH?

I am using ZSH. I was having trouble running the Anaconda package manager commands in my terminal. I found that I could add the bin to my PATH using this code:
export PATH="$HOME/anaconda3/bin:$PATH"
That worked. All of the Anaconda and associated commands work and it left me with this PATH:
/Users/USER/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
But the PATH variable would reset each time I closed the terminal window. After some research, I figured out how modify my .zshrc to make it permanent. I simply pasted this into my .zshrc:
export PATH=/Users/USER/anaconda3/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin
All the commands work and are permanent, but aren't I setting myself up for failure down the road? Everything in the PATH, minus the "/Users/USER/anaconda3/bin" were set automatically. What happens when I update Python, for example? How can I include the "USER/anaconda3/bin" portion of my PATH in my .zshrc without being so explicit?
Your PATH concern is not zsh specific. You could organize things differently.
For example, you could decide to add a directory $HOME/bin/ early in your PATH and put inside that $HOME/bin/ symbolic links to the executables (or scripts) that you want to use. BTW, I recommend to have a short PATH (containing some $HOME/bin/ etc...) since it is more efficient and less messy to understand.
What happens when I update Python, for example?
Let's suppose that Python is installed in your system in /usr/bin/python (and that you use some Linux distribution -or some other Unix- with a good package manager dealing with that;on MacOSX consider homebrew). When that file /usr/bin/python is updated, any future exec of it (e.g. by some shell) will use the new version. Read carefully execve(2).
If ou have several Python-s and the one you want to use is under /Library/Frameworks/Python.framework/Versions/3.6/bin and you upgraded it to some Python 3.7 installed under /Library/Frameworks/Python.framework/Versions/3.7/bin you would need to change your PATH.
If you followed my suggestion, you would (for example) just have a symlink from $HOME/bin/python to /Library/Frameworks/Python.framework/Versions/3.6/bin/python and you would upgrade that symlink when installing Python3.7 using for example:
# remove the old symlink
rm -v $HOME/bin/python
# add the new one
ln -sv /Library/Frameworks/Python.framework/Versions/3.7/bin/python \
$HOME/bin/python
In all cases, you are responsible of having a good enough PATH (and preferably a short one).

Git bash uses wrong python, other solutions don't work

I've seen a couple solution so far but they don't work. I'm trying to run (in git bash, on windows)
bash scripts/test.sh
But it's supposed to use Python27, and I have that, and Python34. when I type python --version, it tells me it's using Python34. I tried doing
PATH=$PATH:/c/Python27/
But it still tells me I'm using Python34. I know it's in my environment variables, so what am I missing?
$PATH:/c/Python27/ adds /c/Python27/ to the end of your PATH. The directory containing the Python34 executable must be already in your $PATH. So you need to add /c/Python27/ before the other directories listed in $PATH, so it is checked before the directory containing Python34.
PATH=/c/Python27/:$PATH

How can I make cygwin aware of enthought python?

I need scipy on cygwin, so I figured the quickest way to make it work would have been installing enthought python. However, I then realized I have to make cygwin aware of enthought before I can use it, e.g. so that calling Python from the cygwin shell I get the enthought python (with scipy) rather than the cygwin one.
How do I do that?
I can guess my question is easy, but I'm just learning about all of this and so please be patient :-)
Think about uninstalling the cygwin version of Python, at least to start with. It's easy enough to reinstall later.
Copy your Windows path.
Install the Windows version of Enthought Python.
Examine the new Windows path. The new entries probably have to be transferred to your bash shell in cygwin. (I haven't seen Enthought. There might be more than one new path entry.) But test without changing the bash path, just to be sure.
Add the new path entries to, umm, .bashrc, I think. The path under cygwin will be a colon delimited string. You'll need to use the /cygdrive path; expect to use an entry like this to put Entought in the path.
/cygdrive/c/Program Files/Enthought
To actually do that, edit .bashrc, and put these two lines (or something like them) at the end.
PATH=$PATH:/cygdrive/c/Program\ Files/Enthought
export PATH
Note that the backslash allows proper interpretation of spaces in file paths. The export statement guarantees that programs called by bash will also include that path.
Just put the directory with enthought python before the directory with Cygwin's python in your path. If both are in the same directory, use ln to create a symbolic link, store it in another directory, and place it higher in your path. The previous answer has instructions to add it to your path.

Categories

Resources