Traceback(most recent call last):File"<stdin>", line 1,in<module>File"/usr/local/lib/python3.4/multiprocessing/context.py", line 132,inValuefrom.sharedctypes importValueFile"/usr/local/lib/python3.4/multiprocessing/sharedctypes.py", line 10,in<
module>import ctypesFile"/usr/local/lib/python3.4/ctypes/__init__.py", line 7,in<module>from _ctypes importUnion,Structure,ArrayImportError:No module named '_ctypes'
I am using Ubuntu and have installed Python 2.7.5 and 3.4.0. In Python 2.7.5 I am able to successfully assign a variable x = Value('i', 2), but not in 3.4.0. I am getting:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.4/multiprocessing/context.py", line 132, in Value
from .sharedctypes import Value
File "/usr/local/lib/python3.4/multiprocessing/sharedctypes.py", line 10, in <
module>
import ctypes
File "/usr/local/lib/python3.4/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ImportError: No module named '_ctypes'
I just updated to 3.3.2 through installing the source of 3.4.0. It installed in /usr/local/lib/python3.4.
Did I update to Python 3.4 correctly?
One thing I noticed that Python 3.4 is installed in usr/local/lib, while Python 3.3.2 is still installed in usr/lib, so it was not overwritten.
./configure
make # alternatively `make -j 4` will utilize 4 threads
sudo make altinstall
Got 3.7 installed and working for me.
SLIGHT UPDATE
Looks like I said I would update this answer with some more explanation and two years later I don’t have much to add.
this SO post explains why certain libraries like python-dev might be necessary.
this SO post explains why one might use the altinstall as opposed to install argument in the make command.
Aside from that I guess the choice would be to either read through the cpython codebase looking for #include directives that need to be met, but what I usually do is keep trying to install the package and just keep reading through the output installing the required packages until it succeeds.
I run into this error when I tried to install Python 3.7.3 in Ubuntu 18.04 with next command: $ pyenv install 3.7.3.
Installation succeeded after running $ sudo apt-get update && sudo apt-get install libffi-dev (as suggested here).
The issue was solved there.
Refer to this thread or this thread, for customized installation of libffi, it is difficult for Python3.7 to find the library location of libffi. An alternative method is to set the CONFIGURE_LDFLAGS variable in the Makefile, for example CONFIGURE_LDFLAGS="-L/path/to/libffi-3.2.1/lib64".
My solution:
Installing libffi-dev with apt-get didn’t help.
But this helped: Installing libffi from source and then installing Python 3.8 from source.
My configuration:
Ubuntu 16.04 LTS
Python 3.8.2
Step by step:
I got the error message “ModuleNotFoundError: No module named ‘_ctypes'” when starting the debugger from Visual Studio Code, and when running python3 -c "import sklearn; sklearn.show_versions()".
install libtool: sudo apt-get install libtool
The file README.md from libffi mentions that autoconf and automake are also necessary. They were already installed on my system.
If you don’t mind using Miniconda, the necessary external libraries and _ctypes are installed by default. It does take more space and may require using a moderately older version of Python (e.g. 3.7.6 instead of 3.8.2 as of this writing).
ffi_inc =[sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]ifnot ffi_inc or ffi_inc[0]=='':
ffi_inc = find_file('ffi.h',[], inc_dirs)if ffi_inc isnotNone:
ffi_h = ffi_inc[0]+'/ffi.h'ifnot os.path.exists(ffi_h):
ffi_inc =Noneprint('Header file {} does not exist'.format(ffi_h))
ffi_lib =Noneif ffi_inc isnotNone:for lib_name in('ffi','ffi_pic'):if(self.compiler.find_library_file(lib_dirs, lib_name)):
ffi_lib = lib_name
break
ffi_lib="ffi"# --- AND INSERT THIS LINE HERE THAT DOES NOT APPEAR ---if ffi_inc and ffi_lib:
ext.include_dirs.extend(ffi_inc)
ext.libraries.append(ffi_lib)
self.use_system_libffi =True
If you are doing something nobody here will listen you about because “you’re doing it the wrong way”, but you have to do it “the wrong way” for reasons too asinine (for instance, in my case it quickly degrades into foul words about somebody on devops team overweight mother), you need to first:
Get libffi and install it into your user install area the usual way.
git clone https://github.com/libffi/libffi.git
cd libffi
./configure --prefix=path/to/your/install/root
make
make install
Then go back to your Python 3 source and find this part of the code in setup.py at the top level of the python source directory
ffi_inc = [sysconfig.get_config_var("LIBFFI_INCLUDEDIR")]
if not ffi_inc or ffi_inc[0] == '':
ffi_inc = find_file('ffi.h', [], inc_dirs)
if ffi_inc is not None:
ffi_h = ffi_inc[0] + '/ffi.h'
if not os.path.exists(ffi_h):
ffi_inc = None
print('Header file {} does not exist'.format(ffi_h))
ffi_lib = None
if ffi_inc is not None:
for lib_name in ('ffi', 'ffi_pic'):
if (self.compiler.find_library_file(lib_dirs, lib_name)):
ffi_lib = lib_name
break
ffi_lib="ffi" # --- AND INSERT THIS LINE HERE THAT DOES NOT APPEAR ---
if ffi_inc and ffi_lib:
ext.include_dirs.extend(ffi_inc)
ext.libraries.append(ffi_lib)
self.use_system_libffi = True
and add the line I have marked above with the comment. Why it is necessary, and why there is no way to get configure to respect ‘–without-system-ffi` on Linux platforms, perhaps I will find out why that is “unsupported” in the next couple of hours, but everything has worked ever since. Otherwise, best of luck… YMMV.
WHAT IT DOES: just overrides the logic there and causes the compiler linking command to add “-lffi” which is all that it really needs. If you have the library user-installed, it is probably detecting the headers fine as long as your PKG_CONFIG_PATH includes path/to/your/install/root/lib/pkgconfig.
Update: Comments point out that the instructions here may be dangerous. Consider using the Visual C++ 2008 Express edition or the purpose-built Microsoft Visual C++ Compiler for Python (details) and NOT using the original answer below. Original error message means the required version of Visual C++ is not installed.
For Windows installations:
While running setup.py for package installations, Python 2.7 searches for an installed Visual Studio 2008. You can trick Python to use a newer Visual Studio by setting the correct path in VS90COMNTOOLS environment variable before calling setup.py.
Execute the following command based on the version of Visual Studio installed:
Visual Studio 2010 (VS10): SET VS90COMNTOOLS=%VS100COMNTOOLS%
Visual Studio 2012 (VS11): SET VS90COMNTOOLS=%VS110COMNTOOLS%
Visual Studio 2013 (VS12): SET VS90COMNTOOLS=%VS120COMNTOOLS%
Visual Studio 2015 (VS14): SET VS90COMNTOOLS=%VS140COMNTOOLS%
WARNING: As noted below, this answer is unlikely to work if you are trying to compile python modules.
If you want to compile with Visual Studio C++ instead of mingw…
Run python.exe to display which version of VC++ it was compiled with (example shown below).
It is important to use the corresponding version of the Visual C++ compiler that Python was compiled with since distilutils‘s get_build_version prevents mixing versions (per Piotr’s warning).
Yellow (top) is Python 2.7, compiled with MSC v.1500 (Visual Studio C++ 2008)
Red (bottom) is Python 3.4.1, compiled with MSC v.1600 (Visual Studio C++ 2010)
Use the table below[1] to match the internal VC++ version with the corresponding Visual Studio release:
MSC v.1000 -> Visual C++ 4.x
MSC v.1100 -> Visual C++ 5
MSC v.1200 -> Visual C++ 6
MSC v.1300 -> Visual C++ .NET
MSC v.1310 -> Visual C++ .NET 2003
MSC v.1400 -> Visual C++ 2005 (8.0)
MSC v.1500 -> Visual C++ 2008 (9.0)
MSC v.1600 -> Visual C++ 2010 (10.0)
MSC v.1700 -> Visual C++ 2012 (11.0)
MSC v.1800 -> Visual C++ 2013 (12.0)
MSC v.1900 -> Visual C++ 2015 (14.0)
MSC v.1910 -> Visual C++ 2017 (15.0)
MSC v.1911 -> Visual C++ 2017 (15.3)
MSC v.1912 -> Visual C++ 2017 (15.5)
MSC v.1913 -> Visual C++ 2017 (15.6)
MSC v.1914 -> Visual C++ 2017 (15.7)
MSC v.1915 -> Visual C++ 2017 (15.8)
MSC v.1916 -> Visual C++ 2017 (15.9)
Download and install the corresponding version of Visual Studio C++ from the previous step.
Additional notes for specific versions of VC++ are listed below.
Uncheck everything except Developer Tools >> Visual C++ Compilers to save time and disk space from installing SDK tools you otherwise don’t need.
Notes for Visual Studio C++ 2010
According to Microsoft, if you installed Visual Studio 2010 SP1, it may have removed the compilers and libraries for VC++.
If that is the case, download Visual C++ 2010 SP1 Compiler Update.
Suggestion: If you have both a 32- and 64-bit Python installation, you may also want to use virtualenv to create separate Python environments so you can use one or the other at a time without messing with your path to choose which Python version to use.
According to @srodriguex, you may be able to skip manually loading the batch file (Steps 4-6) by instead copying a few batch files to where Python is searching by following this answer. If that doesn’t work, here are the following steps that originally worked for me.
Open up a cmd.exe
Before you try installing something which requires C extensions, run the following batch file to load the VC++ compiler’s environment into the session (i.e. environment variables, the path to the compiler, etc).
Execute:
32-bit Compilers:
Note: 32-bit Windows installs will only have C:\Program Files\ as expected
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars32.bat"
64-bit Compilers:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\vsvars64.bat"
Note: Yes, the native 64-bit compilers are in Program Files (x86). Don’t ask me why.
Additionally, if you are wondering what the difference between vcvars64.bat and vcvarsx86_amd64.bat or more importantly the difference between amd64 and x86_amd64, the former are for the native 64-bit compiler tools and the latter are the 64-bit cross compilers that can run on a 32-bit Windows installation.
Update:
If for some reason you are getting error: ... was unexpected at this time. where the ... is some series of characters, then you need to check that you path variable does not have any extraneous characters like extra quotations or stray characters. The batch file is not going to be able to update your session path if it can’t make sense of it in the first place.
If that went well, you should get one of the following messages depending on which version of VC++ and which command you ran:
For the 32-bit compiler tools: Setting environment for using Microsoft Visual Studio 20xx x86 tools.
For the 64-bit compiler tools: Setting environment for using Microsoft Visual Studio 20xx x64 tools.
Now, run the setup via python setup.py install or pip install pkg-name
Hope and cross your fingers that the planets are aligned correctly for VC++ to cooperate.
回答 4
这是怎么回事?Python模块可以用C或C ++编写(通常是为了提高速度)。如果尝试使用Pip(或setup.py)安装这样的软件包,则必须从源代码编译该C / C ++。开箱即用,Pip会大胆假设您已安装了Microsoft Visual C ++编译器。如果没有它,您将看到此错误消息“错误:无法找到vcvarsall.bat”。
规定的解决方案是安装C / C ++编译器,Microsoft Visual C ++或MinGW(一个开源项目)。但是,安装和配置任何一个都非常困难。(编辑2014:Microsoft已发布了用于Python 2.7 的特殊C ++编译器)
What’s going on? Python modules can be part written in C or C++ (typically for speed). If you try to install such a package with Pip (or setup.py), it has to compile that C/C++ from source. Out the box, Pip will brazenly assume you the compiler Microsoft Visual C++ installed. If you don’t have it, you’ll see this cryptic error message “Error: Unable to find vcvarsall.bat”.
The prescribed solution is to install a C/C++ compiler, either Microsoft Visual C++, or MinGW (an open-source project). However, installing and configuring either is prohibitively difficult. (Edit 2014: Microsoft have published a special C++ compiler for Python 2.7)
The easiest solution is to use Christoph Gohlke’s Windows installers (.msi) for popular Python packages. He builds installers for Python 2.x and 3.x, 32 bit and 64 bit. You can download them from http://www.lfd.uci.edu/~gohlke/pythonlibs/
If you too think “Error: Unable to find vcvarsall.bat” is a ludicrously cryptic and unhelpful message, then please comment on the bug at http://bugs.python.org/issue2943 to replace it with a more helpful and user-friendly message.
For comparison, Ruby ships with a package manager Gem and offers a quasi-official C/C++ compiler, DevKit. If you try to install a package without it, you see this helpful friendly useful message:
You’ll need to install a Microsoft compiler, compatible with the compiler used to build Python. This means you need Visual C++ 2008 (or newer, with some tweaking).
Microsoft now supplies a bundled compiler and headers just to be able to compile Python extensions, at the memorable URL:
This is a relatively small package; 85MB to download, installable without admin privileges, no reboot required. The name is a little misleading, the compiler will work for any Python version originally compiled with Visual C++ 2008, not just Python 2.7.
If you start a Python interactive prompt or print sys.version, look for the MSC version string; if it is MSC v.1500 you can use this tool.
Microsoft has released a compiler package for Python 2.7 to make it easier for people to build and distribute their C extension modules on Windows. The Microsoft Visual C++ Compiler for Python 2.7 (a.k.a. VC9) is available from: http://aka.ms/vcpython27
This package contains all the tools and headers required to build C extension modules for Python 2.7 32-bit and 64-bit (note that some extension modules require 3rd party dependencies such as OpenSSL or libxml2 that are not included). Other versions of Python built with Visual C++ 2008 are also supported, so “Python 2.7” is just advertising – it’ll work fine with 2.6 and 3.2.
Note that you need to have setuptools 6.0 or newer installed (listed in the system requirements on the download page). The project you are installing must use setuptools.setup(), not distutils or the auto-detection won’t work.
Microsoft has stated that they want to keep the URL stable, so that automated scripts can reference it easily.
I just had this same problem, so I’ll tell my story here hoping it helps someone else with the same issues and save them the couple of hours I just spent:
I have mingw (g++ (GCC) 4.6.1) and python 2.7.3 in a windows 7 box and I’m trying to install PyCrypto.
It all started with this error when running setup.py install:
error: Unable to find vcvarsall.bat
Easily solved after googling the error by specifying mingw as the compiler of choice:
setup.py install build --compiler=mingw32
The problem is that then I got a different error:
configure: error: cannot run C compiled programs.
It turns out that my anti-virus was blocking the execution of a freshly compiled .exe. I just disabled the anti-virus “resident shield” and went to the next error:
cc1.exe: error: unrecognized command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1
This solved it: “Either install a slightly older version of MinGW, or edit distutils\cygwinccompiler.py in your Python directory to remove all instances of -mno-cygwin.” (from here)
I have python 2.73 and windows 7 .The solution that worked for me was:
Added mingw32’s bin directory to environment variable: append PATH with C:\programs\mingw\bin;
Created distutils.cfg located at C:\Python27\Lib\distutils\distutils.cfg containing:
[build]
compiler=mingw32
To deal with MinGW not recognizing the -mno-cygwin flag anymore, remove the flag in C:\Python27\Lib\distutils\cygwincompiler.py line 322 to 326, so it looks like this:
Look in the setup.py file of the package you are trying to install. If it is an older package it may be importing distutils.core.setup() rather than setuptools.setup().
I ran in to this (in 2015) with a combination of these factors:
Trying to do python setup.py build rather than using pip.
If you use a recent version of pip, it will force (monkeypatch) the package to use setuptools, even if its setup.py calls for distutils. However, if you are not using pip, and instead are just doing python setup.py build, the build process will use distutils.core.setup(), which does not know about the compiler install location.
Solution
Step 1: Open the appropriate Visual C++ 2008 Command Prompt
Open the Start menu or Start screen, and search for “Visual C++ 2008 32-bit Command Prompt” (if your python is 32-bit) or “Visual C++ 2008 64-bit Command Prompt” (if your python is 64-bit). Run it. The command prompt should say Visual C++ 2008 … in the title bar.
Step 2: Set environment variables
Set these environment variables in the command prompt you just opened.
cd to the package you want to build, and run python setup.py build, then python setup.py install. If you want to install in to a virtualenv, activate it before you build.
Maybe somebody can be interested, the following worked for me for the py2exe package.
(I have windows 7 64 bit and portable python 2.7, Visual Studio 2005 Express with Windows SDK for Windows 7 and .NET Framework 4)
File"numpy\core\setup.py", line 686,in get_mathlib_info
raiseRuntimeError("Broken toolchain: cannot link a simple C program")RuntimeError:Broken toolchain: cannot link a simple C program
I spent almost 2 days figuring out how to fix this problem in my python 3.4 64 bit version: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:44:40) [MSC v.1600 64 bit (AMD64)] on win32
Solution 1, hard: (before reading this, read first Solution 2 below)
Finally, this is what helped me:
create manually file vcvars64.bat in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 which contains CALL "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 or other path depending on where you have yours installed
after that I tried to pip install numpy but received the following error:
File "numpy\core\setup.py", line 686, in get_mathlib_info
raise RuntimeError("Broken toolchain: cannot link a simple C program")
RuntimeError: Broken toolchain: cannot link a simple C program
finally after pip install numpy command my avast antivirus tried to interfere into the installation process, but i quickly disabled it
It took very long – several minutes for numpy to compile, I even thought that there was an error, but finally everything was ok.
Solution 2, easy:
(I know this approach has already been mentioned in a highly voted answer, but let me repeat since it really is easier)
After going through all of this work I understood that the best way for me is just to use already precompiled binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/ in future. There is very small chance that I will ever need some package (or a version of a package) which this site doesn’t contain. The installation process is also much quicker this way. For example, to install numpy:
donwload numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl (if you have Python 3.4 64-bit) from that site
in command prompt or powershell install it with pip pip install numpy‑1.9.2+mkl‑cp34‑none‑win_amd64.whl (or full path to the file depending how command prompt is opened)
I encountered this issue when I tried to install numpy library on my python 3.5. The solution is to install VS2015. I had VS2008, 2012, 2013, none of which is compatible with python 3.5. Apparently newer version of python has dependency on newer versions of VS.
Also make sure C++ Common Tools are installed with Visual Studio.
I tried all the above answers, and found all of them not to work, this was perhaps I was using Windows 8 and had installed Visual Studio 2012. In this case, this is what you do.
The vcvarsall.bat file is located here:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC
Simply select the file, and copy it.
Then go to this directory:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Tools
You can download the free Visual C++ 2008 Express Edition from http://go.microsoft.com/?linkid=7729279, which will set the VS90COMNTOOLS environment variable during installation and therefore build with a compatible compiler.
As @PiotrDobrogost mentioned in a comment, his answer to this other question goes into details about why Visual C++ 2008 is the right thing to build with, but this can change as the Windows build of Python moves to newer versions of Visual Studio: Building lxml for Python 2.7 on Windows
但是,这不会为我安装,安装程序返回了错误installation failed with return code 5100。我在以下链接中找到了解决方案:http : //support.microsoft.com/kb/2717426。简而言之,如果安装了x86和x64 Microsoft Visual C ++ 2010 Redistributable的较新版本,它们将与SDK安装程序中的版本冲突,因此需要先进行卸载。
然后安装了SDK,但是我注意到vcvars64.bat仍然不存在C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin,也没有其子文件夹。vcvarsall.bat运行vcvars64批处理文件,因此如果没有该文件,python软件包仍将无法安装(我忘记了此时显示的错误)。
I had this problem using Python 3.4.1 on Windows 7 x64, and unfortunately the packages I needed didn’t have suitable exe or wheels that I could use. This system requires a few ‘workarounds’, which are detailed below (and TLDR at bottom).
Using the info in Jaxrtech’s answer above, I determined I needed Visual Studio C++ 2010 (sys.version return MSC v.1600), so I installed Visual C++ 2010 Express from the link in his answer, which is http://go.microsoft.com/?linkid=9709949. I installed everything with updates, but as you can read below, this was a mistake. Only the original version of Express should be installed at this time (no updated anything).
vcvarsall.bat was now present, but there was a new error when installing the package, query_vcvarsall raise ValueError(str(list(result.keys())))ValueError: [u'path']. There are other stackoverflow questions with this error, such as Errors while building/installing C module for Python 2.7
This would not install for me though, and the installer returned the error installation failed with return code 5100. I found the solution at the following link: http://support.microsoft.com/kb/2717426. In short, if newer versions of x86 and x64 Microsoft Visual C++ 2010 Redistributable’s are installed, they conflict with the ones in SDK installer, and need uninstalling first.
The SDK then installed, but I noticed vcvars64.bat still did not exist in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin, nor its subfolders. vcvarsall.bat runs the vcvars64 batch file, so without it, the python package still wouldn’t install (I forgot the error that was shown at this time).
I then found some instructions here: http://www.cryptohaze.com/wiki/index.php/Windows_7_Build_Setup#Download_VS_2010_and_Windows_SDK_7.1
Following the instructions, I had already installed Express and 7.1 SDK, so installed SDK 7.1 SP1, and did the missing header file fix. I then manually created vcvars64.bat with the content CALL setenv /x64. I will paste all those instructions here, so they don’t get lost.
And, bloody hell, fix the missing batch file for VS2010 Express. This
is getting downright absurd.
In C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64,
create “vcvars64.bat” with the following (you will need to be running
as administrator):
Never mind this question. Somebody here noticed this item on the menu: Start->All Programs->Microsoft Windows SDK v7.1 ->Windows SDK 7.1 Command Prompt
This runs a batch job that appears to set up a working environment for the compiler. From that prompt, you can type “setup.py build” or “setup.py install”.
I opened the Windows SDK 7.1 Command Prompt as instructed, and used it to run easy_install on the python package. And at last, success!
TLDR;
Install Visual Studio Express 2010 (preferably without updated redistributables or SQL server).
Install Windows 7.1 SDK
Instal SDK 7.1 SP1 update, and VS2010 SP1 header file fix (this step may not be required).
Manually create C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat with content CALL setenv /x64
Start->All Programs->Microsoft Windows SDK v7.1 ->Windows SDK 7.1 Command Prompt to open special x64 command prompt, which can then be used with python/easy_install/pip/etc (including those in virtual_envs).
回答 17
下面的步骤为我解决了这个问题,我试图用cython扩展创建安装程序。
安装适用于Python 2.7的Microsoft Visual C ++编译器
默认安装位置为@ C:\ Users \ PC-user \ AppData \ Local \ Programs \ Common \ Microsoft \ Visual C ++ for Python。这实际上可以解决此问题,请在继续操作之前进行一次测试。
Below steps fixed this issue for me, I was trying to create setup with cython extension.
Install Microsoft Visual C++ Compiler for Python 2.7
The default install location would be @
C:\Users\PC-user\AppData\Local\Programs\Common\Microsoft\Visual C++
for Python This might actually fix the issue, test once before proceeding.
If it fails, Check where in VC++
for python vcvarsall.bat file is located
Open the msvc9compiler.py
file of distutils package in notepad.
In my box this was @
C:\Anaconda2\Lib\distutils\msvc9compiler.py find_vcvarsall function
in this file, determine the version of VC by printing out version
argument. For Python 2.7 it’s likely to be 9.0
Now create an
environment variable VS90COMNTOOLS, Pointing to
C:\Users\PC-user\AppData\Local\Programs\Common\Microsoft\Visual C++
for Python\9.0\VC\bin
For some reason distutils expects the
vcvarsall.bat file to be within VC dir, but VC++ for python tools
has it in the root of 9.0 To fix this, remove “VC” from the
path.join (roughly around line 247)
I tried many solutions but only one worked for me, the install of Microsoft Visual Studio 2008 Express C++.
I got this issue with a Python 2.7 module written in C (yEnc, which has other issues with MS VS). Note that Python 2.7 is built with MS VS 2008 version, not 2010!
Despite the fact it’s free, it is quite hard to find since MS is promoting VS 2010.
Still, the MSDN official very direct links are still working: check https://stackoverflow.com/a/15319069/2227298 for download links.
I got the same problem and have solved it at the moment.
“Google” told me that I need to install “Microsoft Visual C++ Compiler for Python 2.7”. I install not only the tool, but also Visual C++ 2008 Reditributable, but it didn’t help. I then tried to install Visual C++ 2008 Express Edition. And the problem has gone!
Just try to install Visual C++ 2008 Express Edition!
calling import setuptools will monkey patch distutils to force compatibility with Visual Studio. Calling vcvars32.bat manually will setup the virtual environment and prevent other common errors the compiler will throw. For VS 2017 the file is located at
Use this link to download and install Visual C++ 2015 Build Tools. It will automatically download visualcppbuildtools_full.exe and install Visual C++ 14.0 without actually installing Visual Studio. After the installation completes, retry pip install and you won’t get the error again.
I have tested it on following platform and versions:
Python 3.6 on Windows 7 64-bit
Python 3.7 on Windows Server 2016 (64-bit system)
Python 3.8 on Windows 10 64-bit
回答 26
如果要在未安装Visual Studio 的Windows机器上安装pyodbc,则另一个选择是使用二进制发行版手动安装pyodbc。
If you’re looking to install pyodbc on a Windows box that doesn’t have Visual Studio installed another option is to manually install pyodbc using the binary distribution.
This is particularly useful if you do not have administrator privileges on the machine you’re working with and are trying to set up a virtualenv.
Steps:
Download the latest Windows installer from here (pyodbc-X.X.X.win-Y-py2.7.exe)
Open the installer executable using 7-Zip (or WinRAR or whatever)
Extract pyodbc.pyd and pyodbc-X.X.X-py2.7.egg-info and place them in [python installation directory or virtualenv]\Lib\site-packages
There is no step 4 :)
回答 27
使用Python 3.4,依赖关系依赖于Visual Studio2010。安装Visual C ++ 2010 Express对我来说解决了这个问题。
The answer given by @monkey is one of the correct ones, but it is incomplete.
In case you’d like to use MinGW, you should select the C, C++ and also other development tools suggested during the MinGW installation process to also get “make.exe.”
You must also have the path set to make.exe in the env.
To complete his answer, here are the steps:
Add mingw32’s bin directory to your environment variables
Append C:\Programs\MinGW\bin;C:\Programs\MinGW\msys\1.0\bin; to the PATH
Edit (create if it doesn’t exist) the distutils.cfg file located at C:\Python26\Lib\distutils\distutils.cfg to be:
[build]
compiler=mingw32
Make sure the environment variables is set by opening a new cmd.exe.