122

I just ran the following command:

pip install -U steem

and the installation worked well until it failed to install pycrypto. Afterwards I did the

pip install cryptography

command because I thought it was the missing package. So my question is, how I can install steem without the pycrypto-error (or the pycrypto-package in addition) and how to uninstall the cryptography-Package which I don't need. (I'm using Windows 7 and Python 3)

Requirement already up-to-date: python-dateutil in c:\users\***\appdata\lo
cal\programs\python\python36\lib\site-packages (from dateparser->maya->steem)
...
Installing collected packages: urllib3, idna, chardet, certifi, requests, pycryp
to, funcy, w3lib, voluptuous, diff-match-patch, scrypt, prettytable, appdirs, la
ngdetect, ruamel.yaml, humanize, tzlocal, regex, dateparser, pytzdata, pendulum,
maya, ecdsa, pylibscrypt, ujson, toolz, steem
Running setup.py install for pycrypto ... error
Complete output from command c:\users\***\appdata\local\programs\pytho
n\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\
***~1\\AppData\\Local\\Temp\\pip-build-k6flhu5k\\pycrypto\\setup.py';f=getattr(
tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();
exec(compile(code, __file__, 'exec'))" install --record C:\Users\***N~1\AppDat
a\Local\Temp\pip-igpkll6u-record\install-record.txt --single-version-externally-
managed --compile:
running install
running build
running build_py
...
building 'Crypto.Random.OSRNG.winrandom' extension
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual
C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

----------------------------------------
Command "c:\users\***\appdata\local\programs\python\python36\python.exe -u
-c "import setuptools, tokenize;__file__='C:\\Users\\***N~1\\AppData\\Local\\
Temp\\pip-build-k6flhu5k\\pycrypto\\setup.py';f=getattr(tokenize, 'open', open)(
__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code,   __fil
e__, 'exec'))" install --record C:\Users\***N~1\AppData\Local\Temp\pip-igpkll6
u-record\install-record.txt --single-version-externally-managed --compile"   faile
d with error code 1 in C:\Users\***N~1\AppData\Local\Temp\pip-build-    k6flhu5k\p
ycrypto\
3

14 Answers 14

133

You need to install Microsoft Visual C++ 14.0 to install pycrypto:

error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

In the comments you ask which link to use. Use the link to Visual C++ 2015 Build Tools. That will install Visual C++ 14.0 without installing Visual Studio.

Alternate link: https://wiki.python.org/moin/WindowsCompilers#Microsoft_Visual_C.2B-.2B-_14.2_standalone:_Build_Tools_for_Visual_Studio_2019_.28x86.2C_x64.2C_ARM.2C_ARM64.29

In the comments you ask about methods of installing pycrypto that do not require installing a compiler. The binaries in the links appear to be for earlier versions of Python than you are using. One link is to a binary in a DropBox account.

I do not recommend downloading binary versions of cryptography libraries provided by third parties. The only way to guarantee that you are getting a version of pycrypto that is compatible with your version of Python and has not been built with any backdoors is to build it from the source.

After you have installed Visual C++, just re-run the original command:

pip install -U steem

To find out what the various install options mean, run this command:

pip help install

The help for the -U option says

-U, --upgrade        Upgrade all specified packages to the newest available
                     version. The handling of dependencies depends on the
                     upgrade-strategy used.

If you do not already have the steem library installed, you can run the command without the -U option.

20
  • 1
    Thank you for your answer, David! So when I have installed Visual C++, do I have to run the "pip install -U steem"-command again or just some install pycrypto-command-thing? (I'm asking, because I don't want to have the packages that were installed before the error twice on my computer.)
    – Studentu
    Jul 6, 2017 at 16:56
  • 2
    Thanks, David! I'll try it again as you have discribed. However, I don't know which Microsoft Visual C++ to download from the site in the url above - do I need Visual C++ 2015 or 2017 or do both include the 14.0-version which is required for python?
    – Studentu
    Jul 7, 2017 at 21:39
  • 7
    Finally a link for the VS 14.0 build tools that is still working.... Thanks! Thanks! Thanks!
    – The Dodo
    Aug 2, 2018 at 14:57
  • 6
    Download Microsoft C++ Build Tools --> Run exe --> Check C++ build tools --> check MSVC v142 and Windows 10 SDK --> wait for installation to finish
    – xinthose
    Jan 15, 2021 at 22:02
  • 2
    @xinthose I appreciate letting us know exactly which packages to download/install, instead of the entire thing Aug 24, 2022 at 17:17
