Both commands give `Requirement already satisfied` - python

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

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

Should I use pip or pip3? [duplicate]

This question already has answers here:
pip or pip3 to install packages for Python 3?
(10 answers)
Closed 2 years ago.
Eventually, every single time I install a new Linux distribution I do sudo apt-get install python3.
However, once installed I always get confused. python is Python 2.7 and python3 is Python 3.x. But also it appears that pip is for Python 2 and pip3 for Python 3. That said most tutorials I see on Internet always use the traditional pip install even though it is about Python 3.
How should I deal with this? Should I simply continue to put this annoying 3 every time I use Python (pip3, ipython3, python3...)? In most of my lectures I read that creating a symlink python->python3 is a bad practice. Is that correct?
Use python3 -m pip or python -m pip. That will use the correct pip for the python version you want. This method is mentioned in the pip documentation:
python -m pip executes pip using the Python interpreter you specified as python. So /usr/bin/python3.7 -m pip means you are executing pip for your interpreter located at /usr/bin/python3.7.
Symlinking python->python3 is a bad idea because some programs might rely on python being python 2. Though, I have seen some Dockerfiles symlink python->python3, like TensorFlow's CPU dockerfile (it's less of an issue in a Docker image). Coincidentally, that same Dockerfile uses the python3 -m pip install syntax that I recommend.
creating a symlink python->python3 is a bad practice. Is that correct?
Sometimes. Some OSs (looking at you, macOS) deeply rely on python pointing to a Python 2 interpreter for internal tools and tasks. Deleting the shipped Python 2 interpreter (or aliasing python to a Python 3 interpreter) will break stuff. How to uninstall Python 2.7 on a Mac OS X 10.6.4?
Whether the correct command for Python 3 is pip or pip3 or (say) gaschplutzga depends on a number of factors.
If you only have Python 3, and you have a command named pip, that's probably safe to use. Going forward, this will be the simple, obvious, safe answer in more and more places.
If you have both, and there is a command called pip3 installed on your system, probably that's the correct one to use.
More generally, you can go through your PATH and look for commands with suitable names. On Unix-like systems with a POSIX-compatible shell, try the commands command -V pip3 and command -V pip. (On Windows systems, maybe try where pip3 and where pip, or pray to whatever dark deity informed your choice of operating system.)
If you receive output like
/opt/random/nonstandard/whoa/pip
/usr/local/bin/pip
/usr/bin/pip
you can try each of these in turn with the full path and adding the --version option to have them identify themselves. When you specify the full path, you are bypassing the system's PATH mechanism entirely. For example,
/opt/random/nonstandard/whoa/pip --version
might identify itself as belonging to Python version 3.2.1. If that's the one you want, and it's at the top of your PATH, you can simply rely on the PATH to give you this version when you type just pip. If not, perhaps you can shuffle your PATH (but understand that this changes the resolution order for all commands in the directory whose position you change) or create a simple alias or wrapper which bypasses the PATH for this particular command in your personal account. On Unix-like systems with a POSIX-compatible shell, this might look like
alias pip=/opt/random/nonstandard/whoa/pip
(to persist this across sessions, you'd add this to your .profile or similar - for Bash, try .bash_profile if it exists; for Zsh, try .zshrc. The full scoop for each shell is more complicated than I can squeeze into these narrow parentheses); on Windows, you might be able to control this by setting the environment variable PY_PYTHON, but there's a huge can of worms behind that "might".
Some sites and OSes / distros have additional wrappers or conventions which introduce additional options; if you use a specific package manager, perhaps also study its documentation. (One common example is Anaconda, though I don't believe it affects the naming or location of pip specifically.)
Use virtual environments, then pip would be associated with the python used to create that virtual environment. Whether you use pip or pip3, it will be equivalent to python3 -m pip as mentioned in jakub's answer. Also, given that Python 2.7 is already EOL (which means you will most likely work with Python 3) and that pip install-ing things onto the system packages should be avoided, then a virtual environment would be helpful here.
For example, using pipenv:
$ pipenv --python=/usr/local/opt/python#3.8/bin/python3
$ pipenv shell
Launching subshell in virtual environment...
(TEMP) $ pip --version
pip 20.2.3 from /Users/me/.venvs/temp2-SbXvZiFd/lib/python3.8/site-packages/pip (python 3.8)
(TEMP) $ pip3 --version
pip 20.2.3 from /Users/me/.venvs/temp2-SbXvZiFd/lib/python3.8/site-packages/pip (python 3.8)
For example, using venv:
$ python3.8 -m venv .venv
$ source .venv/bin/activate
(.venv) $ pip --version
pip 20.2.3 from /Users/me/temp2/.venv/lib/python3.8/site-packages/pip (python 3.8)
(.venv) $ pip3 --version
pip 20.2.3 from /Users/me/temp2/.venv/lib/python3.8/site-packages/pip (python 3.8)
The virtual environment takes care of making sure pip or pip3 in this env refers to the pip from the correct Python version. You can then happily follow tutorials that still use pip install something (unless of course that tutorial refers to a Python 2.7 or a system-wide installation).
You can install pip through pip3 and this should resolve this issue.
$ pip --version
pip 19.0.3 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)
Notice that pip here is of Python 2.7 (in this example).
You can then force pip3 of Python 3.X to install pip under itself.
$ sudo pip3 install pip --upgrade
Installing collected packages: pip
Found existing installation: pip 8.1.1
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Successfully installed pip-19.0.3
Once you check this again, it should reference Python 3.X so you don't have to deal with
what is what.
$ pip --version
pip 19.0.3 from /usr/local/lib/python3.5/dist-packages/pip (python 3.5)
I doubt you'll want to use Python 2 after this, but if you do happen to work with Python 2 code, you can create a virtual environment to access those commands again. Otherwise, you won't have to worry about the pip or pip3 distinction after this.
Not really a duplicate of this question, but this helped me suggest this answer: Can pip (python2) and pip3 (python3) coexist?
Pip is for python version less than 3. and pip3 is used when you want to install packages for python version 3 or higher.

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

How to uninstall Python 2.7 and keep Python 3.4?

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

How to use pip3 for python 3.6 instead of python 3.5?

I'm using Kali dist so I have already installed Python 2.7, 3.5 and 3.6. Commands 'python' and 'pip' are associated with Python 2.7. But the 'python3' uses Python 3.6 while pip3 is installing packages for Python 3.5.
When I tried to create an venv:
pip3 -p python3.6 virtualenv myenv
I've got an error:
no such option: -p
How can I associate pip3 with Python 3.6 instead of Python 3.5?
Your version of pip is inextricably linked to your version of Python, you cannot tell pip "use this Python" or "use that Python." If you have a version mismatch between pip3 (using Python 3.X) and python3 (being Python 3.Y), it means your problem is with multiple overlapping distributions of Python and a weirdly configured $PATH.
If you run pip3 --version it will tell you the site-packages directory and Python version number that pip3 is associated with.
If you run python3 and then execute >>> import site; site.getsitepackages(), it should print the site-packages directory your python3 is using.
If these do not match, you've got path problems and you'll need to post more information about what operating system you're on, what Python distributions you're using, and how you installed them.
Update/Summary of Comment Thread: Original poster had a distribution-bundled Python 3.6 installed alongside a self-installed Python 3.5. The pip3 on their path was associated with Python 3.6 (system Python), while the command python3 was associated with Python 3.5 (their self-installed Python). Resolution:
Run which -a python3 to find Python 3.5. Add the location of Python 3.5 to your $PATH. (Do it in .profile or .bash_profile to make it permanent.)
You can explicitly run the pip3 script with a particular Python version, by prefixing it with the appropriate python3.x command:
ldo#theon:~> pip3 --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.6)
ldo#theon:~> python3.5 $(which pip3) --version
pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
To install a package in the same version location that's associated with the version associated with python3, use the following:
python3 -m pip install [package]
to pick a specific version that you'd like your package to be associated with (so you're not guessing with the above):
python3.5 -m pip install [package]
python3.7 -m pip install [package]
Also, be careful because pip3 can point to different locations and may not necessarily match the location of the python3 binary. I just found that out when I did a pip3 install and it failed to import when running python3.
You can also explicitly call pip3.5, pip3.7, etc, but honestly I prefer using the python[version] -m pip install [package] method because I know that it will install the package in the location associated with whatever python3.x binary I'm using.
When you install Python3, see if there's a comment such as this:
Ignoring ensurepip failure: pip 9.0.1 requires SSL/TLS
You might see entries like this in the log:
INFO: Can't locate Tcl/Tk libs and/or headers
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_bz2 _dbm _gdbm
_lzma _sqlite3 _ssl
_tkinter readline
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
atexit pwd time
This answer describes using ensurepip
https://stackoverflow.com/a/38250442/1607937
Also see this regarding openssl
"SSL module in Python is not available" when installing package with pip3
If you want to use only one version of python you sould probably create an alias. Add this line at the end of your ~/.bashrc flie:
alias pip='python3.6 -m pip'
Then, run source ~/.bashrc, and now pip --version will show something like:
pip xx.x.x from /usr/lib/python3/dist-packages/pip (python 3.6)
you can update line #1 from /usr/bin/pip3 to #!/usr/bin/python3.8 as below
#!/usr/bin/python3.8
# GENERATED BY DEBIAN
import sys
# Run the main entry point, similarly to how setuptools does it, but because
# we didn't install the actual entry point from setup.py, don't use the
# pkg_resources API.
from pip import main
if __name__ == '__main__':
sys.exit(main())
First find the right version of python you want to use:
$ which -a python3.6
/usr/bin/python3.6
then invoke that instance of python directly, e.g.
$ /usr/bin/python3.6 -m venv
usage: venv [-h] [--system-site-packages] [--symlinks | --copies] [--clear] [--upgrade] [--without-pip] [--prompt PROMPT] ENV_DIR [ENV_DIR ...]
venv: error: the following arguments are required: ENV_DIR
Next, pip does not create virtual environments. The module venv does. Read the venv documentation for recommended usage. In your case, you might want:
$ /usr/bin/python3.6 -m venv myenv

Categories