Remove installed Python 3.5 from Mac Os X global path - python

I have recently installed the "official" Python 3.5 on Mac Os X (El Capitan). During this installation, Python changes the global path to include /Library/Frameworks/Python.framework/Versions/3.5/bin (this can be seen using for instance /usr/libexec/path_helper).
However, I am unable to understand where this "set" is done (there is nothing nor in /etc/paths neither in /etc/paths.d). I would like to remove this entry from the global path (without removing the installation itself because it can be always useful).

I have got the same issue. After a SUPER LONG search I found this file: "~/.zprofile". Check within this file and you will find the following code:
# Setting PATH for Python 3.5
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
Just remove this code and save the file.

I also had a similar output when running:
echo $PATH
Standard out-put result:
/Library/Frameworks/Python.framework/Versions/3.9/bin:/Library/Frameworks/Python.framework/Versions/3.8/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
The following sequence of steps solved the issue for me using zsh (macOS Big Sur Version 11.1)
cd /Users/JohnDoe
vim .zprofile
Remove the following PATH settings and save the file:
# Setting PATH for Python 3.8
#The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.8/bin:${PATH}"
export PATH
# Setting PATH for Python 3.9
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.9/bin:${PATH}"
export PATH
Refresh zsh profile from the users home directory:
source .zshrc
Check your work:
echo $PATH
Standard out-put result:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin

To remove python 3.5 from your mac try below command
cd /Library/Frameworks/Python.framework/Versions
sudo rm -rf 3.5

Related

Python3 and 'code' CLI not working after updating to MacOS Monterey

