How do I install Python packages on Windows?
I’m having a hard time setting up python packages. EasyInstall from SetupTools is supposed to help that, but they don’t have an executable for Python 2.6. For instance to install Mechanize, I’m just supposed to put the Mechanize folder in C:\Python24\Lib\site-packages according to INSTALL.txt, but runnning the tests does not work. Can someone help shed some light on this? Thanks!
As of March, 2014, the pip package manager is included with Python 3.4 on all platforms, including Windows. So ensuring you are running Python 3.4 might be a good option.
install python 2.7.10 or 3.4 above which has by default pip in it.Then use python -m pip install Django in cmd and so on
12 Answers 12
The accepted answer is outdated. So first, pip is preferred over easy_install , (Why use pip over easy_install?). Then follow these steps to install pip on Windows, it’s quite easy.
curl https://bootstrap.pypa.io/ez_setup.py | python
curl https://bootstrap.pypa.io/get-pip.py | python
of all the suggestions, this is the only one that worked for me. My environment — Python 3.3.1 , Windows 7 64bit, x64 PC. if possible, please upvote this, saves ppl a lot of trouble.
the above worked for me, but the second curl with https gave a warning about the ssl certificate expired. had to use —insecure on the curl command line
The above worked for me (Windows7 x64, python 2.7) but to install pip I had to follow the instructions @ pip.pypa.io/en/latest/installing.html
Newer versions of Python for Windows come with the pip package manager. (source)
pip is already installed if you’re using Python 2 >=2.7.9 or Python 3 >=3.4
Use that to install packages:
cd C:\Python\Scripts\ pip.exe install
+1 because this explicitly says WHERE to type «pip install
as said this is a great answer! It of course assumes python is installed in c drive. For people using PowerShell, in case you install python to a directory whose path has a space in it, use cd («path») to change the directory.
This worked great on Windows 10, even with Python 2.7. Thanks for Windows-oriented answer that didn’t make my eyes glaze over.
For some Windows installations, pip is located as C:\Users\[you]\AppData\Local\Programs\Python\Python[XX]\Scripts\pip
This is a good tutorial on how to get easy_install on windows. The short answer: add C:\Python26\Scripts (or whatever python you have installed) to your PATH.
When installing Python 3.7 on Windows, there is a nice option to add that path to the PATH environment variable.
You don’t need the executable for setuptools. You can download the source code, unpack it, traverse to the downloaded directory and run python setup.py install in the command prompt
If you downloaded the tar file, just unpack it with a program like WinRAR. Once you’ve done that, open up the command prompt and navigate to the folder where it was unpacked (You’ll know you’re at the right spot if you see a setup.py file). From there you can run python setup.py install and it will install it for you.
Starting with Python 2.7, pip is included by default. Simply download your desired package via
python -m pip install [package-name]
@delinco m **module-name**: Searches **sys.path** for the named module and runs the corresponding **.py** file as a script. .
Add environment path to system or locate and enter the python folder before using python -m pip install [package-name]
Packaging in Python is dire. The root cause is that the language ships without a package manager.
Fortunately, there is one package manager for Python, called Pip. Pip is inspired by Ruby’s Gem, but lacks some features. Ironically, Pip itself is complicated to install. Installation on the popular 64-bit Windows demands building and installing two packages from source. This is a big ask for anyone new to programming.
So the right thing to do is to install pip. However if you can’t be bothered, Christoph Gohlke provides binaries for popular Python packages for all Windows platforms http://www.lfd.uci.edu/~gohlke/pythonlibs/
In fact, building some Python packages requires a C compiler (eg. mingw32) and library headers for the dependencies. This can be a nightmare on Windows, so remember the name Christoph Gohlke.
I had problems in installing packages on Windows. Found the solution. It works in Windows7+. Mainly anything with Windows Powershell should be able to make it work. This can help you get started with it.
- Firstly, you’ll need to add python installation to your PATH variable. This should help.
- You need to download the package in zip format that you are trying to install and unzip it. If it is some odd zip format use 7Zip and it should be extracted.
- Navigate to the directory extracted with setup.py using Windows Powershell (Use link for it if you have problems)
- Run the command python setup.py install
That worked for me when nothing else was making any sense. I use Python 2.7 but the documentation suggests that same would work for Python 3.x also.
Upgrade the pip via command prompt ( Python Directory )
D:\Python 3.7.2>python -m pip install --upgrade pip
Now you can install the required Module
D:\Python 3.7.2>python -m pip install >
pip is the package installer for python, update it first, then download what you need
python -m pip install --upgrade pip
You can also just download and run ez_setup.py, though the SetupTools documentation no longer suggests this. Worked fine for me as recently as 2 weeks ago.
PS D:\simcut> C:\Python27\Scripts\pip.exe install networkx Collecting networkx c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:318: SNIMissingWarning: An HTTPS reques t has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may caus e the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer ve rsion of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissi ngwarning. SNIMissingWarning c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SS LContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL con nections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3. readthedocs.io/en/latest/security.html#insecureplatformwarning. InsecurePlatformWarning Downloading networkx-1.11-py2.py3-none-any.whl (1.3MB) 100% |################################| 1.3MB 664kB/s Collecting decorator>=3.4.0 (from networkx) Downloading decorator-4.0.11-py2.py3-none-any.whl Installing collected packages: decorator, networkx Successfully installed decorator-4.0.11 networkx-1.11 c:\python27\lib\site-packages\pip\_vendor\requests\packages\urllib3\util\ssl_.py:122: InsecurePlatformWarning: A true SSLContext object i s not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplat formwarning. InsecurePlatformWarning
Or just put the directory to your pip executable in your system path.
What path to install Python 3.6 to on Windows?
The 3.6 installer suggests C:\Users\MyUserName\AppData\Local\Programs\Python\Python36-32 which is unlike any other software on Windows. I remember that earlier versions installed to C:\PythonXY which is also unusual on Windows. Is any of that really a good idea? In particular, I don’t see why I would want to install this only for my user account. The checkbox «Install launcher for all users (recommended)» is default checked which seems incompatible with installing into %APPDATA% . What is a good path to install Python to? I’m a complete Python amateur and I don’t want to cause myself problems. I am fearful of adding a space to the path for example. Clicking further through the installer it turns out there is a checkbox to install for all users. This immediately sets a Program Files (x86) based path to the checkbox.
See this tutorial for the recommended installation process for official Python: youtu.be/PUFnDSdk1jQ. The tutorial also covers the (automatic) path setting so that you don’t have the problem in the first place.
4 Answers 4
This is a very subjective question in most cases, I’m not really sure if its even fit for SO.
Here are the different characteristics of each path:
- Requires administrator rights
- All users have access to it — better if you want only one install of a python version on your system
- More practical to write in command line (might be needed for multiple python installs, although using venvs or conda envs solves this problem)
- Program Files is the same, except that there are spaces in the path (probably a bad idea)
- Doesn’t require administrator rights
- Only for one user — good if the other users don’t want/need it
- Might be painful to write in command line
I have admin rights and am the only user on my computer, so I chose the first option, but it really is case-dependent.
EDIT Please see the comments below for rectifications on paths.
Any authenticated user is allowed to create and modify a directory in the root of the system drive. That’s the problem; it isn’t secure. So for 3.5+ %ProgramFiles% is the default for all-user installations. The spaces in this directory for some locales aren’t a problem; code that can’t handle them has a bug that needs to be fixed. From the command-line you can use the py.exe launcher to run any installed version, but if you’re developing for multiple versions across multiple projects you should really think about using virtual environments.
A per-user install of Python defaults to %LocalAppData%\Programs , which is the known shell folder FOLDERID_UserProgramFiles . Using the user’s roaming %AppData% would lead to network congestion if roaming profiles are in use. As far as command-line difficulties with typing this path, there’s the py launcher and PATH environment variable, plus venv virtual environments that can be created wherever you want for convenience.
Installing Python in c:\Program Files\ in 64-bit Windows 10 has problems because of the new «security features» of Windows 10. Subfolders of c:\Programs Files\ have restricted permissions on them which are not compatible with the installation processes for some Python packages. Installing in a directory directly below the root (for example c:\Python36\ for Python 3.6) avoids these problems. It may be «less secure», but it actually works, which installing under c:\Program Files\ sometimes does not. For example, I have found that if you try to install the matplotlib package in Python 3.7 installed under c:\Program Files\, some of the packages that matplotlib is dependent on are blocked from installing, and the package will not run, but if it is installed in c:\Python37\, it runs fine. Another example of overly enthusiastic Microsoft «security.»
Installing in the %appdata% folder for a single user is fine if you are the only person who is going to be using Python, but if your computer is going to be used by another user (for example, if it is a work computer which will be «inherited» by a new employee that takes over your position), Python (and all necessary Python packages) would have to be reinstalled for that user.
I think the best path to install python is in C:\Users\\PythonXX (especially if you are using PC with multiple users and also if you are using your organization PC.
If you install to C:\PythonXX or to C:\Program Files\PythonXX , you will always have permissions issue. As soon as you try to install some packages/libraries using ‘pip install ‘, permissions will not allow to install the packages.
If you leave the installation to be continued in C:\Users\\AppData\Local\Programs\Python\PythonXX as suggested by python installer, which also doesn’t have any permissions issue, but path is not so easy to remember.
Few more important points:
- If you are using a personal laptop and you are the only user (you will be administrator as well), then installing python to C:\PythonXX is also a best option.
- Always check the option, add python path to Path variable during installation, so that you can also use python from command prompt/powershell.
- Always check the option, install pip, so that you can use pip to install/update packages/libraries.