I'm simply unable to install NumPy on Windows. I keep getting this error -
PS C:\python27> pip install http://sourceforge.net/projects/numpy/file/NumPy/
Collecting http://sourceforge.net/projects/numpy/files/NumPy/
Downloading http://sourceforge.net/projects/numpy/files/NumPy/ (58kB)
100% |################################| 61kB 15kB/s
Cannot unpack file c:\users\toshiba\appdata\local\temp\pip-qev4rz-unpack\NumPy
(downloaded from c:\users\toshiba\appdata\local\temp\pip-omripn-build, content-type: text/html; charset=utf-8); cannot detect archive format
Cannot determine archive format of c:\users\toshiba\appdata\local\temp\pip-omripn-build
I had a Python 64 bit version earlier and I was not sure if NumPy version was compatible with 64-bit Python. So I uninstalled it and installed a 32-bit Python version. But still I'm getting the same error. Though my Python 32-bit version is working fine.
I tried "pip install numpy", but that gave me the following error at the end -
C:\Python27\lib\distutils\dist.py:267: UserWarning: Unknown distribution option: 'define_macros'
warnings.warn(msg)
error: Unable to find vcvarsall.bat
----------------------------------------
Command "C:\Python27\python.exe -c "import setuptools,tokenize;__file__='c:\\users\\toshiba\\appdata\\local\\temp\\pip-build-hdhqex\\numpy\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'),__file__, 'exec'))" install --record c:\users\toshiba\appdata\local\temp\pip-x_6llm-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in c:\users\toshiba\appdata\local\temp\pip-build-hdhqex\numpy
What might I be doing wrong?
Some explanations
In the first case, I didn't check but I guess that pip directly downloads the resource corresponding to the given URL: http://sourceforge.net/projects/numpy/file/NumPy/. The server returns a HTML document, while pip expects an archive one. So that can't work.
Then there are basically two ways to install Python packages:
from sources, as you tried then
from pre-compiled packages
The first case, you tried it with the command pip install numpy, but since this package contains native code, it requires development tools to be installed properly (which I always found to be a pain in the neck to do on Windows, but I did it so it's clearly feasible). The error you have error: Unable to find vcvarsall.bat means you don't have the tools installed, or the environment properly set up.
For the second case, you have different kinds of pre-compiled packages:
wheels, which you install with pip as well
installers, which you use as standard installers on Windows
For both, you need to check that the binary has been strictly compiled for your Python architecture (32 or 64 bits) and version.
An easy solution
You can find there several wheels for numpy: http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy. To get the proper architecture, check in the name win32 for 32 bits and amd64 for 64 bits. To get the proper Python version, check cpXX: first X is major version, and second X is minor version, so for instance cp27 means CPython 2.7.
Example: pip install numpy‑1.9.2rc1+mkl‑cp27‑none‑win32.whl
The hard solution: installing and using development tools
DISCLAIMER: all the following explanations might not be quite clear. They result from several investigations at different moments, but in my configuration they led to a working solution. Some links might be useless, or redundant, but that's what I noted. All of this requires a bit of cleaning, and probably generalization too.
First, you need to understand that disutils - which is the pre-installed package which handles packages workflow at lower level than pip (and which is used by the latter) - will try to use a compiler that strictly matches the one that was used to build the Python machine you installed.
Official distributions of Python use Microsoft Visual C++ for Microsoft Windows packages. So you will need to install this compiler in this case.
How to find proper version of Visual C++
The string printed by Python with this command python -c "import sys; print(sys.version)" (or when you invoke the interactive shell) will look like this:
3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:45:13) [MSC v.1600 64 bit (AMD64)]
The last part between square brackets is the identification part of the compiler. Unfortunately, this is not quite straightforward, and you have correspondence lists there:
windows - What version of Visual Studio is Python on my computer compiled with? - Stack Overflow
visual studio - Detecting compiler versions during compile time - Stack Overflow3
Pre-defined Compiler Macros / Wiki / Compilers
WinCvt - Windows Converter toolkit
In the example I gave above, this means Microsoft Visual C++ 2010 64 bits.
How to install Visual C++
You cannot find anymore a standalone package of Visual C++ for modern versions. So you will need to install the Windows SDK itself.
Here are some reference links:
Download Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 from Official Microsoft Download Center: for Visual C++ 15.00 (Visual Studio 2008). Corresponds to WinSDK 7.
Download Microsoft Windows SDK for Windows 7 and .NET Framework 4 from Official Microsoft Download Center: for Visual C++ 16.00 (Visual Studio 2010). Corresponds to WinSDK 7.1.
installation - where can I download the full installer for Visual C++ Express? - Super User
Visual Studio & co. downloads
Troubleshooting
You might have an error at the installation of the SDK:
DDSet_Error: Patch Hooks: Missing required property 'ProductFamily': Setup cannot continue.
DDSet_Warning: Setup failed while calling 'getDLLName'. System error: Cannot create a file when that file already exists.
They have been reported in several questions already:
Windows 7 SDK Installation Failure
Error installing Windows 7 SDK 7.1 with VS2008, VS2010 Premium on Win 7 32bit
As a solution, you can check this link: Windows SDK Fails to Install with Return Code 5100
The thing is to remove all conflicting (understand: the ones that the SDK installer tries to install itself) version of the Visual C++ redistributable.
Use development tools
Normally you should run vsvarsall.bat (located inside the VC folder of the installation path of Visual Studio - example: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat) to set up the proper environment variables so that the execution of distutils doesn't fail when trying to compile a package.
This batch script accepts a parameter, which should set the wanted architecture. However I saw that with the free versions of the SDK some additional scripts were missing when trying several of these parameters.
Just to say that if you are compiling for a 32 bits architecture, simply calling vsvarsall.bat should work. If you need to compile for 64 bits, you can directly call SetEnv.cmd, located somewhere under inside the SDK installation path - example: "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64.
On Windows, pip is great for installing packages that do not require compiling. Otherwise, seriously, save yourself the hassle of building and maintaining packages, and take advantage of the work others did for you. I recommend using either of these Python distributions:
ActivePython
Anaconda
Anaconda is a little larger to download and install, but it includes many useful third-party packages by default (such as numpy). ActivePython includes a package manager which allows you to easily install pre-compiled binaries (installing numpy is as easy as pypm install numpy).
The advantage of using these Python distributions is that you can get a working installation running in minutes, in an easily reproducible manner.
Best solution for this is to download and install VCforPython2.7 from https://www.microsoft.com/en-us/download/details.aspx?id=44266
Then try pip install numpy.
100% working
I tried to install numpy for windows 7, 64-bit and spent quite sometime. I was actually trying to setup sklearn. Researched many posts, documented what worked for me. Hope it saves your time!
https://simplemachinelearning.wordpress.com/2015/11/09/set-up-sklearn-on-windows/
I too faced the above problem while setting up python for machine learning.
I followed the below steps :-
Install python-2.7.13.msi
• set PATH=C:\Python27
• set PATH=C:\Python27\Scripts
Go to http://www.lfd.uci.edu/~gohlke/pythonlibs/#scipy
Downloaded:- • numpy-1.13.1+mkl-cp27-cp27m-win32.whl
• scipy-0.18.0-cp27-cp27m-win32.whl
Installing numpy:
pip install numpy-1.13.1+mkl-cp27-cp27m-win32.whl
Installing scipy:
pip install scipy-0.18.0-cp27-cp27m-win32.whl
You can test the correctness using below cmds:-
>>> import numpy
>>> import scipy
>>> import sklearn
>>> numpy.version.version
'1.13.1'
>>> scipy.version.version
'0.19.1'
>>>
Related
I have Python 3.4, running on Windows 10 x64, trying to install pylint via pip: pip install pylint.
When doing so, I get the following error: Microsoft Visual C++ 10.0 is required. Get it with "Microsoft Windows SDK 7.1": www.microsoft.com/download/details.aspx?id=8279
However I already have:
Microsoft Visual C++ 2010 x64, Microsoft Visual C++ x86 both Redistributable
Microsoft Visual C++ 2013 x64, Microsoft Visual C++ x86 both Redistributable
Microsoft Visual C++ 2015 - 2019 x64, Redistributable
Microsoft Visual C++ 2017 x64, Microsoft Visual C++ 2017 x86 both Redistributable
I saw some other posts with possible solutions that I've tried and did not seem to help to me -
updating setuptools and virtualenv
Downloading the SDK given in the error
Add VS110COMNTOOLS, VS120COMNTOOLS, VS140COMNTOOLS env variables
Of course, after every attempt I've rebooted my PC.
What else could I try to fix this?
Is it possible to install pylint without pip?
You don't have any Visual C++, you only have Redistributable packages. They install run-time libraries that are used to run applications written with VC. But you need Visual C++ compiler! Install Visual Studio 2010 Express.
See also https://stackoverflow.com/search?q=%5Bpip%5D+%22Microsoft+Visual+C%2B%2B+10.0+is+required%22
Python 3.4
According to [Python]: PEP 429 -- Python 3.4 Release Schedule (emphasis is mine):
Python 3.4 has now reached its end-of-life and has been retired. No more releases will be made.
The last version (3.4.10) was released on 2019/03/18.
So, you should move away from it (I'd recommend the (current) LTS version: 3.7). That doesn't magically solve all possible problems, but being a newer version, it requires newer build tools (VStudio) which are easier to find, and have a higher probability of installing and running correctly.
Notes:
Even if you manage to solve the problem for this version, you'll be likely to run into it again when trying to install other such packages, as more and more of them will no longer support it
Python 3.5+ are built with VStudio 14.X. Starting with VStudio 2015 (14.0), MS did some changes to improve backward and forward compatibility between VStudio versions. More details on [SO]: How to circumvent Windows Universal CRT headers dependency on vcruntime.h - (#CristiFati's answer)
2. Pylint
[PyPI]: Pylint is written entirely in Python (I checked the source code), so it wouldn't require a C(++) compiler. This is also backed up by the existence of the pylint-2.3.1-py3-none-any.whl file (available for download).
Some of its dependencies (wrapt, typed-ast: which don't have prebuilt binaries for Python 3.4 on Win - makes sense considering the previous bullet) require it.
According to [PyPA]: pip install - Options (pip install -h):
--no-deps
Don’t install package dependencies.
Now, I don't know your Pylint usecase: whether you are using the parts of it that require the above dependencies, but if you don't, simply pass the --no-deps argument.
[cfati#CFATI-5510-0:e:\Work\Dev\StackOverflow\q057581571]> sopr.bat
*** Set shorter prompt to better fit when pasted in StackOverflow (or other) pages ***
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.04.04_test0\Scripts\python.exe" -c "import sys;print(sys.version)"
3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)]
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.04.04_test0\Scripts\python.exe" -m pip freeze
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.04.04_test0\Scripts\python.exe" -m pip install --no-deps pylint
Collecting pylint
Using cached https://files.pythonhosted.org/packages/60/c2/b3f73f4ac008bef6e75bca4992f3963b3f85942e0277237721ef1c151f0d/pylint-2.3.1-py3-none-any.whl
Installing collected packages: pylint
Successfully installed pylint-2.3.1
You are using pip version 18.1, however version 19.1.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.04.04_test0\Scripts\python.exe" -m pip freeze
pylint==2.3.1
[prompt]>
[prompt]> :: Pylint dummy usage example - just import it
[prompt]> "e:\Work\Dev\VEnvs\py_064_03.04.04_test0\Scripts\python.exe" -c "import pylint;print(pylint)"
<module 'pylint' from 'e:\\Work\\Dev\\VEnvs\\py_064_03.04.04_test0\\lib\\site-packages\\pylint\\__init__.py'>
As seen, the package was installed, and it's usable.
Notes:
There are (official) prebuilt Python 3.5 (and newer) binaries for typed-ast, but not for wrapt, so a Python upgrade will still require building it (assuming that it's needed)
You could always turn to unofficial prebuilt binaries. [UCI.LFD]: Unofficial Windows Binaries for Python Extension Packages is the most comprehensive repository (that I know of), and contains the wrapt build for Python 3.4 (but doesn't the typed-ast one :) )
3. Or else ...
Python 3.4 version is built (on Win) using VStudio 2010 (10.0). Since it's written in C, it requires a C compiler. More details on [Python.Wiki]: WindowsCompilers.
Every package that contains parts written in C(++) (and needs to be built from sources at pip install time - meaning that there are no prebuilt binaries on the public repository), also requires the compiler (the compiler version must match the one that Python was built with).
The above URL lists the 4 items that need to be installed in order to get things going:
Microsoft Visual C++ 2010 Service Pack 1 Compiler Update for the Windows SDK 7.1
Microsoft Windows SDK for Windows 7 and .NET Framework 4
The other 2 are dependencies for these 2 (and I tend to think that will be automatically installed)
I didn't (have to) attempt this step, as I already have VStudio 2010 installed. As a side note, I have 7 VStudio versions (with their corresponding SDKs) installed, and also I have 30+ Python instances (installed, VEnvs, custom built by me, installed by other 3rd-party software, ...) on my machine.
Once you get the (above) build tools installed (and the %VS*% env vars pointing to the desired VStudio version - you have to do this manually when having multiple versions), you will be able to install most of the Python packages containing C(++) code. But there will probably be a few exceptions. Here's an example that gave me some headaches: [SO]: Installing pygraphviz on Windows 10 64-bit, Python 3.6 - (#CristiFati's answer) (check it out - and the URLs it references, there's a bunch of useful information there).
I noticed that you're having some problems installing VStudio 2010. With the risk of repeating myself, switching to a newer Python version would make some of your current problems go away, since it would require newer build tools which are less likely to fail installing. Everything else still applies, though.
Update #0
Concerning the last inquiry in the question:
It's possible to install Pylint without pip, for example doing (almost) what pip does, but manually. However, from what am I concerned, this would be a (lame) workaround (gainarie). Anyway, here are the steps:
Download and unpack the .whl (from section #2.)
Copy the (inside) pylint dir, under Python's site-packages dir
But again, everything done here is also done properly in #2., so this is truly pointless.
Maybe you can try to install pylint from https://www.lfd.uci.edu/~gohlke/pythonlibs/
You could try installing Visual Studio Code and opening your project from there. From my experience, Visual Studio Code offers to install pylint (and other missing libraries) for you when it recognizes it's missing.
Using pip install zipline on Windows 8 with Python 2.7 gives me the error:
Downloading/unpacking six (from python-dateutil==2.1->delorean->zipline[all])
Running setup.py egg_info for package six
Installing collected packages: blist, pytz, requests, python-dateutil, six
Running setup.py install for blist
building '_blist' extension
error: Unable to find vcvarsall.bat
Complete output from command C:\Python27\python.exe -c "import setuptools;__
file__='c:\\users\\ThatsMe\\appdata\\local\\temp\\pip-build-ThatsMe\\blist\\setup.py';ex
ec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" inst
all --record c:\users\ThatsMe\appdata\local\temp\pip-xvoky2-record\install-record.tx
t --single-version-externally-managed:
running install
running build
running build_py
running build_ext
building '_blist' extension
error: Unable to find vcvarsall.bat
Question: How can the error be resolved? Running pip install zipline[all] gives the same error...
The problem here is the line 292 (Using Python 3.4.3 here) in $python_install_prefix/Lib/distutils/msvc9compiler.py which says:
VERSION = get_build_version()
This only checks for the MSVC version that your python was built with. Just replacing this line with your actual Visual Studio version, eg. 12.0 for MSVC2013
VERSION = 12.0
will fix the issue.
UPDATE: Turns out that there is a good reason why this version is hardcoded. MSVC C runtime is not required to be compatible between major versions. Hence when you use a different VS version you might run into runtime problems. So I advise to use VS 2008 (for Python 2.6 up to 3.2) and VS2010 for (Python 3.3 and later) until this issue is sorted out.
Binary compatibility will arrive with VS 2015 (see here) along with Python 3.5 .
For Python 2.7 users Microsoft released a special Microsoft Visual C++ Compiler for Python 2.7 which can be used without installing the whole VS 2008.
You could use ol' good easy_install zipline instead.
easy_install isn't pip but one good aspect of it is the ability to download and install binary packages too, which would free you for the need having VC++ ready. This of course relies of the assumption that the binaries were prepared for your Python version.
UPDATE:
Yes, Pip can install binaries now!
There's a new binary Python archive format (wheel) that is supposed to replace "eggs". Wheels are already supported by pip. This means you'll be able to install zipline with pip without compiling it as soon as someone builds the wheel for your platform and uploads it to PyPI.
If you are getting this error on Python 2.7 you can now get the Microsoft Visual C++ Compiler for Python 2.7 as a stand alone download.
If you are on 3.3 or later you need to install Visual Studio 2010 express which is available for free here: https://www.visualstudio.com/downloads/download-visual-studio-vs#d-2010-express
If you are 3.3 or later and using a 64 bit version of python you need to install the Microsoft SDK 7.1 that ships a 64 bit compiler and follow the directions here Python PIP has issues with path for MS Visual Studio 2010 Express for 64-bit install on Windows 7
First, you should look for the file vcvarsall.bat in your system.
If it does not exist, I recommend you to install Microsoft Visual C++ Compiler for Python 2.7. This will create the vcvarsall.bat in "C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0" if you install it for all users.
The problem now is in the function find_vcvarsall(version) in the C:/Python27/Lib/distutils/msvc9compiler.py module, which is looking for the vcvarsall.bat file.
Following the function calls you will see it is looking for an entry in the registry containing the path to the vcvarsall.bat file. It will never find it because this function is looking in other directories different from where the above-mentioned installation placed it, and in my case, the registry didn't exist.
The easiest way to solve this problem is to manually return the path of the vcvarsall.bat file. To do so, modify the function find_vcvarsall(version) in the msvc9compiler.py file with the absolute path to the vcvarsall.bat file like this:
def find_vcvarsall(version):
return r"C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat"
This solution worked for me.
If you already have the vcvarsall.bat file you should check if you have the key productdir in the registry:
(HKEY_USERS, HKEY_CURRENT_USERS, HKEY_LOCAL_MACHINE or HKEY_CLASSES_ROOT)\Software\Wow6432Node\Microsoft\VisualStudio\version\Setup\VC
Where version = msvc9compiler.get_build_version()
If you don't have the key just do:
def find_vcvarsall(version):
return <path>\vcvarsall.bat
To understand the exact behavior check msvc9compiler.py module starting in the find_vcvarsall(version) function.
Simply because you don't have c++ compiler installed there in your machine, check the following
Download Microsoft Visual C++ 2008 from this page. That is a generally useful page anyway, so you should probably bookmark it. For Python 3.3+ use MS Visual C++ 2010.
Install it.
Open Windows explorer (the file browser) and search for the location of ‘vcvarsall.bat’ and cut it to your clipboard.
run regedit from the Windows start key. You will need admin privilges.
Add a registry entry to
HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir (64 bit Windows) or
HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\9.0\Setup\VC\ProductDir (32 bit)
as described here.
Hint: 0.9 in the registery directory is the currently installed version of your visual studio, if you running VS 2013, you have to find the path HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\VisualStudio\12.0....
At the Windows start key, type cmd to get a command shell. If you need to, go to your virtual environment and run activate.bat.
pip install or whatever you use to install it.
You need to have Visual Studio's bin dir in your path. Pip install is trying to compile some C code.
I spent hours researching this vcvarsall.bat as well. Most answers on SO focus on Python 2.7 and / or creating workarounds by modifying system paths. None worked for me. This solution worked out of the box for Python 3.5 and (I think) is the "correct" way of doing it.
See this link -- it describes the Windows Compilers to use for different versions of Python: https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.0_standalone:_Visual_C.2B-.2B-_Build_Tools_2015_.28x86.2C_x64.2C_ARM.29
For Python 3.5, download this: https://www.microsoft.com/en-us/download/details.aspx?id=49983
For me, I had to run C:\Program Files (x86)\Microsoft Visual C++ Build Tools\Visual C++ x64 Native Build Tools Command Prompt for it to work. From that command prompt, I ran "pip install django_compressor" which was the particular package that was causing me an issue, and it worked perfectly.
Hope this saves someone some time!
Thanks to "msoliman" for his hint, however his answer doesn't give clear solution for those who doesn't have VS2010
For example I have VS2012 and VS2013 and there are no such KEYs in system registry.
Solution:
Edit file: "[Python_install_loc]/Lib/distutils/msvc9compiler.py"
Change on line 224:
productdir = Reg.get_value(r"%s\Setup\VC" % vsbase,
"productdir")
to:
productdir = "C:\Program Files (x86)\Microsoft Visual Studio [your_vs_version(11/12...)]\VC"
and that should work
If you are trying to install matplotlib in order to work with graphs on python. Try this link.
https://github.com/jbmohler/matplotlib-winbuild.
This is a set of scripts to build matplotlib from source on the MS Windows platform.
To build & install matplotlib in your Python, do:
git clone https://github.com/matplotlib/matplotlib
git clone https://github.com/jbmohler/matplotlib-winbuild
$ python matplotlib-winbuild\buildall.py
The build script will auto-detect Python version & 32/64 bit automatically.
I appreciate this might not be the answer to resolving on 3.4 but I tried a huge variety of things to fix this on 3.4 and thought this might be useful if someone is time pressed or doesn't have the know-how to correct it (in my case, work demands).
With exactly the same setup, I found that my installation problems only happened with Python 3.4. When I changed to 2.7, all my issues seemed to be resolved.
We have a rather overzealous security setup though so I'm going to try the same on my home version (still 3.4) and see if I have any more joy. My inclination is that my VS version has somehow been restricted and the answers above should help. If I find anything more tonight I'll add further detail.
This is my first reply, not the most technical I'm afraid!
When using PIP for the first time I got an error while installing bokeh
C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution option:
'define_macros'
warnings.warn(msg)
error: Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat).
I have Dreamspark Premium so I can install anything I want but I do not want to clog my pc with various versions of the same product so if I can I'd rather install a newer version of VS.
Will this error get fixed even with a newer install of VS?
EDIT:
I installed VS2015 and it still doesn't work.
Also, I tried adding the vcvarsall.bat to path and copying it to common7/tools and that didn't help as well.
I also have a 2010 c++ redistributable installed from before I even got this problem but it still doesn't seem to see it...
The easiest way to solve this is to install a copy of Visual Studio 2010 (agreed - not a great solution). Because Python 3.4 was built with that version, you also need that version to build extensions. However, most packages have other dependencies, and so building from source should generally considered to be a significant investment and you really should just find a prebuilt version.
For bokeh, you could look into using Anaconda instead of a normal Python installation, as that will include an already built version, or there are some other suggestions listed on the PTVS page (that don't require you to use PTVS).
Also, as people migrate to Python 3.5, the compiler required will be Visual Studio 2015, so you're already set up for that. However, many packages will need some changes to build with the newer compiler, so there may be some delay before everything works again.
I installed distribute and pip using the links I have just given. I also installed the Microsoft Visual C++ 2008 redistributable package. However when I try to use pip.exe I get
error: Unable to find vcvarsall.bat
How can I fix this?
Installing the Microsoft Visual C++ 2008 Redistributable Package is not sufficient to compile packages. You need to install a compiler, not just the support files.
There are three ways to do this:
Install Visual C++.
Use mingw's port of gcc instead of Visual C++.
Use cygwin's port of gcc instead of either, and a cygwin build on Python instead of the native one.
If you want to go with option 1, you need to install Visual C++ itself. The free version should work just as well as the paid version, as long as you're not going to build binary packages to redistribute to others. Unfortunately, I'm not sure where to find the 2008 version anymore. As of May 2013, the download page only has 2010 and 2012.
When you install this, it will create a batch file called vcvarsall.bat (not vcvarshall.bat!), and give you the option of putting that batch file in your PATH. Running that batch file sets up a DOS prompt for building with that version of Visual C++. (This is handy if you have multiple versions of Visual C++, or other compilers, around.) If you skip that option, you will have to do it manually.
This question shows how to use a newer Visual Studio with older Python, and also shows how to point distutils at a vcvarsall.bat that's not on your PATH, and has links to a whole lot of other relevant questions and blog posts.
Many people find option 2 simpler. Install mingw, modify your PATH in the environment to include C:\MinGW\bin (or wherever you choose to install it), and pass -c mingw32 whenever you run a setup.py script.
The problem is that it's not as clearly documented how to tell easy_install and pip to use mingw instead of VC++. To do that, you need to find or create a distutils.cfg file, find or create a [build] section within it, and add compiler=mingw32. Not too hard. This blog post looks like it explains things pretty well, or see this answer.
Option 3 is by far the simplest. Install cygwin, tell it to install the Python and gcc packages, and you're done.
The problem is that you don't have native Windows Python, you have a Unix Python running in a fake Unix environment on top of Windows. If you like Cygwin, you'll love this; otherwise, you won't.
You'll receive such error only for packages (or one of package's dependencies) that has CPython extensions. Pip internally:
downloads the source
runs distutils python setup install
install prepares setup files and tries to build CPython extensions in windows environment
windows environment calls MS Visual Studio vcvarsall.bat script which setups DOS environment variables to enable MS Visual Studio's C compiler in the shell
if vcvarsall.bat is not found - you'll get this message
Usual solution
For python libraries which have CPython extensions that are portable on windows, it is usual to have windows binary package, which are downloadable from pypi or library web site.
In such cases it is more suitable (and painless) to install library by downloading and running windows binary package.
There is a feature request for pip to Add support for installation of binary distutils packages on Windows.
New way to do it - wheels
Thanks to comment from #warren-p: That feature request has been superseeded by Wheels support in PIP.
Official description: A wheel is a ZIP-format archive with a specially formatted filename and the .whl extension.
As I have understood, if there is windows binary package with extension .whl then start by installing wheel first:
# Make sure you have the latest pip that supports wheel
pip install --upgrade pip
pip install wheel
and then install .whl like this:
pip install full-path-or-url-to-your-library.whl
References:
pythonwheels.com
https://pypi.python.org/pypi/wheel
http://wheel.readthedocs.org/en/latest/
You can download Visual Studio 2008 Express SP1 from
http://visual-studio-2008.en.malavida.com/
You can deselect the two add to browser options it offers.
I found these links on microsoft.com that still work to Install Visual C++.
http://download.microsoft.com/download/8/B/5/8B5804AD-4990-40D0-A6AA-CE894CBBB3DC/VS2008ExpressENUX1397868.iso
2008 SP1 here
http://download.microsoft.com/download/E/8/E/E8EEB394-7F42-4963-A2D8-29559B738298/VS2008ExpressWithSP1ENUX1504728.iso
I've read every other google source and SO thread, with nothing working.
Python 2.7.3 32bit installed on Windows 7 64bit. Download, extracting, and then trying to install PyCrypto results in "Unable to find vcvarsall.bat".
So I install MinGW and tack that on the install line as the compiler of choice. But then I get the error "RuntimeError: chmod error".
How in the world do I get around this? I've tried using pip, which gives the same result. I found a prebuilt PyCrypto 2.3 binary and installed that, but it's nowhere to be found on the system (not working).
Any ideas?
If you don't already have a C/C++ development environment installed that is compatible with the Visual Studio binaries distributed by Python.org, then you should stick to installing only pure Python packages or packages for which a Windows binary is available.
Fortunately, there are PyCrypto binaries available for Windows:
http://www.voidspace.org.uk/python/modules.shtml#pycrypto
UPDATE:
As #Udi suggests in the comment below, the following command also installs pycrypto and can be used in virtualenv as well:
easy_install http://www.voidspace.org.uk/python/pycrypto-2.6.1/pycrypto-2.6.1.win32-py2.7.exe
Notice to choose the relevant link for your setup from this list
If you're looking for builds for Python 3.5, see PyCrypto on python 3.5
After years and years, python finally agreed for a binary disribution called wheel which allows to install even binary extensions on Windows without having a compiler with simple pip install packagename. There is a list of popular packages with their status. Pycrypto is not there yet, but lxml, PySide and Scrapy for example.
Edited Nov 2015: pip uninstall pycrypto & pip install pycryptodome. It is a pycrypto fork with new features and it supports wheel. It replaces pycrypto, so existing code will continue to work (see https://pycryptodome.readthedocs.org/en/latest/src/examples.html)
Microsoft has recently recently released a standalone, dedicated Microsoft Visual C++ Compiler for Python 2.7. If you're using Python 2.7, simply install that compiler and Setuptools 6.0 or later, and most packages with C extensions will now compile readily.
For VS2010:
SET VS90COMNTOOLS=%VS100COMNTOOLS%
For VS2012:
SET VS90COMNTOOLS=%VS110COMNTOOLS%
then Call:
pip install pyCrypto
In general
vcvarsall.bat is part of the Visual C++ compiler, you need that to install what you are trying to install. Don't even try to deal with MingGW if your Python was compiled with Visual Studio toolchain and vice versa. Even the version of the Microsoft tool chain is important. Python compiled with VS 2008 won't work with extensions compiled with VS 2010!
You have to compile PyCrypto with the same compiler that the version of Python was compiled with. Google for "Unable to find vcvarsall.bat" because that is the root of your problem, it is a very common problem with compiling Python extensions on Windows.
There is a lot of information and a lot to read to get this right on whatever system you are on with this link.
Beware using Visual Studio 2010 or not using Visual Studio 2008
As far as I know the following is still true. This was posted in the link above in June, 2010 referring to trying to build extensions with VS 2010 Express against the Python installers available on python.org.
Be careful if you do this. Python 2.6 and 2.7 from python.org are
built with Visual Studio 2008 compilers. You will need to link with
the same CRT (msvcr90.dll) as Python.
Visual Studio 2010 Express links with the wrong CRT version:
msvcr100.dll.
If you do this, you must also re-build Python with Visual Studio 2010
Express. You cannot use the standard Python binary installer for
Windows. Nor can you use any C/C++ extensions built with a different
compiler than Visual Studio 2010 (Express).
Opinion: This is one reason I abandoned Windows for all serious development work for OSX!
PyCryptodome is an almost-compatible fork of PyCrypto with Windows wheels available on pypi.
You can install it with a simple:
pip install pycryptodome
The website includes instructions to build it from sources with the Microsoft compilers too.
I have managed to get pycrypto to compile by using MinGW32 and MSYS. This presumes that you have pip or easy_install installed.
Here's how I did it:
1) Install MinGW32. For the sake of this explanation, let's assume it's installed in C:\MinGW. When using the installer, which I recommend, select the C++ compiler. MSYS should install with MinGW
2) Add c:\mingw\bin,c:\mingw\mingw32\bin,C:\MinGW\msys\1.0, c:\mingw\msys\1.0\bin and c:\mingw\msys\1.0\sbin to your %PATH%. If you aren't familiar, this article is very helpful.
3) From the search bar, run msys and the MSYS terminal will open. For those familiar with Cygwin, it works in a similar fashion.
4) From within the MSYS terminal pip install pycrypto should run without error after this.
For Windows 7:
To install Pycrypto in Windows,
Try this in Command Prompt,
Set path=C:\Python27\Scripts (i.e path where easy_install is located)
Then execute the following,
easy_install pycrypto
For Ubuntu:
Try this,
Download Pycrypto from "https://pypi.python.org/pypi/pycrypto"
Then change your current path to downloaded path using your terminal and user should be root:
Eg: root#xyz-virtual-machine:~/pycrypto-2.6.1#
Then execute the following using the terminal:
python setup.py install
It's worked for me. Hope works for all..
For those of you looking for python 3.4 I found a git repo with an installer that just works. Here are the direct links for x64 and x32
Try just using:
pip install pycryptodome
or:
pip install pycryptodomex
Source: https://pypi.python.org/pypi/pycryptodome
If you are on Windows and struggling with installing Pycrypcto just use the:
pip install pycryptodome.
It works like a miracle and it will make your life much easier than trying to do a lot of configurations and tweaks.
It's possible to build PyCrypto using the Windows 7 SDK toolkits. There are two versions of the Windows 7 SDK. The original version (for .Net 3.5) includes the VS 2008 command-line compilers. Both 32- and 64-bit compilers can be installed.
The first step is to compile mpir to provide fast arithmetic. I've documented the process I use in the gmpy library. Detailed instructions for building mpir using the SDK compiler can be found at sdk_build
The key steps to use the SDK compilers from a DOS prompt are:
1) Run either vcvars32.bat or vcvars64.bat as appropriate.
2) At the prompt, execute "set MSSdk=1"
3) At the prompt, execute "set DISTUTILS_USE_SDK=1"
This should allow "python setup.py install" to succeed assuming there are no other issues with the C code. But I vaaguely remember that I had to edit a couple of PyCrypto files to enable mpir and to find the mpir libraries but I don't have my Windows system up at the moment. It will be a couple of days before I'll have time to recreate the steps. If you haven't reported success by then, I'll post the PyCrypto steps. The steps will assume you were able to compile mpir.
I hope this helps.
So I install MinGW and tack that on the install line as the compiler
of choice. But then I get the error "RuntimeError: chmod error".
This error "RuntimeError: chmod error" occurs because the install script didn't find the chmod command.
How in the world do I get around this?
Solution
You only need to add the MSYS binaries to the PATH and re-run the install script.
(N.B: Note that MinGW comes with MSYS so )
Example
For example, if we are in folder C:\<..>\pycrypto-2.6.1\dist\pycrypto-2.6.1>
C:\.....>set PATH=C:\MinGW\msys\1.0\bin;%PATH%
C:\.....>python setup.py install
Optional: you might need to clean before you re-run the script:
`C:\<..>\pycrypto-2.6.1\dist\pycrypto-2.6.1> python setup.py clean`
Go to "Microsoft Visual C++ Compiler for Python 2.7" and continue based on "System Requirements" (this is what I did to put below steps together).
Install setuptools (setuptools 6.0 or later is required for Python to automatically detect this compiler package)
either by: pip install setuptools
or download "Setuptools bootstrapping installer" source from, save this file somwhere on your filestystem as "ez_python.py" and install with: python ez_python.py
Install wheel (wheel is recommended for producing pre-built binary packages). You can install it with: pip install wheel
Open Windows elevated Command Prompt cmd.exe (with "Run as administrator") to install "Microsoft Visual C++ Compiler for Python 2.7" for all users. You can use following command to do so: msiexec /i C:\users\jozko\download\VCForPython27.msi ALLUSERS=1 just use your own path to file: msiexec /i <path to MSI> ALLUSERS=1
Now you should be able to install pycrypto with: pip install pycrypto
My answer might not be related to problem mention here, but I had same problem with Python 3.4 where Crypto.Cipher wasn't a valid import. So I tried installing PyCrypto and went into problems.
After some research I found with 3.4 you should use pycryptodome.
I install pycryptodome using pycharm and I was good.
from Crypto.Cipher import AES
This probably isn't the optimal solution but you might download and install the free Visual C++ Express package from MS. This will give you the C++ compiler you need to compile the PyCrypto code.
So I install MinGW and tack that on the install line as the compiler of choice. But then I get the error "RuntimeError: chmod error".
You need to install msys package under MinGW
and add following entries in your PATH env variable.
C:\MinGW\bin
C:\MinGW\msys\1.0\bin [This is where you will find chmod executable]
Then run your command from normal windows command prompt.
Step 1: Install Visual C++ 2010 Express from
here.
(Do not install Microsoft Visual Studio 2010 Service Pack 1 )
Step 2: Remove all the Microsoft Visual C++ 2010 Redistributable packages from Control Panel\Programs and Features. If you don't do those then the install is going to fail with an obscure "Fatal error during installation" error.
Step 3: Install offline version of Windows SDK for Visual Studio 2010 (v7.1) from here.
This is required for 64bit extensions. Windows has builtin mounting for ISOs like Pismo.
Step 4: You need to install the ISO file with Pismo File Mount Audit Package. Download Pismo from here
Step 5: Right click the downloaded ISO file and choose mount with Pismo. Thereafter, install the Setup\SDKSetup.exe instead of setup.exe.
Step 6a: Create a vcvars64.bat file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 by changing directory to C:\Program Files (x86)\Microsoft Visual Studio version\VC\ on the command prompt.
Type command on the command prompt:
cd C:\Program Files (x86)\Microsoft Visual Studio version\VC\r
Step 6b:
To configure this Command Prompt window for 64-bit command-line builds that target x86 platforms, at the command prompt, enter:
vcvarsall x86 Click here for more options.
Step 7: At the command prompt, install the PyCrypto by typing:
C:\Python3X>pip install -U your_wh_file
I had Pycharm for python.
Go to pycharm -> file -> setting -> project interpreter
Click on +
Search for "pycrypto" and install the package
Note: If you don't have "Microsoft Visual C++ Compiler for Python 2.7" installed then it will prompt for installation, once installation finished try the above steps it should work fine.