Did installing Miniconda destroy Python 2.7 on my Mac? - python

Have I lost Python 2.7 and does Mac OS still need it? If so, how do I fix this?
I'm a longtime Python 3.x user on Mac OS. I wanted to try Miniconda3 to see if I could recommend it to Mac and Windows students (non-CS). Now I when I try $ type -a python3 I get:
python3 is /Applications/miniconda3/bin/python3
python3 is /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
python3 is /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
python3 is /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
python3 is /usr/local/bin/python3
Try $ type -a python2 and get:
-bash: type: python2: not found
Try $ type -a python and get:
python is /Applications/miniconda3/bin/python
python is /usr/bin/python
I used the Miniconda 64-bit (.pkg installer) under Python 3.7 here:
https://docs.conda.io/en/latest/miniconda.html

Type /usr/bin/python and:
Python 2.7.10 (default, Oct 6 2017, 22:29:07)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Okay, it's all good. Thanks, juanpa.arrivillaga!

Related

Python Path difference

what is the difference between them?
/Library/Developer/CommandLineTools/usr/bin/python3
/usr/bin/python3
MacBook-Pro Desktop % whereis python3
/usr/bin/python3
MacBook-Pro Desktop % /usr/bin/python3 --version
Python 3.8.9
MacBook-Pro Desktop % /Library/Developer/CommandLineTools/usr/bin/python3 --version
Python 3.8.9
>python3
Python 3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from my_custom_module.__main__ import main
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'my_custom_module'
But it works with other
>/Library/Developer/CommandLineTools/usr/bin/python3
>>>from my_custom_module.__main__ import main
it works
There is weird thing happens I mean, when I type full path I get 3.8.8 but when I type short name "python3" I get 3.7.9.
though
whereis returns as follow
MacBook-Pro Desktop % whereis python3
/usr/bin/python3
/usr/bin/python3
Python 3.8.9 (default, Aug 3 2021, 19:21:54)
[Clang 13.0.0 (clang-1300.0.29.3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
But
MacBook-Pro Desktop % python3
Python 3.7.9 (v3.7.9:13c94747c7, Aug 15 2020, 01:31:08)
[Clang 6.0 (clang-600.0.57)] on darwin
I think your confusion lies in the whereis command. whereis python3 doesn't actually tell you what will be run when you use python3, it just searches the standard binary directories for the specified program (python3). I would recommend using which instead, as it searches the actual PATH that you use.
See man page for whereis, man page for which, comparison.
For example on my personal computer:
❯ whereis python3
/usr/bin/python3
❯ which python3
/usr/local/bin/python3
❯ /usr/bin/python3 --version
Python 3.8.9
❯ /usr/local/bin/python3 --version
Python 3.9.7
❯ python3 --version
Python 3.9.7

How to setup python3 version on mac?

I have installed python 3.8.0 via pyenv.
pyenv which python
/Users/myname/.pyenv/versions/3.8.0/bin/python
If I run python3 I get
python3
Python 3.6.8rc1 (v3.6.8rc1:cc3e73212a, Dec 11 2018, 17:37:34)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
If I check
which python3
/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
How can I set the 3.8.0 version as default?
By typing pyenv global 3.8
You check get the list of options by typing pyenv -h
If you have multiple versions of python installed, you can do python -3.x -m ...
Also check if the env is active before opening it.

Move from python 2 to python 3 on Mac

I have both python 2.7.16 and python 3.7.3 on my Macbook air.
I don't use python 2.7.16 so I want to remove it, but I understood that this could break my Mac.
I am frustrated from using python3 and pip3 instead of python and pip is there a way to make all of the python3 commands to be accessed by using python (without 3) instead of python 2 and make python 2 be accessible by using python2?
tnx ahead
(base) shrub$ /usr/bin/py
pydoc python python2.7 pythonw
pydoc2.7 python-config python2.7-config pythonw2.7
Looking in /usr/bin there is a python executable (which when run opens a shell with python3) and a python2.7 executable (which when run opens a shell with python2).
(base) shrub$ python
Python 3.7.4 (default, Aug 13 2019, 15:17:50)
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
(base) shrub$ python2.7
Python 2.7.10 (default, Feb 22 2019, 21:55:15)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Running python scripts with python (python hello.py for example) should default to python3 and running scripts with python2.7 (python2.7 hello.py for example) will run them with python2.
Also there is a script called 2to3 which can help you with converting your python2 code to python3 :)
https://docs.python.org/3.0/library/2to3.html

"python" command can't find Python2 installation

I have screwed up my python install on my MacOS machine.
Here it is -
REMs-MBP:opt rem$ which python
/usr/bin/python
REMs-MBP:opt rem$ python
-bash: /usr/local/opt/python/libexec/bin/python: No such file or directory
REMs-MBP:opt rem$ which python2
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2
REMs-MBP:opt rem$ python2
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
python2 works fine but default python is not working fine.
How can I fix it?
brew install python by default tries to install python3. I need python2.7 as my default.
Updates:
pip still pointing to python3 installation.
PREMs-MBP:opt prem$ which python
/usr/bin/python
PREMs-MBP:opt prem$ pip
-bash: /usr/local/bin/pip: /usr/local/Cellar/python/3.7.0/bin/python3.7: bad interpreter: No such file or directory

How to get Automator to recognize python script with pyperclip?

I'm using Automator in Mac OSX 10.12.3 to run a Python script utilizing pyperclip. I created an Automator step with Run Shell Script (/usr/bin/python):
import pyperclip
import datetime
now = datetime.datetime.now()
pyperclip.copy(str(now.year) + str(now.month) + str(now.day) + '_' + str(now.hour) + str(now.minute) + str(now.second))
However, it is showing this error:
ImportError: No module named pyperclip
I can execute this code in Terminal, why pyperclip is not recognized by /usr/bin/python ? FYI, I also have Anaconda installed.
Automator is using /usr/bin/python while I installed pyperclip under Anaconda virtualenv. When I run python, I noticed it said :
Python 3.5.2 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:52:12)
[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Look like it is a different python version compared to the one Automator is using. Now all I have to do is:
sudo /usr/bin/python -m pip install pyperclip

Categories