pip install error: Microsoft Visual C++ 10.0 is required - python

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.

Related

Installing wxPython on Windows: DistutilsPlatformError: Microsoft Visual C++ 14.2 or greater is required

I have installed:
Python 3.10.1
PyCharm Community 2021.3
Visual Studio Build Tools 2022, including:
C++ Build Tools Core Features
C++ 2022 Redistributable Update
C++ core desktop features
MSVC v143 - VS 2022 C++ x64/x86 build tools (Latest)
Windows 10 SDK (10.0.19041.0)
C++ CMake tools for Windows
Testing tools core features - Build Tools
C++ AddressSanitizer
C++/CLI support for v143 build tools (Latest)
C++ Modules for v143 build tools (x64/x86 - experimental)
When trying to install wxPython in my project's virtualenv, I get this error:
distutils.errors.DistutilsPlatformError: Microsoft Visual C++ 14.2 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
Both the error and anything I can find on the internet (including here) tells me to download C++ build tools and install C++ 14.2 or greater / the latest version. I have:
done that (see the list above),
rebooted
venv/Scripts/pip install --upgrade setuptools
venv/Scripts/pip install --upgrade wheel
venv/Scripts/pip install --upgrade pip
What am I missing here? Is there some sort of path variable that I need to configure somewhere so pip/wheel/setuptools knows where to find the compiler?
I have the same problem. Solved for me to use Python 3.9.9.
Its maybe about a distutils problem in Python 3.10.1 with this warning from msvc9compiler.py:
DeprecationWarning: The distutils package is deprecated and slated for
removal in Python 3.12
This leads to:
raise DistutilsPlatformError("Unable to find vcvarsall.bat")
The current wxPython 4.1.1 is not compatible with python 3.10 on windows (it works on Linux). You can download an older version of Visual Studio Build Tools to get around the issue with the DistutilsPlatformError, however you will not be able to successfully install on python 3.10 on windows. I found a solution for the problem, the link is Compile_wxPython_4.1.2a1_Python3.10_Windows. I was not able to compile it but there is a link to the whl file that was bult using the procedure. I downloaded and installed it using the command pip install wxPython-4.1.2a1-cp310-cp310-win_amd64.whl
I am confident in the near future 4.1.2 will be released to PyPy and you will be able to install it using pip.
The answers here have already provided the right pointers, but in this anser I would like to list all the necessary steps directly so you don't have to visit other resources, and it also provides the solution for both 64-bit and 32-bit versions of Python 3.10.x.
Solution for 64-bit version of Python 3.10.x
Download the wxPython wheel file directly here: wxPython-4.1.2a1-cp310-cp310-win_amd64.whl.
Using the Windows command line, move to the folder where you downloaded the wheel file.
Run: pip install wxPython-4.1.2a1-cp310-cp310-win_amd64.whl
Solution for 32-bit version of Python 3.10.x
Prerequisites
Download and install Microsoft C++ Build Tools.
Download and install cygwin.
Download and install GitHub Command Line Interface (GitHub CLI).
Build wxPython
In the Windows command line ran as Administrator, execute the following commands:
gh repo clone wxWidgets/Phoenix
cd .\Phoenix\
git submodule update --init --recursive
python -m venv venv
.\venv\Scripts\activate
pip install -r .\requirements.txt
python build.py dox etg --nodoc sip build
Create wheel
Still in the command line, execute the following:
python setup.py bdist_wheel
Install wheel
Still in the command line, execute the following:
cd dist
pip install <created-wheel-filename>
The <created-wheel-filename> should be the wheel you just created, so something like: wxPython-4.2.0a1-cp310-cp310-win32.whl
Source
Compile wxPython 4.1.2a1 using Microsoft C++ Build Tools 2019
This problem is currently being fixed. Or rather it is fixed and a PR will be made with the fix pretty soon. I wrote a proper MSVC build environment script instead of the one that comes with either distutils or setuptool neither of which really work correctly when setting up an MSVC build environment.
Here is a link to the script I wrote that handles setting up the build environment properly
https://github.com/kdschlosser/python_msvc
and here is a link to a working fork of wxPython
https://github.com/oleksis/Phoenix/tree/try-pyMSVC
The problem with wxPython compiling properly is because neither setuptools or distutils has the capability of detecting Visual Studio 2022 properly. My script uses COM interfaces to collect the information needed to set up the build environment. The environment is set up without using the vcvar*.bat files.

Installing NumPy on Windows

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'
>>>

Using pip in windows

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

How do I install PyCrypto on Windows?

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.

Compiling Python modules on Windows x64

