How to uninstall Python 2.7 and keep Python 3.4? - python

I think my title is pretty self-explanatory.
I want to uninstall Python 2.7 and keep Python 3.4 intact. Is this easy to do? I found a couple of tutorials about how to uninstall Python, but I don't want to uninstall the entire thing. Also, I am running Spyder (Python 3.6). This should work just fine after I get rid of 2.7, right. The reason I am asking all of this is because I installed pandas_datareader and apparently it went to 2.7, but I really wanted it on 3.4. Finally, I'm assuming, after I unistall 2.7, and run this 'pip install pandas_datareader' it will go to 3.4, right.
I can't seem to control where the install goes.

Instead of using:
pip install <module>
you can use the following to install the module which will install it to python-3.x (as long as python points to your python-3.x directory in your PATH):
python -m pip install <module>
Or alternatively, you can use pip3 to install it directly to python-3.x.
To use pip3, you need to navigate to:
C:\path\to\python\Scripts\pip3
and then run it as:
pip3 install <module>
and it will be installed to python-3.x rather than python-2.x.

If you need to uninstall a Python just use Windows' Add/Remove programs and run the uninstaller for that specific version.
Later versions of Python include PyLauncher (py.exe) and install it to C:\Windows which is always in the path. Use it to control which Python to run and which pip to run if you have several installed. If you use this you won't have to add a specific version of Python or its Scripts directory (where pip.exe is) to your path.
Examples:
py -3 -m pip install <package> # Use latest Python 3 installed.
py -2 -m pip install <package> # Use latest Python 2.
py -3.3 # Run Python 3.3
py -2.7-32 # Run 32-Python 2.7 on a 64-bit OS.
py # Run default Python (usually latest 3.x)
The PY_PYTHON environment variable can override the default.
See also: Python Launcher for Windows

Related

Terminal can't find version of python despite it being installed

I'm trying to install packages on multiple versions of Python. I'm currently running 3.8.8, and 3.11.0.
Following this post Install a module using pip for specific python version
called
python3.11 -m pip install pandas
which results in
File "<stdin>", line 1 python3.11 -m pip install pandas SyntaxError: invalid syntax
This seems to indicate an issue with python, so I double checked that python3.11 is installed.
the python3.11 works in isolation seems to work.
I don't understand why the install command isn't working.
If you’re using Linux try just
python3 —-version
In Windows you may need to add path to folder with installed Python to PATH variable.
Check your environment variables, you could try removing the variables pointing to the 3.8 version until you get the packages you want installed.
You could also try navigating to that python 3.11 installation directly, and executing the python shell from there, then run the command.

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

Both commands give `Requirement already satisfied`

I was trying to install a package called configparser on my local machine. Now, I have both Python 2.7 as well as Python 3.7.4 on my machine. Hence I wanted both versions of configparser to be installed.
I have set the default python version to be Python 3.7.4. So I used this command first:
1.pip3 install configparser:
which gave me requirement satisfied since I already had installed it.
Now, when I use:
2.pip install configparser:
it tells me that requirement is satisfied. But there is now package called configparser in Python 2.
What do I have to do to install the Python2 version of configparser on my machine?
Thanks in advance.
P.S: I use Windows 10, develop in PyCharm.
Also, pip -V gives me:
pip 19.1.1 from c:\users\ymodak\appdata\local\programs\python\python37-32\lib\site-packages\pip (python 3.7)
you need to set the path of your envernnement variable to where python 2 is installed
or do this "path to pip in python2 directory"/pip install "Package"
if you want to configure pip to install packages on python 2 and pip3 to install packages on python3 you need to delete pip in python 3 directory and set both of paths in environnement variable python2 (path to pip in python2 directory) and python3 (path to pip3 in python3 directory)
It used to be that normally, 'python', 'pip' (and also 'ipython' if you use that) would be python 2, and to use python3, you have to explicitly say 'python3', 'pip3', 'ipython3'.
I have noticed recently (on Macs at least) that this is not necessarily still the case... on my Mac after installing 3.6.3, 'python' still points at a 2.7.15 install, but 'ipython' and 'pip' both point at the python3 version. This is just a general note that when mixing versions, you can end up with all kinds of mixed pointers to things - in my case, I have a system python at /usr/bin/python that's 2.7.10, a homebrew-installed python 2 that's 2.7.15, and a 3.6.3 installation installed from the .pkg on the official python site.
However, in every case, usually they are all installed with explicit versioning as well, so you should be able to do e.g.
pip2 install configparser
pip3 install configparser
or even
pip2.7 install configparser
pip3.6 install configparser
pip3.7 install configparser
etc. to point directly at a specific version.
You also can (per one of the other answers) call it as a module from any python version e.g.
/my/path/to/a/custom/python -m pip install configparser
and that will guarantee to put it in whatever path that python requires - on my system, I have two python 2.7 versions installed; pip2.7 points to the one in /usr/local/bin/python2.7, which is a 2.7.15 install. There is no pip2.7.10 - it only goes to the first subversion - but I can manually do
/usr/local/bin/python -m pip list
/usr/bin/python -m pip list
and get two different lists of installed modules, as each one has its own site-packages area. So that is always an option.
in python 3, use
python3 -m pip install configparser
assuming that python3 is keyword to call python 3.7
in python2, use
python -m pip install configparser
assume python is keyword to call python2

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

Does the python.org installer of python come with pip, and how do I use it?

I can download python 2.7.12 from python.org, and all python versions from 2.7.9 onwards are supposed to come with pip, but after installing it, using pip in the terminal does not work.
I am on macOS.
Have I installed pip, and if I have, how do I use it?
Here you have informations about pip:
https://packaging.python.org/installing/
normally python from python.org come with pip, maybe you should just update...
to update from terminal:
pip install -U pip setuptools
After when you need to install package, for example numpy, just do in a terminal:
pip install numpy
more informations here :
https://pip.pypa.io/en/stable/reference/pip_install/
you can also use conda install from anaconda as an alternative of pip :
http://conda.pydata.org/docs/get-started.html
Multiple instances of Python can coexist on your machine. Thus you could have installed Python 2.7.12 yet, when you call Python from terminal, you may be calling an older version.
To know which version you are using, type which python in terminal and look at its path. Then from Python in terminal, type
import sys
print(sys.version)
to get the exact version.
As Dadep says, I would recommend using conda to isolate your invironments if you have to play with multiple Python interpreters. Further conda simplifies 3rd party package installation process beyond doubt.

Categories