I updated to MacOS Monterey and now python is not working:
➜ ~ python3 --version
dyld[6578]: dyld cache '/System/Library/dyld/dyld_shared_cache_x86_64h' not loaded: syscall to map cache into shared region failed
dyld[6578]: Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
Reason: tried: '/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation' (no such file), '/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation' (no such file)
[1] 6578 abort python3 --version
But if I run:
➜ ~ /usr/bin/python3 --version
Python 3.8.9
I am able to run it. But when running code . for opening a project in vs code it gives the same error:
dyld[6683]: dyld cache '/System/Library/dyld/dyld_shared_cache_x86_64h' not loaded: syscall to map cache into shared region failed
dyld[6683]: Library not loaded: /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
Referenced from: /Library/Frameworks/Python.framework/Versions/3.6/Resources/Python.app/Contents/MacOS/Python
Reason: tried: '/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation' (no such file), '/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation' (no such file)
/usr/local/bin/code: line 10: ./MacOS/Electron: No such file or directory
I am not sure what to do so that it runs commands like code . successfully.
This is 100% a version conflict/PATH problem.
First, open up terminal and try running echo $PATH. It should print something like this:
/opt/homebrew/bin:/opt/homebrew/sbin:/Library/Frameworks/Python.framework/Versions/3.10/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
As you can see, it says 3.10 for me, while yours says 3.6
#guest_fish makes a good suggestion with deleting outdated versions of Python, but another way you can try is by checking the following:
vim $HOME/.zprofile ---> this is the zsh analogue to .bash_profile, here's what mine looks like:
# Setting PATH for Python 3.10
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
export PATH
eval "$(/opt/homebrew/bin/brew shellenv)"
Note how it matches the first part of the path I echo'd above
vim /etc/paths ---> this should match the middle parts of your PATH, mine looks like this:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
vim /etc/paths.d/<your_unique_id> (just press tab to complete it when you're in paths.d, you generally have only one option). Mine looks like this:
/Library/Apple/usr/bin
Note how it matches the end of the path
When you visit each of these files, you can modify them (password protected obv) to put /usr/bin/python3 first, meaning that will be the first place that it looks for python build files and will (hopefully) use the correct version
Now, to fix the code thing, you could try going into VSCode and hitting SHIFT + ⌘ + P, then select Shell Command: Install 'code' command in PATH - this should update it for you automatically.
Lmk how it goes!
Your python3 is 3.8.9 but the error message is for 3.6. It looks like you have clashing python versions. I fixed this error on my machine by uninstalling 3.6 and all of its syslinks like seen here under "Uninstalling Python 3 Using Terminal", except I used homebrew commands brew doctor and then brew cleanup for steps 4. and 5.

How can I change the default python3 path in MAC cmd?

My Mac has contained multiple python versions so that I would like to fix one as my default python.
In the current, it has set the path of anaconda python. I have stopped to use the anaconda-python.
And I would like to change the python3 as default following with path:
/usr/local/bin/python3
How can I do this?
Hope:
python3 as default that path
jupyter notebook would follow that path
pip3 install package would follow that path
Update your environment variable PATH to include your required python path. Append the python path in the beginning of the environment variable PATH, so that first it'll look in that path.
You need to update that in .bash_profile file. For that go to the root path and look for the mentioned file. Run ls-a to check whether the file is present.
cd ~
ls -a
Open the file
vi .bash_profile
Add below commands in the file (press i to go into insert mode)
# Setting PATH for Python
export PATH={ur path}:$PATH
(Save the file by pressing :wq)
Check whether the update is made by running
echo $PATH
You can change the path to this by editing the .bashrc file
export PATH="/usr/local/bin/python3:${PATH}"

Getting error when exporting ipa in development method

When I select IPA distribution method as development and try to export, I am getting this same error for all my projects, and I am not using python anywhere so why I am getting this error. Please help me to solve this error.
I am using Xcode 9.2
ipatool failed with an exception:#<RuntimeError: Couldn't locate python in /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/bin /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/libexec /Applications/Xcode.app/Contents/Developer/usr/bin /Applications/Xcode.app/Contents/Developer/usr/local/bin /Applications/Xcode.app/Contents/Developer/Tools /usr/bin /bin /usr/sbin /sbin>
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:157:in `locate_tool'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:137:in `unicode_equal?'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1703:in `block in MakeFileSystemNode'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1703:in `each'
/Applications/Xcode.app/Contents/Developer/usr/bin/ipatool:1703:in `detect'
I found the problem, thanks to Alper to guiding me in the right direction, when we create or export an IPA Xcode needs python which is located in /usr/bin/python path, and in my case I have installed python but it was not on that location, so I search for python executable file in my system and copy paste that executable file on this /usr/bin/ location, and it work's.
Well it seems that Apple use python and that something has broken. Since the error is in your Xcode.app path, I'd recommend a reinstall of your Xcode to see whether that fixes things.
It happen because XCode can't find path to python binary file.
1) Find your python binary file:
Enter in your terminal:
python
Next enter:
import sys
sys.path
The screen will display the paths to various python directories.
Example:
['', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload', '/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages']
Copy path to bin/ folder and exit from python:
Just press command+d
2) Copy python binary file to /usr/bin destination:
Enter in your terminal:
cp {INSERT HERE COPIED PATH TO /bin PYTHON DIRECTORY}/python /usr/bin/
Example:
cp /Library/Frameworks/Python.framework/Versions/2.7/bin/python /usr/bin/
After that the issue will fixed!
If you ever have problem with application not locating your python - symlink will do the trick.
For some reason my pythons are installed in /usr/local/bin, while one of my IDEs searches in /usr/bin.
sudo ln -s /usr/local/bin/python /usr/bin/python
fixed this issue.
enjoy!

Windows command line, "python3" pointing to the wrong python3.exe

So, I have Anaconda, OSGeo and Python2.7 installed on my computer.
I'm also using Spyder. In Spyder :
>>> import sys
>>> sys.executable
'C:\\ProgramData\\Anaconda3\\pythonw.exe'
Which is what I want.
However, in the windows command line and powershell :
$ python3
>>> import sys
>>> sys.executable
'C:\\Progra~1\\OSGeo4W\\bin\\python3.exe'
Which is not what I want. I want to use 'C:\\ProgramData\\Anaconda3\\pythonw.exe' (or python.exe, not sure) when using python3 in the command line.
Also :
$ pip3
Fatal error in launcher: Unable to create process using '"'
I don't get why python3 in the windows command line points to OSGeo's version of Python3. Here is my path :
C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Anaconda3;C:\ProgramData\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Git\cmd;C:\Program Files\PuTTY\;C:\Progra~1\OSGeo4W\bin\;C:\Program Files\Microsoft\R Open\R-3.4.0\bin
I also have an environment variable called PYTHONHOME
C:\ProgramData\Anaconda3
Moreover (for completeness of information), I have python 2 installed :
$ python
File "C:\ProgramData\Anaconda3\lib\site.py", line 177
file=sys.stderr)
^
SyntaxError: invalid syntax
($ pip outputs the same thing).
Having python3 and python2.7 both work when using python3 and python (respectively) in the windows command line would be a nice bonus, but it's not really my priority.
There are probably several things you have to take care of:
In general the search order of the Windows PATH is from left to right starting with the system PATH. The first matching element wins. In your case this is correct because the system will search C:\ProgramData\Anaconda3\ first. However in that folder is no executable called python3 by default. On my system I created a simlink pointing to python.exe. On your system you can do it in PowerShell like this:
New-Item -Path C:\ProgramData\Anaconda3\python3.exe -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\python.exe
pip is located in Scripts\ folder so in your case you have to add C:\ProgramData\Anaconda3\Scripts to your PATH and create the corresponding simlinks again. In this case you have to create two of them because pip.exe is appending its name to the script that is trying to call (i.e. if your exe file is called foo.exe it will try to call foo-script.exe which does not exist) you can create the simlinks in PowerShell with those two commands:
New-Item -Path C:\ProgramData\Anaconda3\Scripts\pip3.exe -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\Scripts\pip.exe
and
New-Item -Path C:\ProgramData\Anaconda3\Scripts\pip3-script.py -ItemType SymbolicLink -Value C:\ProgramData\Anaconda3\Scripts\pip-script.py
Like this you will be able to use python3 and pip3 from your cmd line. Please check for similar problems with your python2 installation folder.
Hope it helps.