I'm starting out some projects in words processing and I needed NumPy and NLTK.
That was the first time I got to know easy_install and how to compile new module of python into the system.
I have Python 2.7 x64 plus VS 11 and VS 12. Also Cygwin (the latest one I guess).
I could see in the file that compiles using VS that it looks for VS env with the same version as the one that compiled the python code, why?
When I hardcoded 11.0 which is my version, numpy failed to build on several strange errors regarding vcvarsall (it found vcvarsall, probably misused it).
Can't I build python binaries on Windows?
If not, can I cross compile on Linux for Windows? (using the same method as Google for the Android SDK)
Update: This answer is now over 5 years old! Python-2.7 is about to be deprecated, so what you really need is a Microsoft Visual C compiler for Python-3. Take a look at this Python wiki on MS Windows Compilers. MS Build Tools 2015 with VC-14.0 is what you need to build extensions for Python-3.5 and 3.6. You can either install the older MS build tools 2015 which includes VC-14.0 or the newer MS build tools for 2017 - click the link, then scroll down until you find Build Tools for Visual Studio 2017 - which also includes VC-14.0.
Also if your versions of pip and setuptools are up to date, then you can ignore all of that silly old school MSSDK nonsense. Especially if you are using the VC for Python 2.7 or MS build tools 2015. Since setuptools-24, it just knows where to look for these compilers, hopefully.
Update: As Zooba mentions below, free x86 and AMD64 (x86-64) VC90 c-compilers for Python-2.7 are now available from Microsoft.
Update: Patch vcvarsall.bat to use x64 compilers from SDK v7.0 directly with pip in any shell instead of using SDK shell and setting DISTUTILS_USE_SDK and MSSdk environmental variables as in directions below. See Fix vcvarsall.bat to install Python-2.7 x64 extensions with v90 instead of sdk7.
tl;dr: Use Windows SDK v7.0 compilers, open the SDK shell and call
C:\> setenv /release /x64
C:\> set DISTUTILS_USE_SDK=1
C:\> MSSdk=1
to build Python 2.7.x extensions using distutils, pip or easy_install. See Python x64 Package Extensions with pip, MSVC 2008 Express & SDK 7.
Note: You can install Numpy optimized using Intel MKL from Christoph Gohlke. For virtualenv's, try converting the binary distribution windows installer to a wheel file which can be installed with pip. Building NumPy from source is not trivial. It has become a possibility with the recent introduction and availability of OpenBLAS, a fork of GotoBLAS. There are optimized binaries available for Windows x86 and x86-64 as well as source which is relatively simpler to compile than GotoBLAS or ATLAS.
Note: In the past I hadn't recommended compiling NumPy from source because you had to optimize BLAS for your platform which was very time-intensive, and the reference BLAS (FORTRAN) or CBLAS (C/C++) implementations were relatively low-performing. Also NumPy depends on LAPACK which also depends on BLAS an additional hurdle to building NumPy. However OpenBLAS binaries are already compiled with LAPACK, so this obstacle has already been removed. See Carl Kleffner's static MinGW-w64 toolchains to build NumPy with OpenBLAS on Windows - he has resolved some of the ABI incompatibilities and issues linking to the correct Microsoft Visual C Common Runtime library (msvcr90.dll for Python-2.7).
So onward to the main question about installing Python extensions on Windows 7 x64.
The recommended way to compile extensions is to use the same compiler used to compile the Python shared library [1-3]. The official Python 2.7.x for Windows was compiled using Microsoft Visual C++ Compilers version 9.0 [4] (aka MSVC90 or simply VC90) from Microsoft Visual Studio 2008 Professional, which you might be able to get for free from Microsoft DreamSpark. Evidentally the x64 compilers are not installed by default, so make sure they are installed along with the x86 compilers. Note: MS Visual Studio 2008 may no longer be available, but MS Visual Studio 2010 will let you use the MSVC90 toolchain if installed, which can be installed from Windows SDK7.
You can tell what version your Python was built with by looking at the header when you execute the python interpreter from a command line. e.g.: Python 2.7.3 (default, Apr 10 2012, 23:24:47) [MSC v.1500 64 bit (AMD64)] on win32 means that it was built with VS 2008 C++. You can build Python yourself from source, but this is also an arduous task. In general it is not recommended to mix compiler runtimes, although in practice you may find that they still work.
If you have your heart set on using GNU GCC, then you would have to use mingw-w64 because MinGW is only for native x86 applications, not AMD64/x86-64. You will need to
create a distutils config file to specify the mingw compiler,
remove the -mno-cygwin bug from distutils.cygwinccompiler.Mingw32ccompiler and
export a library definitions file using either pexports.exe from msys or gendef.exe from msys2 and make a static library libpython27.a using dlltool.exe (msys/msys2) (but the newest releases of Official Python for Windows already have this file in the Python27\lib folder, thanks!).
However in the end you will still need to link against the runtime that python was built with, msvcr90.dll, so you will need Visual C++ 2008 redistributable. Note: Windows GCC from mingw-w64 uses msvcrt.dll which is not the same as msvcr90.dll or later.
If you want to do it for free you can use Microsoft Visual C++ 2008 Express SP1 but you will need to add the Windows SDK 7 for .NET Frameworks 3.5 SP1 because the express version does not have the x64 compilers. The procedure for installing x64 C++ extensions with VS2008 Express & SDK 7 are very similar to the those on the cython site for windows x64 extensions. Note: MS Visual Studio 2008 Express is no longer available or supported.
FYI: You do not necessarily need Visual Studio to build using Microsoft compilers. They are available free with the appropriate SDK package. CL.EXE is the compiler executable, but you will have to set whatever platform options that are normally configured by Autotools or some other tool such as CMAKE. CMAKE plays well with MSVC, but Autotools AFAIK doesn't work with MSVC and would require some POSIX environment and utilities which on Windows are available in MSYS.
For many Python packages that use distutils or setuptools, they can compile extensions using Windows SDK 7 by following the directions that are posted in various places through the reference documentation and wikis:
From the Start Menu select All Programs then Microsoft Windows SDK v7.0 and start CMD Shell to open a command window optimized for Windows SDK.
Step #1 is the equivalent of typing the following in the Run box from the Start Menu or from a Command Prompt (aka C:\Windows\System32\cmd.exe):
%COMSPEC% /E:ON /V:ON /K "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.cmd"
NOTE: The flags /E:ON, which enables command extensions, and /V:ON, which enables delayed variable expansion, are both necessary to for SetEnv.cmd to function, or you will get an message that the x64 compilers are not installed, &c.
Then type setenv /Release /x64 which will set the SDK environment variables specifically for Windows 7 x64 release (vs debug or x86 which are the default).
Type set DISTUTILS_USE_SDK=1 hit return and then type set MSSdk=1 and return to tell distutils.msvccompiler that you are using the SDK, and that the SDK will determine all of the environment variables.
Now use your installation method of choice:
pip install pyyaml ntlk which is the recommended way, see ntlk, but you must have setuptools and pip installed.
python setup.py install for each downloaded, extracted tarball
easy_install pyyaml ntlk which is the old way and the only way to install eggs.
[1] Building C and C++ Extensions on Windows
[2] distutils.msvccompiler — Microsoft Compiler
[3] Python Dev Guide: Getting Started: Windows
[4] What version of visual studio is this python compiled with
Since the other answers, Microsoft has released a compiler package specifically for building extensions for Python 2.7 (and any version of Python that used VS 2008/VC9). Here's how to use it:
Go to http://aka.ms/vcpython27, download and install the package (it's fairly small and does not require administrator rights)
Update setuptools to 6.0 or later (pip install -U setuptools)
Install your package (pip install <whatever>)
The combination of the latest setuptools version and this compiler pack should make it really easy to do this.
there are several ways to do it apparently.
build using mingw
build python 2.7 using VS 2008 express.
i'm not sure regarding which version is good to build 3.2 but it could be VS 2010.
you can compile python x64 from source using your desired VS, but u'll have competability issues with other pre built packages.
This worked best for me:
Install Visual Studio Express 2008
Install Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 SP1 from http://www.microsoft.com/en-us/download/details.aspx?id=3138
Go to C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin and open the Visual Studio 2008 x64 Win64 Command Prompt
In that shell, run pip install <package>
You should not have to install any redistributable packages on client systems when done this way.
For Windows 10, Python 2.7.11, Cygwin 2.5.2 and x86_64-w64-mingw32-gcc 4.9.2
or 5.4.0 (but see note under 1 below), pulling together comments from elsewhere, here's what I had to do for my Python extension to compile, link, and beat a race condition between msvcrt.dll and msvcr90.dll:
Edit distutils/cygwinccompiler, and in class Mingw32CCompiler
Replace the old -mno-cygwin fix with
if self.gcc_version < '4' or is_cygwingcc():
no_cygwin = ' -nostdlib -lgcc'
for gcc 4.9.2 -- note for 5.4.0, no 'if', just
no_cygwin = ''
Get the right compiler in place:
self.set_executables(compiler='x86_64-w64-mingw32-gcc%s -O -Wall' % no_cygwin,
compiler_so='x86_64-w64-mingw32-gcc%s -mdll -O -Wall' % no_cygwin,
compiler_cxx='x86_64-w64-mingw32-g++%s -O -Wall' % no_cygwin,
linker_exe='x86_64-w64-mingw32-gcc%s' % no_cygwin,
linker_so='x86_64-w64-mingw32-%s%s %s %s'
note for x86_64-w64-mingw32-gcc 5.4.0, it seems to work better without msvcr90, so make the call to get_msvcr conditional:
if self.gcc_version < '5':
self.dll_libraries = get_msvcr()
Use a setup.py with the following
libdirs=['C:\\Python27\\libs',...]
macros=[('MS_WIN64','1'),...]
platform="WIN32"
Patch one of my source file headers to include
#ifdef MS_WIN64
#define strdup _strdup
#endif
Finally,
/c/Python27/python [editted setup].py -v build --compiler=mingw32
/c/Python27/python [editted setup].py -v install
Some of the above may not be in quite the optimal place, but it got my extension working...

Categories

Resources