Uninstalling Python 2.7 on OSX 10.8.4 - python

Main problem:
I've installed recently Python3.3 - If I run now in Terminal: python script.py (where script.py is coded in version 3.3) I'll get a python 2.7 output e.g.:
print('String',Var) --> ('String',Var)
Instead of:
print('String, Var) --> String Var
How can I uninstall Python 2.7 easily with Macport (without reading through Shell commands (time restriction)?)
This one didn't worked.
Second (smaller) problem:
If I type in Terminal python, I'll get python2.7 idle as output. How can I change this, so that command python refers to python3.3 (instead of using the command python3)
(About me:
Python2.7 novice, absolutely no Shell knowledge, OS X 10.8.4 User, Xcode and Macport installed.)

Bad idea to uninstall the pre installed version of python. Better idea is to alias python to whatever you want in your bashrc/bash_profile.
In your home directory, aka ~, you might already have a .bash_profile(If you don't have one, you can make it). You can edit that with your favorite text editor and add alias python='python3' Or whatever you want called whenever you type python into bash.
(FWIW Homebrew is the new hotness, you might want to look into it as well)

I agree that it is bad idea to uninstall Python 2.7, just use following commands:
To list available Python versions:
port select --list python
To select desired version:
sudo port select python desired_version_from_list
This is proper and easy way to do it in MacPorts.

DON'T UNINSTALL PYTHON!!
It will mess up everything --> may be crash your OS. I tried that in Fedora 17 and it failed my package manager as yum is build in Python. One many great thing about Python is it supports multiple versions at once in the same platform which you already experienced.
Now, to resolve your problem do Edgar suggested.
Also, while writing your python code do this:
#!/usr/bin/env python3
print('Hello world!')
Then,
python hello.py would run code in python3.

Related

How can I change my python version in git bash?

I been looking at fixes for this but im terrible at search. I came across this fix
didnt work
$ PATH=$PATH:/c/Python36/python
$ python --version
Python 2.7.13
I came across an alias fix turned out to be temporary so that didnt work
I want basically every command i do like everything under Python36/Scripts like pip, pytest, etc to be from python36. But everything is going to python 2.7
how do you change your python version? I am trying to change my git bash python version from python 2.7.13 to 3.6. I don't want to delete python 2.7 tho
Do this:
pkg install python2
And to use python2 do
python2 yourcode.py
And for python3 use
python3 yourcode.py
To check Version if you check:
python - -version
It will give 3.9.2 for me and 3.6 for you but if you check
python2 - - version
It will give the result 2.7.18
Here is the proof:
Check this in order to change the default python version without removing the package.
https://unix.stackexchange.com/a/521060/214441

Installing pip with default python on Mac OS 10.14 Mojave

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 am trying to use python 3 instead of python 2

Currently in my mac terminal when I type python --version it says I am using python 2.7.x. I would like to change so that I am using python 3.8.x. How can I update this in terminal? Also, if I would like to go back to using python 2.7, is there a way to revert it?
Thanks!
If Python 3 is installed, you should be able to run python3. If not, install the current distribution from their website.
Python 2.7.x is always available via the alias python2.
brew install python3
will install python 3 and you can use python3 command to run 3x version of python. If you want to use python 2x version you could either use virtualenv or you could just use python2 to run your program with python 2x version.
If you want to implicitly specify that inside a file you could use
#!/bin/env python2.7
on top of the script to run the program with python 2.7 version.
As you see, there are many options for the same.

How to use and install all the libraries of Python3?

Using Ubuntu 16.04.
I was doing development in Python2.7, although recently moved to Python3.5, both of which come by default. The problem is, I find all the python libraries have to be reinstalled or downloaded for the next Python3. Also, the behaviour of Python seems weird because to execute the same script in python3, I have to enter in terminal
python3 script.py
which is different from other applications where I do not have to give the version number. Anyway, the questions I am trying to find answers are
To what extent are the libraries, packages (such as pip etc.) shared between 2.7 and 3.5? Or do I need double installations (and double the space) for everything now? A bit space limited in my old laptop.
Most of the installation instructions and commands I find online do not specify whether they are for 2 or 3. Given that I have two versions, how do I control/make sure they go to 3.5?
Is it advisable and possible to completely remove everything related to 2.7? Can I keep working with 3.5?
The first thing you need to know is that all official libraries and python tools for python3 got the "3" character to separate them from the previous versions. So, you need to use pip3, and not pip, python3, not python, and the packages are called python-pygame, not python-pygame.
So, to answer to you in order:
Yes, the you have to double the space needed if you decide to use both python2 and python3
Usually, if in the tool name there is 3, it is for python3, and if not it's for python2
Python2 and python3 are completly indipendent (different path, indipendent versions, etc.) so having python 2.7 installed doesn't affect python3 BUT since python 3 is the next version of python 2, it makes it obsolete (in my opinion) so if you don't have enough space for both, keeping python2 is absolutely not needed nor useful
If you want to control your python execution then you have various method or techniques:
For downloading packages according to version
You can use pip{version-name} to download the libraries. Like if you want to download library of python 2.7 then write
pip2.7 install package-name
for python 3.5 then use
pip3.5 install package-name
For execution of program:
If you want to execute the program accoridng to you choice of version then just use
python{version-name} script.py
eg:
python2 script.py
python3 script.py
or you just write down the path of your python version on the top of script. Please refer this for more details:
Why do people write #!/usr/bin/env python on the first line of a Python script?

OS X: How to link updated Python version (3.4 to 3.6)

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.

Categories