2019: ⚠️easy_install has been deprecated. Check Method #2 below for preferred installation!
I made a gif, coz. why not?
Details:
⚡️ OK, I read the solutions given above, but here’s an EASY solution to install pip.
MacOS comes with Python installed. But to make sure that you have Python installed open the terminal and run the following command.
python --version
If this command returns a version number that means Python exists. Which also means that you already have access to easy_install considering you are using macOS/OSX.
ℹ️ Now, all you have to do is run the following command.
sudo easy_install pip
After that, pip will be installed and you’ll be able to use it for installing other packages.
Let me know if you have any problems installing pip this way.
You can install it through Homebrew on OS X. Why would you install Python with Homebrew?
The version of Python that ships with OS X is great for learning but
it’s not good for development. The version shipped with OS X may be
out of date from the official current Python release, which is
considered the stable production version. (source)
Homebrew is something of a package manager for OS X. Find more details on the Homebrew page. Once Homebrew is installed, run the following to install the latest Python, Pip & Setuptools:
I’m surprised no-one has mentioned this – since 2013, python itself is capable of installing pip, no external commands (and no internet connection) required.
sudo -H python -m ensurepip
This will create a similar install to what easy_install would.
WARNING: for a modern macOS (2019) this can install python3, and for python2 you really need to do: brew install python@2
Install python3:
brew install python3
UPDATE: Python 3
If you install python3, pip will be installed automatically.
brew install python3
NEW 2019: now to use pip version 3, use pip3 , or you can execute: python3, to use version 3. When you install packages with pip3 they will be separated from python2.
OLD: You need only to upgrade pip, but before that you need create a virtual environment to work with Python 3. You can use a project folder or any folder:
downloading get-pip.py. Be sure to do this by following a trusted link since you will have to run the script as root.
call sudo python get-pip.py
The main advantage of that solution is that it install pip for the python version that has been used to run get-pip.py, which means that if you use the default OS X installation of python to run get-pip.py you will install pip for the python install from the system.
Most solutions that use a package manager (homebrew or macport) on OS X create a redundant installation of python in the environment of the package manager which can create inconsistencies in your system since, depending on what you are doing, you may call one installation of python instead of another.
Installing a separate copy of Python is a popular option, even though Python already comes with MacOS. You take on the responsibility to make sure you’re using the copy of Python you intend. But, the benefits are having the latest Python release and some protection from hosing your system if things go badly wrong.
brew update
brew install python # or brew install python3
Now confirm that we’re working with our newly installed Python:
ls -lh `which python`
…should show a symbolic link to a path with “Cellar” in it like:
lrwxr-xr-x 1 chris admin 35B Dec 2 13:40 /usr/local/bin/python -> ../Cellar/python/2.7.8_2/bin/python
Pip should be installed along with Python. You might want to upgrade it by typing:
pip install --upgrade pip
Now you’re ready to install any of the 50,000+ packages on PyPI.
Other Notes
Formerly, I’ve used get-pip.py to install pip. But, the docs warn that get-pip.py does not coordinate with package managers and may leave your system in an inconsistent state. Anyway, there’s no need, given that pip is now included with Python as of 2.7.9.
Note that pip isn’t the only package manager for Python. There’s also easy_install. It’s no good to mix the two, so don’t do it.
Finally, if you have both Python 2 and 3 installed, pip will point to whichever Python you installed last. Get in the habit of explicitly using either pip2 or pip3, so you’re sure which Python is getting the new library.
On the recent version (from Yosemite or El Capitan I believe… at least from Sierra onward), you need to run brew postinstall python3 after brew install python3 if you use homebrew.
So,
brew install python3 # this only installs python
brew postinstall python3 # this installs pip
On 1st March 2018 the python formula will be upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link –force). We will maintain python2, python3 and python@3 aliases.
So to install Python 3, run the following command:
brew install python3
Then, the pip is installed automatically, and you can install any package by pip install <package>.
Then update your PATH to include py27-pip bin directory (you can add this in ~/.bash_profile
PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
If you want to install pip without the need for sudo, which is always frustrating when trying to install packages globally, install pip in your local folder /usr/local like this:
I recommend Anaconda to you. It’s the leading open data science platform powered by Python. There are many basic packages installed. Anaconda (conda) comes with its own installation of pip.
I’m trying to install version 1.2.2 of the MySQL_python adaptor, using a fresh virtualenv created with the --no-site-packages option. The current version shown in PyPi is 1.2.3. Is there a way to install the older version? I found an article stating that this should do it:
pip install MySQL_python==1.2.2
When installed, however, it still shows MySQL_python-1.2.3-py2.6.egg-info in the site packages. Is this a problem specific to this package, or am I doing something wrong?
First, I see two issues with what you’re trying to do. Since you already have an installed version, you should either uninstall the current existing driver or use pip install -I MySQL_python==1.2.2
However, you’ll soon find out that this doesn’t work. If you look at pip’s installation log, or if you do a pip install -Iv MySQL_python==1.2.2 you’ll find that the PyPI URL link does not work for MySQL_python v1.2.2. You can verify this here: http://pypi.python.org/pypi/MySQL-python/1.2.2
The download link 404s and the fallback URL links are re-directing infinitely due to sourceforge.net’s recent upgrade and PyPI’s stale URL.
So to properly install the driver, you can follow these steps:
Since this appeared to be a breaking change introduced in version 10 of pip, I downgraded to a compatible version:
pip install 'pip<10'
This command tells pip to install a version of the module lower than version 10. Do this in a virutalenv so you don’t screw up your site installation of Python.
I recently ran into an issue when using pip‘s -I flag that I wanted to document somewhere:
-I will not uninstall the existing package before proceeding; it will just install it on top of the old one. This means that any files that should be deleted between versions will instead be left in place. This can cause weird behavior if those files share names with other installed modules.
For example, let’s say there’s a package named package. In one of packages files, they use import datetime. Now, in package@2.0.0, this points to the standard library datetime module, but in package@3.0.0, they added a local datetime.py as a replacement for the standard library version (for whatever reason).
Now lets say I run pip install package==3.0.0, but then later realize that I actually wanted version 2.0.0. If I now run pip install -I package==2.0.0, the old datetime.py file will not be removed, so any calls to import datetime will import the wrong module.
In my case, this manifested with strange syntax errors because the newer version of the package added a file that was only compatible with Python 3, and when I downgraded package versions to support Python 2, I continued importing the Python-3-only module.
Based on this, I would argue that uninstalling the old package is always preferable to using -I when updating installed package versions.
There are 2 ways you may install any package with version:-
A). pip install -Iv package-name == versionB). pip install -v package-name == version
For A
Here, if you’re using -I option while installing(when you don’t know if the package is already installed) (like ‘pip install -Iv pyreadline == 2.* ‘or something), you would be installing a new separate package with the same existing package having some different version.
For B
At first, you may want to check for no broken requirements.
pip check
2.and then see what’s already installed by
pip list
3.if the list of the packages contain any package that you wish to install with specific version then the better option is to uninstall the package of this version first, by
pip uninstall package-name
4.And now you can go ahead to reinstall the same package with a specific version, by
pip install -v package-name==version
e.g. pip install -v pyreadline == 2.*
Downloading/unpacking Fabric==1.2.0(from-r ../testing/requirements.txt (line 3))Running setup.py egg_info for package Fabric
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no files found matching 'fabfile.py'Downloading/unpacking South==0.7.3(from-r ../testing/requirements.txt (line 8))Running setup.py egg_info for package South....
I got some output that seems to indicate that the installation is fine
Downloading/unpacking Fabric==1.2.0 (from -r ../testing/requirements.txt (line 3))
Running setup.py egg_info for package Fabric
warning: no previously-included files matching '*' found under directory 'docs/_build'
warning: no files found matching 'fabfile.py'
Downloading/unpacking South==0.7.3 (from -r ../testing/requirements.txt (line 8))
Running setup.py egg_info for package South
....
But later check revealed none of the package is installed properly. I cannot import the package, and none is found in the site-packages directory of my virtualenv. So what went wrong?
--no-index – Ignore package index (only looking at --find-links URLs instead).
-f, --find-links <URL> – If a URL or path to an html file, then parse for links to archives.
If a local path or file:// URL that’s a directory, then look for archives in the directory listing.
I’ve read the above, realize this is an old question, but it’s totally unresolved and still at the top of my google search results so here’s an answer that works for everyone:
Here, -r is short form of --requirement and it asks the pip to install from the given requirements file.
pip will start installation only after checking the availability of all listed items in the requirements file and it won’t start installation even if one requirement is unavailable.
One workaround to install the available packages is installing listed packages one by one. Use the following command for that. A red color warning will be shown to notify you about the unavailable packages.
cat requirements.txt | xargs -n 1 pip install
To ignore comments (lines starting with a #) and blank lines, use:
I work with a lot of systems that have been mucked by developers “following directions they found on the internet”. It is extremely common that your pip and your python are not looking at the same paths/site-packages. For this reason, when I encounter oddness I start by doing this:
It is unhappy because pip is (python3.6 and) using /usr/local/lib/python3.6/site-packages while python is (python2.7 and) using /usr/local/lib/python2.7/site-packages
When I want to make sure I’m installing requirements to the right python, I do this:
$ which -a python python2 python3
/usr/local/bin/python
/usr/bin/python
/usr/local/bin/python2
/usr/local/bin/python3
$ /usr/bin/python -m pip install -r requirements.txt
You’ve heard, “If it ain’t broke, don’t try to fix it.” The DevOps version of that is, “If you didn’t break it and you can work around it, don’t try to fix it.”
(test_env) $ ls /tmp/behave/setup.py
/tmp/behave/setup.py
从git repo安装python包
(test_env) $ cd /tmp/behave && pip install .
running install
...Installed/private/tmp/test_env/lib/python2.7/site-packages/enum34-1.0-py2.7.eggFinished processing dependencies for behave==1.2.5a1
如果我们从 /tmp
>>>import pip
>>> sorted(["%s==%s"%(i.key, i.version)for i in pip.get_installed_distributions()])['behave==1.2.5a1','enum34==1.0','parse-type==0.3.4','parse==1.6.4','six==1.6.1']>>>import os
>>> os.getcwd()'/private/tmp'
如果我们从 /tmp/behave
>>>import pip
>>> sorted(["%s==%s"%(i.key, i.version)for i in pip.get_installed_distributions()])['enum34==1.0','parse-type==0.3.4','parse==1.6.4','six==1.6.1']>>>import os
>>> os.getcwd()'/private/tmp/behave'
This solution applies to the system scope or to a virtual environment scope, and covers packages installed by setuptools, pip and (god forbid) easy_install.
My use case
I added the result of this call to my flask server, so when I call it with http://example.com/exampleServer/environment I get the list of packages installed on the server’s virtualenv. It makes debugging a whole lot easier.
Caveats
I have noticed a strange behaviour of this technique – when the Python interpreter is invoked in the same directory as a setup.py file, it does not list the package installed by setup.py.
Steps to reproduce:
Create a virtual environment
$ cd /tmp
$ virtualenv test_env
New python executable in test_env/bin/python
Installing setuptools, pip...done.
$ source test_env/bin/activate
(test_env) $
I say “surprisingly” because the package install tool is the exact place one would expect to find this functionality, although not under the name ‘freeze’ but python packaging is so weird, that I am flabbergasted that this tool makes sense. Pip 0.8.2, Python 2.7.
Which seems to be syntactic sugar for “pip freeze”. It will list all of the modules particular to your installation or virtualenv, along with their version numbers. Unfortunately it does not display the current version number of any module, nor does it wash your dishes or shine your shoes.
As of pip 10, the accepted answer will no longer work. The development team has removed access to the get_installed_distributions routine. There is an alternate function in the setuptools for doing the same thing. Here is an alternate version that works with pip 10:
import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
print(installed_packages_list)
Please let me know if it will or won’t work in previous versions of pip, too.
I normally use pip list to get a list of packages (with version).
This works in a virtual environment too, of course. To show what’s installed in only the virtual environment (not global packages), use pip list --local.
Here’s documentation showing all the available pip list options, with several good examples.
import sys
import os
import shutil
import pkgutil
import importlib
import collections
if sys.version_info.major ==2:raiseNotImplementedError('CPython 2 is not supported yet')def main():# name this file (module)
this_module_name = os.path.basename(__file__).rsplit('.')[0]# dict for loaders with their modules
loaders = collections.OrderedDict()# names`s of build-in modulesfor module_name in sys.builtin_module_names:# find an information about a module by name
module = importlib.util.find_spec(module_name)# add a key about a loader in the dict, if not exists yetif module.loader notin loaders:
loaders[module.loader]=[]# add a name and a location about imported module in the dict
loaders[module.loader].append((module.name, module.origin))# all available non-build-in modulesfor module_name in pkgutil.iter_modules():# ignore this moduleif this_module_name == module_name[1]:continue# find an information about a module by name
module = importlib.util.find_spec(module_name[1])# add a key about a loader in the dict, if not exists yet
loader = type(module.loader)if loader notin loaders:
loaders[loader]=[]# add a name and a location about imported module in the dict
loaders[loader].append((module.name, module.origin))# pretty print
line ='-'* shutil.get_terminal_size().columns
for loader, modules in loaders.items():print('{0}\n{1}: {2}\n{0}'.format(line, len(modules), loader))for module in modules:print('{0:30} | {1}'.format(module[0], module[1]))if __name__ =='__main__':
main()
This solution is primary based on modules importlib and pkgutil and work with CPython 3.4 and CPython 3.5, but has no support for the CPython 2.
Explanation
sys.builtin_module_names – names all built-in modules (look my answer here)
pkgutil.iter_modules() – returns an information about all available modules
importlib.util.find_spec() – returns an information about importing module, if exists
BuiltinImporter – an importer for built-in modules (docs)
SourceFileLoader – an importer for a standard Python module (by default has extension *.py) (docs)
ExtensionFileLoader – an importer for modules as shared library (written on the C or C++)
Full code
import sys
import os
import shutil
import pkgutil
import importlib
import collections
if sys.version_info.major == 2:
raise NotImplementedError('CPython 2 is not supported yet')
def main():
# name this file (module)
this_module_name = os.path.basename(__file__).rsplit('.')[0]
# dict for loaders with their modules
loaders = collections.OrderedDict()
# names`s of build-in modules
for module_name in sys.builtin_module_names:
# find an information about a module by name
module = importlib.util.find_spec(module_name)
# add a key about a loader in the dict, if not exists yet
if module.loader not in loaders:
loaders[module.loader] = []
# add a name and a location about imported module in the dict
loaders[module.loader].append((module.name, module.origin))
# all available non-build-in modules
for module_name in pkgutil.iter_modules():
# ignore this module
if this_module_name == module_name[1]:
continue
# find an information about a module by name
module = importlib.util.find_spec(module_name[1])
# add a key about a loader in the dict, if not exists yet
loader = type(module.loader)
if loader not in loaders:
loaders[loader] = []
# add a name and a location about imported module in the dict
loaders[loader].append((module.name, module.origin))
# pretty print
line = '-' * shutil.get_terminal_size().columns
for loader, modules in loaders.items():
print('{0}\n{1}: {2}\n{0}'.format(line, len(modules), loader))
for module in modules:
print('{0:30} | {1}'.format(module[0], module[1]))
if __name__ == '__main__':
main()
Warning: Adam Matan discourages this use in pip > 10.0. Also, read @sinoroc’s comment below
This was inspired by Adam Matan’s answer (the accepted one):
import tabulate
try:
from pip import get_installed_distributions
except:
from pip._internal.utils.misc import get_installed_distributions
tabpackages = []
for _, package in sorted([('%s %s' % (i.location, i.key), i) for i in get_installed_distributions()]):
tabpackages.append([package.location, package.key, package.version])
print(tabulate.tabulate(tabpackages))
which lets you then easily discern which packages you installed with and without sudo.
A note aside: I’ve noticed that when I install a packet once via sudo and once without, one takes precedence so that the other one isn’t being listed (only one location is shown). I believe that only the one in the local directory is then listed. This could be improved.
Hidden in the documentation source directory in 2.5 is a small script that lists all available modules for a Python installation.
Pros:
uses only imp, sys, os, re, time
designed to run on Python 1.5.2 and newer
the source code is really compact, so you can easy tinkering with it, for example to pass an exception list of buggy modules (don’t try to import them)
import pkgutil
__version__ ='0.1.1'def get_ver(name):try:return str(__import__(name).__version__)except:returnNonedef lambda_handler(event, context):return{'statusCode':200,'body':[{'path': m.module_finder.path,'name': m.name,'version': get_ver(m.name),}for m in list(pkgutil.iter_modules())#if m.module_finder.path == "/var/runtime" # Uncomment this if you only care about a certain path],}
I needed to find the specific version of packages available by default in AWS Lambda. I did so with a mashup of ideas from this page. I’m sharing it for posterity.
import pkgutil
__version__ = '0.1.1'
def get_ver(name):
try:
return str(__import__(name).__version__)
except:
return None
def lambda_handler(event, context):
return {
'statusCode': 200,
'body': [{
'path': m.module_finder.path,
'name': m.name,
'version': get_ver(m.name),
} for m in list(pkgutil.iter_modules())
#if m.module_finder.path == "/var/runtime" # Uncomment this if you only care about a certain path
],
}
What I discovered is that the provided boto3 library was way out of date and it wasn’t my fault that my code was failing. I just needed to add boto3 and botocore to my project. But without this I would have been banging my head thinking my code was bad.
Good news! Python 3.4 (released March 2014) and Python 2.7.9 (released December 2014) ship with Pip. This is the best feature of any Python release. It makes the community’s wealth of libraries accessible to everyone. Newbies are no longer excluded from using community libraries by the prohibitive difficulty of setup. In shipping with a package manager, Python joins Ruby, Node.js, Haskell, Perl, Go—almost every other contemporary language with a majority open-source community. Thank you, Python.
If you do find that pip is not available when using Python 3.4+ or Python 2.7.9+, simply execute e.g.:
And, alas for everyone using Python 2.7.8 or earlier (a sizable portion of the community). There’s no plan to ship Pip to you. Manual instructions follow.
Python 2 ≤ 2.7.8 and Python 3 ≤ 3.3
Flying in the face of its ‘batteries included’ motto, Python ships without a package manager. To make matters worse, Pip was—until recently—ironically difficult to install.
This installs the pip package, which (in Windows) contains …\Scripts\pip.exe that path must be in PATH environment variable to use pip from the command line (see the second part of ‘Alternative Instructions’ for adding it to your PATH,
Alternative instructions
The official documentation tells users to install Pip and each of its dependencies from source. That’s tedious for the experienced and prohibitively difficult for newbies.
For our sake, Christoph Gohlke prepares Windows installers (.msi) for popular Python packages. He builds installers for all Python versions, both 32 and 64 bit. You need to:
For me, this installed Pip at C:\Python27\Scripts\pip.exe. Find pip.exe on your computer, then add its folder (for example, C:\Python27\Scripts) to your path (Start / Edit environment variables). Now you should be able to run pip from the command line. Try installing a package:
pip install httpie
There you go (hopefully)! Solutions for common problems are given below:
Proxy problems
If you work in an office, you might be behind an HTTP proxy. If so, set the environment variables http_proxy and https_proxy. Most Python applications (and other free software) respect these. Example syntax:
If you’re really unlucky, your proxy might be a Microsoft NTLM proxy. Free software can’t cope. The only solution is to install a free software friendly proxy that forwards to the nasty proxy. http://cntlm.sourceforge.net/
Unable to find vcvarsall.bat
Python modules can be partly written in C or C++. Pip tries to compile from source. If you don’t have a C/C++ compiler installed and configured, you’ll see this cryptic error message.
copy the uncompressed pip folder content into C:\Python2x\ folder (don’t copy the whole folder into it, just the content), because python command doesn’t work outside C:\Python2x folder and then run: python setup.py install
Add your python C:\Python2x\Scripts to the path
You are done.
Now you can use pip install package to easily install packages as in Linux :)
1) If you have installed Python 3.4 or later, pip is included with Python and should already be working on your system.
2) If you are running a version below Python 3.4 or if pip was not installed with Python 3.4 for some reason, then you’d probably use pip’s official installation script get-pip.py. The pip installer now grabs setuptools for you, and works regardless of architecture (32-bit or 64-bit).
To install or upgrade pip, securely download get-pip.py.
Then run the following (which may require administrator access):
python get-pip.py
To upgrade an existing setuptools (or distribute), run pip install -U setuptools
I’ll leave the two sets of old instructions below for posterity.
OLD Answers:
For Windows editions of the 64 bit variety – 64-bit Windows + Python used to require a separate installation method due to ez_setup, but I’ve tested the new distribute method on 64-bit Windows running 32-bit Python and 64-bit Python, and you can now use the same method for all versions of Windows/Python 2.7X:
Download distribute – I threw mine in C:\Python27\Scripts (feel free to create a Scripts directory if it doesn’t exist.
Open up a command prompt (on Windows you should check out conemu2 if you don’t use PowerShell) and change (cd) to the directory you’ve downloaded distribute_setup.py to.
Run distribute_setup: python distribute_setup.py (This will not work if your python installation directory is not added to your path – go here for help)
Change the current directory to the Scripts directory for your Python installation (C:\Python27\Scripts) or add that directory, as well as the Python base installation directory to your %PATH% environment variable.
Install pip using the newly installed setuptools: easy_install pip
The last step will not work unless you’re either in the directory easy_install.exe is located in (C:\Python27\Scripts would be the default for Python 2.7), or you have that directory added to your path.
Download ez_setup.py and run it; it will download the appropriate .egg file and install it for you. (Currently, the provided .exe installer does not support 64-bit versions of Python for Windows, due to a distutils installer compatibility issue.
After this, you may continue with:
Add c:\Python2x\Scripts to the Windows path (replace the x in Python2x with the actual version number you have installed)
Open a new (!) DOS prompt. From there run easy_install pip
If paranoid, inspect file to confirm it isn’t malicious
(must b64 decode).
Open a console in the download folder as Admin and run
get-pip.py. Alternatively, right-click its icon in Explorer and choose the “run as Admin…”.
The new binaries pip.exe (and the deprecated easy_install.exe) will be found in the "%ProgramFiles%\PythonXX\Scripts" folder (or similar), which is often not in your PATH variable. I recommend adding it.
Python 3.4, which was released in March 2014, comes with pip included: http://docs.python.org/3.4/whatsnew/3.4.html
So, since the release of Python 3.4, the up-to-date way to install pip on Windows is to just install Python.
The recommended way to use it is to call it as a module, especially with multiple python distributions or versions installed, to guarantee packages go to the correct place: python -m pip install --upgrade packageXYZ
When I have to use Windows, I use ActivePython, which automatically adds everything to your PATH and includes a package manager called PyPM which provides binary package management making it faster and simpler to install packages.
pip and easy_install aren’t exactly the same thing, so there are some things you can get through pip but not easy_installand vice versa.
My recommendation is that you get ActivePython Community Edition and don’t worry about the huge hassle of getting everything set up for Python on Windows. Then, you can just use pypm.
In case you want to use pip you have to check the PyPM option in the ActiveState installer. After installation you only need to logoff and log on again, and pip will be available on the commandline, because it is contained in the ActiveState installer PyPM option and the paths have been set by the installer for you already. PyPM will also be available, but you do not have to use it.
The up-to-date way is to use Windows’ package manager Chocolatey.
Once this is installed, all you have to do is open a command prompt and run the following the three commands below, which will install Python 2.7, easy_install and pip. It will automatically detect whether you’re on x64 or x86 Windows.
cinst python
cinst easy.install
cinst pip
All of the other Python packages on the Chocolatey Gallery can be found here.
Python 2.7.9 and later (on the Python 2 series), and Python 3.4 and later include pip by default, so you may have pip already.
If you don’t, run this one line command on your prompt (which may require administrator access):
python -c "exec('try: from urllib2 import urlopen \nexcept: from urllib.request import urlopen');f=urlopen('https://bootstrap.pypa.io/get-pip.py').read();exec(f)"
It will install pip. If Setuptools is not already installed, get-pip.py will install it for you too.
As mentioned in comments, the above command will download code from the Pip source code repository at GitHub, and dynamically run it at your environment. So be noticed that this is a shortcut of the steps download, inspect and run, all with a single command using Python itself. If you trust Pip, proceed without doubt.
Be sure that your Windows environment variable PATH includes Python’s folders (for Python 2.7.x default install: C:\Python27 and C:\Python27\Scripts, for Python 3.3x: C:\Python33 and C:\Python33\Scripts, and so on).
hg clone https://bitbucket.org/tarek/distribute
cd distribute
hg checkout 0.6.27
rem optionally, comment out tag_build and tag_svn_revision in setup.cfg
msvc-build-launcher.cmd
python setup.py bdist_win32
cd ..
echo build is in distribute\dist
建造 pip
git clone https://github.com/pypa/pip.git
cd pip
git checkout 1.1
python setup.py bdist_win32
cd ..
echo build is in pip\dist
I’ve built Windows installers for both distribute and pip here (the goal being to use pip without having to either bootstrap with easy_install or save and run Python scripts):
On Windows, simply download and install first distribute, then pip from the above links. The distribute link above does contain stub .exe installers, and these are currently 32-bit only. I haven’t tested the effect on 64-bit Windows.
Building on Windows
The process to redo this for new versions is not difficult, and I’ve included it here for reference.
Building distribute
In order to get the stub .exe files, you need to have a Visual C++ compiler (it is apparently compilable with MinGW as well)
hg clone https://bitbucket.org/tarek/distribute
cd distribute
hg checkout 0.6.27
rem optionally, comment out tag_build and tag_svn_revision in setup.cfg
msvc-build-launcher.cmd
python setup.py bdist_win32
cd ..
echo build is in distribute\dist
Building pip
git clone https://github.com/pypa/pip.git
cd pip
git checkout 1.1
python setup.py bdist_win32
cd ..
echo build is in pip\dist
For latest Python Download – I have python 3.6 on windows. You don’t have to wonder everything you need is there , take a breath i will show you how to do it.
make sure where you install python for me its was in the following directory
Now , lets add python and pip into environment variable path settings
if you are on windows, so that typing pip or python anywhere call
python aor pip from where they are installed.
So, PIP is found under the folder in above screen “SCRIPTS”
Lets add Python and PIP in environment variable path.
Almost Done , Let test with CMD to install goole package using pip.
To install pip globally on Python 2.x, easy_install appears to be the best solution as Adrián states.
However the installation instructions for pip recommend using virtualenv since every virtualenv has pip installed in it automatically. This does not require root access or modify your system Python installation.
Installing virtualenv still requires easy_install though.
2018 update:
Python 3.3+ now includes the venv module for easily creating virtual environments like so:
python3 -m venv /path/to/new/virtual/environment
See documentation for different platform methods of activating the environment after creation, but typically one of:
New python executable in myvirtualenv\Scripts\python.exe
Installing setuptools....................................done.Installing pip.........................done.
To use pip, it is not mandatory that you need to install pip in the system directly. You can use it through virtualenv. What you can do is follow these steps:
We normally need to install Python packages for one particular project. So, now create a project folder, let’s say myproject.
Copy the virtualenv.py file from the decompressed folder of virtualenv, and paste inside the myproject folder
Now create a virtual environment, let’s say myvirtualenv as follows, inside the myproject folder:
python virtualenv.py myvirtualenv
It will show you:
New python executable in myvirtualenv\Scripts\python.exe
Installing setuptools....................................done.
Installing pip.........................done.
Now your virtual environment, myvirtualenv, is created inside your project folder. You might notice, pip is now installed inside you virtual environment. All you need to do is activate the virtual environment with the following command.
I just wanted to add one more solution for those having issues installing setuptools from Windows 64-bit. The issue is discussed in this bug on python.org and is still unresolved as of the date of this comment. A simple workaround is mentioned and it works flawlessly. One registry change did the trick for me.
在大多数情况下,这已经可以满足要求,但是,如果有必要,请确保环境变量PATH包含Python的文件夹(例如,Python 2.7.x在Windows默认安装:C:\Python27 and C:\Python27\Scripts,for Python 3.3x:C:\Python33 and C:\Python33\Scripts等)
Updated at 2016 :Pip should already be included in Python 2.7.9+ or 3.4+, but if for whatever reason it is not there, you can use the following one-liner.
Download https://bootstrap.pypa.io/get-pip.py and run it with Administrator permission python get-pip.py (If you are on Linux, use sudo python get-pip.py)
PS:
This should already be satisfied in most cases but, if necessary, be sure that your environment variable PATH includes Python’s folders (for example, Python 2.7.x on Windows default install: C:\Python27 and C:\Python27\Scripts, for Python 3.3x: C:\Python33 and C:\Python33\Scripts, etc)
Can’t believe there are so many lengthy (perhaps outdated?) answers out there. Feeling thankful to them but, please up-vote this short answer to help more new comers!
I use the cross-platform Anaconda package manager from continuum.io on Windows and it is reliable. It has virtual environment management and a fully featured shell with common utilities (e.g. conda, pip).
conda also comes with binaries for libraries with non-Python dependencies, e.g. pandas, numpy, etc. This proves useful particularly on Windows as it can be hard to correctly compile C dependencies.
I had some issues installing in different ways when I followed instructions here. I think it’s very tricky to install in every Windows environment in the same way. In my case I need Python 2.6, 2.7 and 3.3 in the same machine for different purposes so that’s why I think there’re more problems.
But the following instructions worked perfectly for me, so might be depending on your environment you should try this one:
Also, due to the different environments I found incredible useful to use Virtual Environments, I had websites that use different libraries and it’s much better to encapsulate them into a single folder, check out the instructions, briefly if PIP is installed you just install VirtualEnv:
pip install virtualenv
Into the folder you have all your files run
virtualenv venv
And seconds later you have a virtual environment with everything in venv folder, to activate it run venv/Scripts/activate.bat (deactivate the environment is easy, use deactivate.bat). Every library you install will end up in venv\Lib\site-packages and it’s easy to move your whole environment somewhere.
The only downside I found is some code editors can’t recognize this kind of environments, and you will see warnings in your code because imported libraries are not found. Of course there’re tricky ways to do it but it would be nice editors keep in mind Virtual Environments are very normal nowadays.
If you have tried installing pip through the Windows installer file from http://www.lfd.uci.edu/~gohlke/pythonlibs/#pip as suggested by @Colonel Panic, you might have installed the pip package manager successfully, but you might be unable to install any packages with pip. You might also have got the same SSL error as I got when I tried to install Beautiful Soup 4 if you look in the pip.log file:
Downloading/unpacking beautifulsoup4
Getting page https://pypi.python.org/simple/beautifulsoup4/
Could not fetch URL https://pypi.python.org/simple/beautifulsoup4/: **connection error: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed**
Will skip URL https://pypi.python.org/simple/beautifulsoup4/ when looking for download links for beautifulsoup4
The problem is an issue with an old version of OpenSSL being incompatible with pip 1.3.1 and above versions. The easy workaround for now, is to install pip 1.2.1, which does not require SSL:
Change directory to the extracted folder: cd <path to extracted folder>/pip-1.2.1
Run python setup.py install
Now make sure C:\Python27\Scripts is in PATH because pip is installed in the C:\Python27\Scripts directory unlike C:\Python27\Lib\site-packages where Python packages are normally installed
Now try to install any package using pip.
For example, to install the requests package using pip, run this from cmd:
pip install requests
Whola! requests will be successfully installed and you will get a success message.
pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4 binaries downloaded from python.org, but you’ll need to upgrade pip.
On Windows upgrade can be done easily
Go to Python command line and run below Python command
python -m pip install -U pip
Installing with get-pip.py
Download get-pip.py in the same folder or any other folder of your choice. I am assuming you will download it in the same folder from you have python.exe file and run this command
Then add C:\Python37\Scripts path to your environment variable. Assumes that there is a Python37 folder in your C drive, that folder name may varied according to the installed python version
$ pipenv
Usage: pipenv [OPTIONS] COMMAND [ARGS]...
Options:
--where Output project home information.
--venv Output virtualenv information.
--py Output Python interpreter information.
--envs Output Environment Variable options.
--rm Remove the virtualenv.
--bare Minimal output.
--completion Output completion (to be eval'd).
--man Display manpage.
--three / --two Use Python 3/2 when creating virtualenv.
--python TEXT Specify which version of Python virtualenv should use.
--site-packages Enable site-packages for the virtualenv.
--version Show the version and exit.
-h, --help Show this message and exit.
Usage Examples:
Create a new project using Python 3.7, specifically:
$ pipenv --python 3.7
Remove project virtualenv (inferred from current directory):
$ pipenv --rm
Install all dependencies for a project (including dev):
$ pipenv install --dev
Create a lockfile containing pre-releases:
$ pipenv lock --pre
Show a graph of your installed dependencies:
$ pipenv graph
Check your installed dependencies for security vulnerabilities:
$ pipenv check
Install a local setup.py into your virtual environment/Pipfile:
$ pipenv install -e .
Use a lower-level pip command:
$ pipenv run pip freeze
Commands:
check Checks for security vulnerabilities and against PEP 508 markers
provided in Pipfile.
clean Uninstalls all packages not specified in Pipfile.lock.
graph Displays currently–installed dependency graph information.
install Installs provided packages and adds them to Pipfile, or (if no
packages are given), installs all packages from Pipfile.
lock Generates Pipfile.lock.
open View a given module in your editor.
run Spawns a command installed into the virtualenv.
scripts Displays the shortcuts in the (optional) [scripts] section of
Pipfile.
shell Spawns a shell within the virtualenv.
sync Installs all packages specified in Pipfile.lock.
uninstall Un-installs a provided package and removes it from Pipfile.
$ pipenv install
Creating a virtualenv for this project...
...
No package provided, installing all dependencies.
Virtualenv location: /Users/kennethreitz/.local/share/virtualenvs/test-EJkjoYts
Installing dependencies from Pipfile.lock...
...
To activate this project's virtualenv, run the following:
$ pipenv shell
$ pipenv lock
Assuring all dependencies from Pipfile are installed...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Note: your project now has only default [packages] installed.
To install [dev-packages], run: $ pipenv install --dev
安装所有开发人员依赖项:
$ pipenv install --dev
Pipfile found at /Users/kennethreitz/repos/kr/pip2/test/Pipfile. Considering this to be the project home.
Pipfile.lock out of date, updating...
Assuring all dependencies from Pipfile are installed...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
卸载所有内容:
$ pipenv uninstall --all
No package provided, un-installing all dependencies.
Found 25 installed package(s), purging...
...
Environment now purged and fresh!
使用外壳:
$ pipenv shell
Loading .env environment variables...
Launching subshell in virtual environment. Type 'exit' or 'Ctrl+D' to return.
$ ▯