How can I run my python script from the terminal in Mac OS X without having to type the full path?

I'm on Mac OS 10.6 Snow Leopard and I'm trying to add a directory to my PATH variable so I can run a tiny script I wrote by just typing: python alarm.py at the terminal prompt.
I put the path in my .profile file and it seems to show up when I echo $PATH, but python still can't find script the that I've put in that directory.
Here's the contents of my .profile file in my home directory:
~ toby$ vim .profile
export PATH=/Users/tobylieven/Documents/my_scripts:$PATH
Here's the output of echo $PATH, where all seems well:
~ toby$ echo $PATH
/Users/tobylieven/Documents/my_scripts:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
Here's the script I'm trying to run:
~ toby$ ls /Users/tobylieven/Documents/my_scripts
-rwxrwxrwx# 1 tobylieven staff 276 17 Jan 21:17 alarm.py
Here's the command I'm trying to use to run the script and the fail message I'm getting instead:
~ toby$ python alarm.py
python: can't open file 'alarm.py': [Errno 2] No such file or directory
If anyone has an idea what I might be doing wrong, that'd be great.
Thanks a lot.
PATH is only for executables, not for python scripts. Add the following to the beginning of your Python script:
#!/usr/bin/env python
and run
sudo chmod a+x /Users/tobylieven/Documents/my_scripts/alarm.py
Then, you can type just alarm.py to execute your program.
Which python are you targeting?
Did you install it with brew? It uses a different path.
which python3 or which python
Choose the one you want
Copy that output
Paste it at the top of your python file
add a #! in front of that path so it looks something like
#!/usr/local/bin/python3
Make sure to change the file permissions
chmod +x filename
Put that file in a folder that is in your path
Not sure if your folder is in your path?
echo $path
How to add that folder to your path?
Find your path first
echo $HOME
If you are using bash or zsh you might have something like this
In ~/.bash_profile or ~/.bashrc or ~/.zshrc at the bottom of your file
export PYTHON_UTILS="$HOME/code/python/utils"
export PATH="$PYTHON_UTILS:$PATH"
Consider removing the .py from your file bc it is not needed in this case
Close and open your terminal, which is sourcing your file by its path
And now you should be able to treat your python file similar to a bash command
You don't need to use python3 filename.py to run the file, you can just use filename
From anywhere on your filesystem!
change alarm.py to include:
#!/bin/python
as the very first line in the file.
(or /usr/bin/python, depending on where you python interpreter is located. You can figure this out by typing: which python in the terminal.)
You can then just run alarm.py instead of python alarm.py.
e.g.:
~ toby$ alarm.py
And phihag who beat me by a few seconds is right, you need to add execute permissions (via chmod) to alarm.py.
You need to modify the Python specific path variable: PYTHONPATH.
So:
export PYTHONPATH=/Users/tobylieven/Documents/my_scripts
should get you working.
See: Python Module Search path
Something of interest that I really struggled with on OS X coming from Window, is that you its very hard to get the directory of your current script.
I found this.
#! /bin/zsh
cd "${0:h}"
Now you could execute a python file relative to the executed script instead of having to know the exact path where your python file is.
This might or might not help but I use this a lot to make my scripts and .command files work better.

Categories

Resources