Run Python 3.6 in Terminal on Mac? - python

I am using a Python on a Mac and I know that Python 2 comes preinstalled on the system (and in fact usable through Terminal). Is there a way to make it so Terminal can run Python 3? Can/should you set this as a default? I know changing the default settings for Python version usage could break your system so should I just install Python 3 and then use it through its launch icon instead?

Use can use python version management tool
https://github.com/yyuu/pyenv

Package manager:
pip3 install something
Interpreter:
python3

You can use python 3 in terminal after you have python 3 installed. Every time you run a command type python3 instead of python if you are using pip to install modules you can do this:
But you must have pip installed for python 3
$ python3 -m pip install something

Best option is to install Python through Anaconda. This allows easy management and much more. You can have virtual environments having different Python versions as well as different modules installed.

as usual in Mac python 2.7 is already installed, however if you installed python 3+
then you can just type in terminal: python3
so that you can use the newer version that you installed.
if you want to use python 2.7 then just type: python

Related

Importing packages from python 2.7 to 3.7

I was using Python 3.7 on my Mac (version 10.12.6), even though my default is python 2.7. None of my import statements were working (import cv2, import Pyautogui) when I looked back and realized that I had downloaded the packages to python2.7. how do I reinstall or move these packages to 3.7, I'm hoping to make python 3.7 my primary module. if I could make them automatically go to 3.7 that would be great as well. I am required to use '--user' for may of my PIP statements so I don't know if you can use two '--' statements together. Thanks.
If you have both Python 2 and Python 3 installed then you can access the PIP of Python 3 with the command python3 -m pip install SomePackage.
Please note, some packages might not be available for Python 3. Other packages might behave differently. Consider virtual environments like conda or venv for your work.

How to Set Default Version of Python to 3.x vs 2.7 on Mac OSX?

I am attempting to install django framework using pip install -e django/, however, it requires Python 3.5+. Mac OSX by default comes with Python 2.7 so I have installed Python 3.6.5 from the python website.
I have confirmed the latest version of Python is installed through python3 .
I am still unable to install Django likely because Python 2.7 is also installed and seen first by pip.
Is it necessary to remove Python 2.7 from my system or can I modify PYTHON_HOME to achieve what I would like to do?
You can install to python 3 using
pip3 install django
python3 -m pip install django
As abarnert says in the comments, you shouldn't remove the Python 2.7 installation or try to set Python 3 to be the default.
It's good practice to use a virtual environment. Since you're using Python 3 you could use pipenv. Once the Python 3 virtual environment is activated, python will use the python 3 from the virtual environment.

Python running setup.py through cmd doesn't work?

So I'm trying to install via cmd using a setup.py file..
However, when I try to install it through CMD, this happens:
The first way you were trying to install it is correct python setup.py install, however you need Python 2.x for this installer to work. You are in a Python 3.2 environment and it appears that this module has not been updated to work with Python3 at this time.
http://ocemp.sourceforge.net/manual/installation.html
The print bdist.bdist_base, self.install_dir statement is Python 2.x syntax. If it were compatible with Python3, it would be print(bdist.bdist_base, self.install_dir)
----------
If you require development in both Python3 and Python2, I highly recommend installing Anaconda
https://www.continuum.io/downloads
You can set up multiple environments with whatever versions of Python that you want. Then you can activate each one as necessary.
http://conda.pydata.org/docs/py2or3.html

configure pip, give it python interpreter

I am new to python. I have installed pip and it have python2.4 interpreter,
I want to give pip newer version of python interpreter.
how can I do that on Unix system?
I am trying this:
pip --environment=/usr/lib/python2.6/site-packages/
but it not works.
thanks in advance!
Alternative to pip you can also run pip2.x and pip3.y (for python2.x and 3.y respectively)

Django is installing to the wrong python version

I had python 2.6 and I downloaded Django. I found that python 2.6 throws errors when trying to run django, so I downloaded python 2.7. Now, typing python in the terminal runs 2.7 but the django library isn't in the 2.7 folder. So I uninstalled django using:
sudo pip uninstall django
and that worked just fine. When i used the command:
sudo pip install django
it installed into the python 2.6 instead of python 2.7.
How can I install django into python 2.7 instead of python 2.6?
(I am running a MacBook Pro on 1.6, and I was told to not uninstall the base version of python because so many of the systems use 2.6)
You need to install pip for python2.7. If it's installed, you should be able to see it using which pip-2.7.
It's better not to touch system python. Use homebrew to install your own.
The problem is that you are running pip from your default Python installation (2.6), read this: How to run multiple python version on Windows, maybe answers give you how to solve in your OS X.
You can view the version of your default Python installation by executing python -V, there is a way to specify which version to use when you execute python, in Linux you can create an alias (alias python=python2.7) in your $HOME/.bash_profile, OS X must have something similar, then install pip using your preferred version.
BTW, It's recommended to use virtualenv

Categories