105

If you already have Visual Studio Build Tools installed but you're still getting that error, then you may need to "Modify" your installation to include the Visual C++ build tools.

To do that:

  1. Open up the Visual Studio Installer (you can search for it in the Start Menu if needed).

  2. Find Visual Studio Build Tools and click "Modify":

enter image description here

  1. Add a checkmark to Visual C++ build tools and then click "Modify" in the bottom right to install them:

enter image description here

After the C++ tools finish installing, run the pip command again and it should work.

8
  • 68
    With VS 2019, this option is found in the "Individual Components" tab of VS installer, under the name of "MSVC v140 - VS2015 C++ Build Tools (v14.00)" and needs to download 800 MB.
    – mins
    Nov 27, 2020 at 18:54
  • 5
    How to do this via regular windows cmd?
    – shs_sf
    Jan 3, 2021 at 22:22
  • 7
    @mins is it required to download windows universal crt sdk with it? Totally, it is requiring me 3.64GB of space!!! Nov 1, 2021 at 11:30
  • 4
    @shs_sf If you like using chocolatey (as I do) then you can install these packages: cinst visualstudio2019buildtools cinst visualstudio2019-workload-vctools
    – barbalion
    Nov 16, 2021 at 20:24
  • 7
    For 2022: you pick the "C++ build tools" it is not the same icon than this screenshot. And you accept the 7GB install :( Jul 1, 2022 at 14:17
17

I landed on this question after searching for "Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools". I got this error in Azure DevOps when trying to run pip install to build my own Python package from a source distribution that had C++ extensions. In the end all I had to do was upgrade setuptools before calling pip install:

pip install --upgrade setuptools

So the advice here about updating setuptools when installing from source archives is right after all:). That advice is given here too.

0
15

I got this error when I tried to install pymssql even though Visual C++ 2015 (14.0) is installed in my system.

I resolved this error by downloading the .whl file of pymssql from here.

Once downloaded, it can be installed by the following command :

pip install python_package.whl

Hope this helps

2
  • When I got a similar bug, I use the same method to solve my problem. thank you~
    – Hong Cheng
    May 14, 2021 at 0:49
  • 2
    asyncpg pakage is not available in the list. Nov 3, 2021 at 7:15
9

