-->

How to find my IDLE's Python, then apply pip u

2019-05-11 09:56发布

问题:

I have two python 2.7's of interest:

  • version with IDLE that came from https://www.python.org/downloads/
  • anaconda 2.7 installation

I use MacOS. (I understand I'm overdue to switch to Python 3)

I'd like to apply pip install --upgrade PackageName to a package that IDLE's Python uses, but when I type that in my terminal it tries to apply it to my anaconda version.

Is there a way I can find my IDLE's python, point to it, then apply the pip command to it?

Here's what I have:

$ which python

/Users/david/anaconda2/bin/python

$ which -a python

/Users/david/anaconda2/bin/python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
/usr/local/bin/python
/usr/bin/python

update: Per this answer I've opened IDLE and typed

import sys
sys.executable

and it returned /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python.

I then opened a terminal and entered /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -m pip install --upgrade skyfield

and I received the following:

Cache entry deserialization failed, entry ignored
Could not fetch URL https://pypi.python.org/simple/skyfield/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Requirement already up-to-date: skyfield in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Could not fetch URL https://pypi.python.org/simple/jplephem/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Requirement already up-to-date: jplephem>=2.3 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from skyfield)
Could not fetch URL https://pypi.python.org/simple/sgp4/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Requirement already up-to-date: sgp4>=1.4 in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from skyfield)
Could not fetch URL https://pypi.python.org/simple/numpy/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) - skipping
Requirement already up-to-date: numpy in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages (from skyfield)

I close IDLE then reopen it, then type

import skyfield
skyfield.__version__

and still it's only 1.0

No update.

Skyfield is currently on version 1.10 https://rhodesmill.org/skyfield/installation.html and I upgraded my anaconda version successfully today to 1.10 using pip install --upgrade skyfield

回答1:

To find your IDLE's version, open IDLE, the go to the help section in the menubar. Hit About IDLE, and there is your python version!

To verify that your pip is the version you want, all you have to do is type this:

pip -V

It will give you something like this on Windows (MAC will be similar):

pip 19.0.2 from c:\python27\lib\site-packages\pip (python 2.7)

In the case that is the incorrect path, just get get-pip.py then run it using the python version you want it to compile to like this:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py

To use the pip you wish to use, type this:

/usr/local/bin/pip install foo


回答2:

In the IDLE shell, enter import sys; sys.executable and you will see full path to the python that is executing IDLE.

To install to that specific executable, enter in Terminal path/to/python.exe -m pip install ....