Installing Python 2.7 and 3.6 Side by Side on Mac - python

Python newbie here. I just bought a new Mac Book Pro (switched from Windows) and Python 2.7 is already installed on it. I want to install 3.6 side by side and choose between the two versions. I found a great tutorial located here http://joebergantine.com/articles/installing-python-2-and-python-3-alongside-each-ot/ but I'm confused on one of the command line operations. Under Python 2 Installation it says:
Install Python 2 from the latest Python.org package. This allows you to run python2 and pip. After this installation Python 2.x will be accessible at /Library/Frameworks/Python.framework/Versions/2.7/bin/.
Once the Python 2 package is installed, install virtualenv for Python
2 for the User only. When specifying the User installation, Python
packages are then accessible at ~/Library/Python/2.7/bin. Specifying
the User installation doesn't automatically add virtualenv to the
system path which we will do manually in the next step via an alias.
This is what allows Python3 and Python2 to run alongside each other:
$ pip install --user virtualenv
Do I have to be in the ~/Library/Python/2.7/bin directory when I run this command or the /Library/Frameworks/Python.framework/Versions/2.7/bin/ directory? I'm confused because I don't know where the former directory is coming from.

Why not using pip for python 2.7 and pip3 for python 3.6?
If it says pip3 is not installed you can use sudo apt-get install pip3
then you can use pip3 for python 3.6 and pip for python2.7 for installing packages for respective versions

I faced the exact error, in the exact situation about 2 years ago. The solution to your issue is pyenv. I was able to run multiple versions of python inside different folders of the same directory. It truly was a very nice solution.
Hope this helps.

Related

How to install brownie on mac os running both python 2.7 and 3.9 [duplicate]