As an alternative to installing Visual C++, there is a way by installing an additional package in Conda (this option doesn't require admin rights). This worked for me:

conda install libpython m2w64-toolchain -c msys2
2
  • 2
    Thanks. Given others have mentioned cryptography support, an explanation would be helpful, just to know what is installed and why this is an acceptable alternative. Blindly/randomly adding libraries to a computer isn't generally a good option. Perhaps also linking to the original source, as I imagine you didn't invent the solution.
    – mins
    Nov 27, 2020 at 18:29
  • 2
    Love you man. I can never get this problem to fix itself on Windows. Tried downloading every C++ compiler thing Microsoft have with no help. Tried editing some environment variables to point to the Common7/Tools path and it didn't work. But this worked. Oct 2, 2021 at 5:45
8

I faced the same problem. Found the fix here.

Basically just install this.

shasum output:

3e0de8af516c15547602977db939d8c2e44fcc0b  visualcppbuildtools_full.exe

md5sum output:

MD5 (visualcppbuildtools_full.exe) = 8d4afd3b226babecaa4effb10d69eb2e

Run your pip installation command again. If everything works fine, its good. Or you might face the following error like me:

Finished generating code
    LINK : fatal error LNK1158: cannot run 'rc.exe'
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\x86_amd64\\link.exe' failed with exit status 1158

Found the fix for the above problem here: Visual Studio can't build due to rc.exe

That basically says

Add this to your PATH environment variables:

C:\Program Files (x86)\Windows Kits\8.1\bin\x86

Copy these files:

rc.exe
rcdll.dll

From

C:\Program Files (x86)\Windows Kits\8.1\bin\x86

To

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin

It works like a charm

2
  • Thanks, the above finally fixed it for me. One difference though, my folder is called C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin Dec 10, 2020 at 8:52
  • @MathiasThorsen the folder name is based on your Visual Studio version, they vary from version to version. Aug 14, 2021 at 8:24
7

Updated link here for download Microsoft Visual C++ 14.0

It works for me without a Visual Studio downloader

0
5

Pycrypto has vulnerabilities assigned the CVE-2013-7459 number, and the repo hasn't accept PRs since June 23, 2014.

Pycryptodome is a drop-in replacement for the PyCrypto library, which exposes almost the same API as the old PyCrypto, see Compatibility with PyCrypto.

If you haven't install pycrypto yet, you can use pip install pycryptodome to install pycryptodome in which you won't get Microsoft Visual C++ 14.0 issue.

1
  • still got the error after pip install pycryptodome
    – Sean.H
    Jun 16 at 9:37
1

Three steps I follow for this error:

  1. C++ Build tools are installed
  2. pip install --upgrade setuptools
  3. try using conda to install, conda may have the compiled version which won't need the build tools
1

None of the solutions proposed by other people here worked for me.

So in my case I had to uinstall ALL older versions of Microsoft Visual C++ Redistributable from my computer:

enter image description here

Only the newest one (in my case 2015-2022) should be left!

After uinstalling I ran this command:

pip install <your_lib_name>

and everything worked great after that.

1

On Windows, I strongly recommand installing the latest version of Visual Studio Community. It's free, you will maybe miss some build tools if you only install vc_redist, so you can easily install package by pip instead of wheel, it save lot of time.

1
  • 2
    As of 2020 having VS Community installed doesn't prevent to see this error. But perhaps you need to have the C++ "workload" installed, which I don't have.
    – mins
    Nov 27, 2020 at 17:52
0

Killer solution: install nodejs and tick the option of install chocolatey and other necessary tools... and it will install the tools required to setup a development environment.

1
  • 2
    Installing nodejs is rarely the solution, especially when the problem is to do with MS Build Tools for Python.
    – jon_two
    Aug 23, 2022 at 10:07
0

I'm going to add another answer here since I was caught on this for hours and finally figured out what the cause was and it was painfully unintuitive.

I kept getting the "Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools" when trying to install a python depedndency. No matter how many times I re-installed it, the error persisted.

After hours of debugging, the issue ended up being that it was not getting added to my PATH. Apparently with everything I had on my path, adding it would put it at 2050 characters, and Windows limits it at 2048. My guess is the installer is just silently failing on this, hence no indication.

Find the path of the build tools, (mine was C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\Hostx86\x86 ), and append it to your path.

If you have the same issue as I did, you'll need to shorten the path by removing other elements here. I had a few old Python version I was able to remove in order to go under the character limit.

4
  • "My guess is the installer is just silently failing on this, hence no indication." The resulting PATH is a valid value for the environment variable; it just has a nonexistent directory at the end (it's not the responsibility of any tool in particular to check for this) and therefore the compiler isn't found. The install process is as noisy as ever about the fact that a compiler wasn't found; I don't know what you would consider "not silent". Aug 25 at 18:47
  • I would consider not silent being an actual error thrown on install that a path wasn't added. The compiler WAS installed, it just wasn't being added to the path. Programs trying to consume it throw a misleading error saying it's not installed. Aug 26 at 19:24
  • But as far as I'm aware, a path was added (it was just truncated), and that path addition happened in a context that the installer didn't have any way to know about. Aug 26 at 20:42
  • There was no evidence of a partial path existing. In any scenario, I don't get the point of being pedantic on this. No matter how you split hairs, it didn't work. Aug 28 at 22:23
-1

Try doing this:

py -m pip install pipwin
py -m pipwin install PyAudio
2
  • what are this packages?
    – ediordna
    Nov 16, 2021 at 16:49
  • 1
    @ediordna it appears to be some kind of wrapper that searches for pre-built binaries for Windows rather than letting Pip attempt to compile them locally. It also appears to be no longer maintained. Aug 25 at 18:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.