I am trying to get python 3 working on my OSX laptop.
I need to install requests for python 3, and it isn't working.
I think I've managed to get pip installed for both python 2.7 & python 3 however...
Whenever I use 'pip' it points to python2... I can't seem to access the pip for python 3?
In all likelihood, pip3 will be installed pointing to your Python 3 installation, so your use case is probably solvable by just switching from:
$ pip install foo
to:
$ pip3 install foo # Or pip3.7 install foo if you need to disambiguate further
That said, it can get kind of complicated when you have many different Python installs, where pip/pip3 might have been installed pointing to a Python version that doesn't correspond to the python/python3 you're using, which can be quite confusing.
If you know python & python3 are the correct executable, just use it to invoke pip on your behalf. It's fairly easy too, just check your version to be sure it's the one you expect (e.g. on my system):
$ python --version
Python 2.7.15rc1
$ python3 --version
Python 3.6.6
then use the appropriate one with -mpip, a flag to run an installed module/package via the chosen Python as the "main" executable, bypassing the need for specifically versioned pip executable entirely. So if you wanted to install foo for Python 3.6 on my machine, you'd run:
$ python3 -mpip install foo
This is especially useful on Windows, where the pip executables often either don't exist, or are not installed in the PATH, so it's irritating to use them. Instead, use the Windows launcher that comes with any modern Python 3 version (but manages all Python versions on the machine), and is used to disambiguate among various versions. For example:
C:\>; Installs foo for latest installed version of Python 3
C:\>py -3 -mpip install foo
C:\>; Installs foo for latest installed version of Python 2
C:\>py -2 -mpip install foo
C:\>; Installs foo for latest installed version of Python 3.6
C:\>py -3.6 -mpip install foo
Essentially, any use of pip can be replaced by executing the Python interpreter directly with the -mpip option to run the pip package as the "main" executable.
This trick applies to many other tools with dedicated launchers that are often not installed in the PATH, particularly on Windows, and it makes updates easier too; my Windows shortcut for launching ipython3 never used a hardcoded path to the launcher (e.g. C:\Program Files\Python36\Scripts\ipython3.exe), instead using %WINDIR%\py.exe -3 -mIPython. In addition to being more portable (the shortcut "just works" on any Windows system with a semi-recent Python 3 install), it's self-updating; when I upgraded from 3.6 to 3.7, the shortcut didn't have to change at all (I had to run py -3 -mpip install ipython again to get IPython reinstalled, but once I'd done that, the shortcut seamlessly began referring to the 3.7 install with no changes needed).
Run this command to find the python that is used before running pip: which python. You can do the same idea to find which pip version is being run: which pip
You’ll need to create separate virtual environments in order to use different python versions and/or python dependencies. Use something like conda or venv to do this. Then, ensure that the desired python version virtual environment is activated prior to installing a new package with pip.
To install requests for python3, use pip3 install requests which is the pip installer for Python 3 modules.
This guide has some further info on getting Python 3 working on a mac.
https://docs.python-guide.org/starting/install3/osx/
try to sudo apt-get update first then sudo apt-get install python3-pip --fix-missing

How to use pip with python 2 & 3 installed? (OSX)

I am trying to get python 3 working on my OSX laptop.
I need to install requests for python 3, and it isn't working.
I think I've managed to get pip installed for both python 2.7 & python 3 however...
Whenever I use 'pip' it points to python2... I can't seem to access the pip for python 3?
In all likelihood, pip3 will be installed pointing to your Python 3 installation, so your use case is probably solvable by just switching from:
$ pip install foo
to:
$ pip3 install foo # Or pip3.7 install foo if you need to disambiguate further
That said, it can get kind of complicated when you have many different Python installs, where pip/pip3 might have been installed pointing to a Python version that doesn't correspond to the python/python3 you're using, which can be quite confusing.
If you know python & python3 are the correct executable, just use it to invoke pip on your behalf. It's fairly easy too, just check your version to be sure it's the one you expect (e.g. on my system):
$ python --version
Python 2.7.15rc1
$ python3 --version
Python 3.6.6
then use the appropriate one with -mpip, a flag to run an installed module/package via the chosen Python as the "main" executable, bypassing the need for specifically versioned pip executable entirely. So if you wanted to install foo for Python 3.6 on my machine, you'd run:
$ python3 -mpip install foo
This is especially useful on Windows, where the pip executables often either don't exist, or are not installed in the PATH, so it's irritating to use them. Instead, use the Windows launcher that comes with any modern Python 3 version (but manages all Python versions on the machine), and is used to disambiguate among various versions. For example:
C:\>; Installs foo for latest installed version of Python 3
C:\>py -3 -mpip install foo
C:\>; Installs foo for latest installed version of Python 2
C:\>py -2 -mpip install foo
C:\>; Installs foo for latest installed version of Python 3.6
C:\>py -3.6 -mpip install foo
Essentially, any use of pip can be replaced by executing the Python interpreter directly with the -mpip option to run the pip package as the "main" executable.
This trick applies to many other tools with dedicated launchers that are often not installed in the PATH, particularly on Windows, and it makes updates easier too; my Windows shortcut for launching ipython3 never used a hardcoded path to the launcher (e.g. C:\Program Files\Python36\Scripts\ipython3.exe), instead using %WINDIR%\py.exe -3 -mIPython. In addition to being more portable (the shortcut "just works" on any Windows system with a semi-recent Python 3 install), it's self-updating; when I upgraded from 3.6 to 3.7, the shortcut didn't have to change at all (I had to run py -3 -mpip install ipython again to get IPython reinstalled, but once I'd done that, the shortcut seamlessly began referring to the 3.7 install with no changes needed).
Run this command to find the python that is used before running pip: which python. You can do the same idea to find which pip version is being run: which pip
You’ll need to create separate virtual environments in order to use different python versions and/or python dependencies. Use something like conda or venv to do this. Then, ensure that the desired python version virtual environment is activated prior to installing a new package with pip.
To install requests for python3, use pip3 install requests which is the pip installer for Python 3 modules.
This guide has some further info on getting Python 3 working on a mac.
https://docs.python-guide.org/starting/install3/osx/
try to sudo apt-get update first then sudo apt-get install python3-pip --fix-missing

aws CLI install window

I am having trouble installing the aws CLI for windows.
I am following these instructions here
It requires that I have Python 3.6.2 but I have Python 2.7.6 when I run python --version
After I run
pip install --user --upgrade awscli
and then try to run
aws --version
nothing happens.
I tried setting my path in Environment Variables but it still won't work.
After this, I tried to upgrade my python version by installing python 3.6 on their website, but my python version won't update when I run python --version.
Could this be that start of why I cant install the CLI?
Use this link to download and install AWSCLI Download the AWS CLI MSI installer for Windows
then go to C:\Program Files\Amazon\AWSCLI or where-so-ever you have installed this and set the path in Environment variables.
Cheers!
Have you gone through the steps on the amazon website? Python 2 and 3 are quite different from what I understand.
https://docs.aws.amazon.com/cli/latest/userguide/installing.html
The AWS script you are running is really just a python program. I recommend verifying install paths, and possibly use their bundled installer found on the page above, about half way down.
At first make sure you have installed python3. Check it with command:
Try to verify python version with command(on centos or redhat):
$ rpm -qa|grep python3
And then make sure python3 has been added to $PATH
$python3 --version
And I think you need to install pip3 for python3.X.
$yum search python3|grep pip
And then install the package you need with command
$ pip3 install --user --upgrade awscli
You can develop Python software for AWS in both Python 2.x and 3.x. The CLI is written in Python 2.x.
You can have both Python 2 and Python 3 installed on your system. You can either specify the python.exe manually using its full path (not recommended but I do this all the time) or by updating your environment PATH variable to point to the correct Python installation. I use a batch file so that I can switch back and forth between Python 2 and Python 3.
When you run "pip install --user --upgrade awscli" the version of Python that is running determines the awscli package that is downloaded and installed.
For Microsoft Windows, AWS provides an MSI installer package that contains everything that you need including the correct version of Python 2.7. I recommend that you start with the AWS Windows MSI and then learn how Python works (environment) on Windows.
Keep in mind that Python 2.x is going away. This is not official but plan for January 1, 2020 as the drop dead day. This means where possible develop for Python 3. IMHO it is time to stop developing for AWS in Python 2.x.
If you have choco installed the following will work....
choco install -y awscli
$env:Path += ';C:\Program Files\Amazon\AWSCLI'

How do we separately use, maintain & install libraries for python 2.7 and python 3.5 on the same Ubuntu OS?

I need to work with Both Python 2.7.12 and python 3.5.2 simultaneously on my Ubuntu 16.04.1 LTS. Python 3 came pre-installed so I've no idea where it sits, in terms of path to the directory, while python 2 sits in /usr/local/lib/python2.7/.
I found lots of questions on SO and on askubuntu about how to install but nothing about how to use them separately, installing different libraries, and what should I avoid or be careful of, if I maintain this dual python thing for the long term? For example, I usually run pip install to install a library and I can check that its installed in my python2 directory but how do I install the same package for my python3 without conflicts? Something like: python3 pip install <package> ?? Where is the default python3 installed? And how do I call python3 for paths where python is not part of the command for example: pip freeze, sudo-apt get, etc.?
PS: I've not officially worked with Virtualenv but I've been informed that is usually good for isolating projects within a python language version, rather than isolating two different language versions from each other.
Please let me know.
Thanks
This is absolutely no problem, as Python does that for you. You don't need a virtualenv at all.
If you use Ubuntu packages, make sure you use the python3- versions for Python 3, and the normal python- versions for Python 2.
For example, python3-numpy and python-numpy.
If you use pip to install extra packages, you an either use the pip script with the version number appended: pip2.7 or pip3.5, or, my preferred method, call pip as a module for the respective Python executable:
python2.7 -m pip install <whatever>
and
python3.5 -m pip install <whatever>
Other than that, there should not be any issue: Python stores the packages in completely separate directories, and each Python executable only uses its respective directive.
Do not fiddle around with PYTHONPATH, unless you really know what you're doing. This has the danger of setting your PYTHONPATH to a directory with Python 2.7 modules and then using Python 3.5 to run things.
If you start from scratch, you may need to install pip first.
For the system Python(s), use the relevant package:
sudo apt install python-pip
sudo apt install python3-pip
For your locally installed Python(s), use the built-in bootstrapper module:
pythonx.y -m ensurepip
Note on the OS-installed Python executables:
Python 3.5 lives at /usr/bin/python3.5, Python 2.7 (the OS one) at /usr/bin/python2.7.
You could even use the OS 2.7 one next to your locally installed /usr/local/bin/python2.7 (and confuse yourself when a package can't be found because you used the wrong one).
Or install Python 3.6 next to Python 3.5 (provided you've used make altinstall, so python3 doesn't get overwritten).
This is also why you don't really want to run pip (or even pip2.7) as is: pip2.7 may get you the system one, instead of the one in /usr/local/bin/pip2.7, depending on your PATH.
(The same goes for the python2.7 executable, so if you need to specify the full path /usr/local/bin/python2.7 to run that one (or have an alias), the same holds for pip2.7. If, on the other hand, /usr/local/bin is first on your PATH, you should in principle never run into the same pip and python executables.)

How can I use pip to pip install Python 3 in Ubuntu terminal?

Currently using Cloud9's ACE IDE dev environment for some learning opportunities, however, I ran into an API that is exclusively made for Python 3.
How can I pip install Python 3 while keeping python 2.7.6 (the current version) intact?
pip cannot be used to install Python, pip is used to install python packages, it's a package manager.
If you are looking for a command line utility that handles installing different version of CPython, (among other things) you can look at conda, conda is an environment manager.
conda is usually packaged with anaconda and works by managing environments in which you can specify different versions of Python. It helps you easily install different (with conda env create versions of python and switch between them via different environments (with source activate).
You can't use pip to install Python 3. In any case, since you specifically mentioned the Cloud9 IDE, it already comes with both Python 2 and 3. python is symlinked to python2 though, so if you want to call Python 3, you have to type python3 (instead of just python) in the terminal.
From the question it seems like you want to use apt-get instead of pip.
Try this:
sudo apt-get install python3

Categories